Commits

Armin Rigo committed aff26a5

Tweaks

Comments (0)

Files changed (3)

     CTypeDescrObject *ct;
     char *funcname;
     void *funcptr;
+    int ok;
 
     if (!PyArg_ParseTuple(args, "O!s:load_function",
                           &CTypeDescr_Type, &ct, &funcname))
         return NULL;
 
-    if (!(ct->ct_flags & CT_FUNCTIONPTR)) {
+    ok = 0;
+    if (ct->ct_flags & CT_FUNCTIONPTR)
+        ok = 1;
+    if ((ct->ct_flags & CT_POINTER) && (ct->ct_itemdescr->ct_flags & CT_VOID))
+        ok = 1;
+    if (!ok) {
         PyErr_Format(PyExc_TypeError, "function cdata expected, got '%s'",
                      ct->ct_name);
         return NULL;
     char *filename;
     void *handle;
     DynLibObject *dlobj;
-
-    if (!PyArg_ParseTuple(args, "et:load_library",
-                          Py_FileSystemDefaultEncoding, &filename))
+    int is_global = 0;
+
+    if (!PyArg_ParseTuple(args, "et|i:load_library",
+                          Py_FileSystemDefaultEncoding, &filename,
+                          &is_global))
         return NULL;
 
-    handle = dlopen(filename, RTLD_LAZY);
+    handle = dlopen(filename, RTLD_LAZY | (is_global?RTLD_GLOBAL:RTLD_LOCAL));
     if (handle == NULL) {
         PyErr_Format(PyExc_OSError, "cannot load library: %s", filename);
         return NULL;
 /************************************************************/
 /* Emulate dlopen()&co. from the Windows API */
 
-#define RTLD_LAZY  0
+#define RTLD_LAZY   0
+#define RTLD_GLOBAL 0
+#define RTLD_LOCAL  0
 
 static void *dlopen(const char *filename, int flag)
 {
     return sizeof(BPtr)
 
 
-def find_and_load_library(name):
+def find_and_load_library(name, is_global=0):
     import ctypes.util
     path = ctypes.util.find_library(name)
-    return load_library(path)
+    return load_library(path, is_global)
 
 def test_load_library():
     x = find_and_load_library('c')
     assert repr(x).startswith("<clibrary '")
+    x = find_and_load_library('c', 1)
+    assert repr(x).startswith("<clibrary '")
 
 def test_nonstandard_integer_types():
     d = nonstandard_integer_types()
     assert strlen(input) == 6
     #
     assert strlen("foobarbaz") == 9
+    #
+    BVoidP = new_pointer_type(new_void_type())
+    strlenaddr = ll.load_function(BVoidP, "strlen")
+    assert strlenaddr == cast(BVoidP, strlen)
 
 def test_read_variable():
     if sys.platform == 'win32':