Author: Armin Rigo <[email protected]>
Branch:
Changeset: r620:aff26a5f7a80
Date: 2012-07-10 12:41 +0200
http://bitbucket.org/cffi/cffi/changeset/aff26a5f7a80/
Log: Tweaks
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -2245,12 +2245,18 @@
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;
@@ -2351,12 +2357,14 @@
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;
diff --git a/c/misc_win32.h b/c/misc_win32.h
--- a/c/misc_win32.h
+++ b/c/misc_win32.h
@@ -60,7 +60,9 @@
/************************************************************/
/* 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)
{
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -24,14 +24,16 @@
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()
@@ -818,6 +820,10 @@
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':
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit