[pypy-commit] cffi cffi-1.0: test and fix

arigo noreply at buildbot.pypy.org
Sun May 17 20:13:21 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r2039:5cd5342dd8ce
Date: 2015-05-17 20:14 +0200
http://bitbucket.org/cffi/cffi/changeset/5cd5342dd8ce/

Log:	test and fix

diff --git a/c/cdlopen.c b/c/cdlopen.c
--- a/c/cdlopen.c
+++ b/c/cdlopen.c
@@ -117,7 +117,7 @@
     int neg;
 } cdl_intconst_t;
 
-int _cdl_realize_global_int(struct _cffi_getconst_s *gc)
+static int _cdl_realize_global_int(struct _cffi_getconst_s *gc)
 {
     /* The 'address' field of 'struct _cffi_global_s' is set to point
        to this function in case ffiobj_init() sees constant integers.
diff --git a/c/ffi_obj.c b/c/ffi_obj.c
--- a/c/ffi_obj.c
+++ b/c/ffi_obj.c
@@ -105,7 +105,7 @@
         default:
             PyErr_Format(FFIError,
                          "function, global variable or non-integer constant "
-                         "'%.200s' must be fetched from their original 'lib' "
+                         "'%.200s' must be fetched from its original 'lib' "
                          "object", name);
             return NULL;
         }
diff --git a/c/lib_obj.c b/c/lib_obj.c
--- a/c/lib_obj.c
+++ b/c/lib_obj.c
@@ -278,6 +278,8 @@
             if (address == NULL) {
                 /* for dlopen() style */
                 address = cdlopen_fetch(lib->l_libname, lib->l_libhandle, s);
+                if (address == NULL)
+                    return NULL;
             }
             x = make_global_var(ct, address);
         }
diff --git a/testing/cffi1/test_re_python.py b/testing/cffi1/test_re_python.py
--- a/testing/cffi1/test_re_python.py
+++ b/testing/cffi1/test_re_python.py
@@ -38,6 +38,8 @@
     #define BIGNEG -420000000000L
     int add42(int);
     int globalvar42;
+    int no_such_function(int);
+    int no_such_globalvar;
     struct foo_s;
     typedef struct bar_s { int x; signed char a[]; } bar_t;
     enum foo_e { AA, BB, CC };
@@ -137,3 +139,13 @@
     ffi.RTLD_NOW    # check that we have the attributes
     ffi.RTLD_LAZY
     ffi.RTLD_GLOBAL
+
+def test_no_such_function_or_global_var():
+    from re_python_pysrc import ffi
+    lib = ffi.dlopen(extmod)
+    e = py.test.raises(ffi.error, getattr, lib, 'no_such_function')
+    assert str(e.value).startswith(
+        "symbol 'no_such_function' not found in library '")
+    e = py.test.raises(ffi.error, getattr, lib, 'no_such_globalvar')
+    assert str(e.value).startswith(
+        "symbol 'no_such_globalvar' not found in library '")


More information about the pypy-commit mailing list