[pypy-commit] pypy default: Update to cffi/22eff74bf6e8
arigo
noreply at buildbot.pypy.org
Thu May 28 18:27:49 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r77660:364248f972d0
Date: 2015-05-28 18:27 +0200
http://bitbucket.org/pypy/pypy/changeset/364248f972d0/
Log: Update to cffi/22eff74bf6e8
diff --git a/pypy/module/_cffi_backend/lib_obj.py b/pypy/module/_cffi_backend/lib_obj.py
--- a/pypy/module/_cffi_backend/lib_obj.py
+++ b/pypy/module/_cffi_backend/lib_obj.py
@@ -129,11 +129,15 @@
fetch_funcptr = rffi.cast(
realize_c_type.FUNCPTR_FETCH_CHARP,
g.c_address)
- assert fetch_funcptr
- assert w_ct.size > 0
- ptr = lltype.malloc(rffi.CCHARP.TO, w_ct.size, flavor='raw')
- self.ffi._finalizer.free_mems.append(ptr)
- fetch_funcptr(ptr)
+ if w_ct.size <= 0:
+ raise oefmt(space.w_SystemError,
+ "constant has no known size")
+ if not fetch_funcptr: # for dlopen() style
+ ptr = self.cdlopen_fetch(attr)
+ else:
+ ptr = lltype.malloc(rffi.CCHARP.TO, w_ct.size, flavor='raw')
+ self.ffi._finalizer.free_mems.append(ptr)
+ fetch_funcptr(ptr)
w_result = w_ct.convert_to_object(ptr)
#
elif op == cffi_opcode.OP_DLOPEN_FUNC:
diff --git a/pypy/module/_cffi_backend/test/test_re_python.py b/pypy/module/_cffi_backend/test/test_re_python.py
--- a/pypy/module/_cffi_backend/test/test_re_python.py
+++ b/pypy/module/_cffi_backend/test/test_re_python.py
@@ -22,6 +22,8 @@
#define BIGNEG -420000000000L
int add42(int x) { return x + 42; }
int globalvar42 = 1234;
+ const int globalconst42 = 4321;
+ const char *const globalconsthello = "hello";
struct foo_s;
typedef struct bar_s { int x; signed char a[]; } bar_t;
enum foo_e { AA, BB, CC };
@@ -34,7 +36,8 @@
c_file = tmpdir.join('_test_re_python.c')
c_file.write(SRC)
ext = ffiplatform.get_extension(str(c_file), '_test_re_python',
- export_symbols=['add42', 'globalvar42'])
+ export_symbols=['add42', 'globalvar42',
+ 'globalconst42', 'globalconsthello'])
outputfilename = ffiplatform.compile(str(tmpdir), ext)
cls.w_extmod = space.wrap(outputfilename)
#mod.tmpdir = tmpdir
@@ -47,6 +50,8 @@
#define BIGNEG -420000000000L
int add42(int);
int globalvar42;
+ const int globalconst42;
+ const char *const globalconsthello = "hello";
int no_such_function(int);
int no_such_globalvar;
struct foo_s;
@@ -157,6 +162,18 @@
p[0] -= 1
assert lib.globalvar42 == 1238
+ def test_global_const_int(self):
+ from re_python_pysrc import ffi
+ lib = ffi.dlopen(self.extmod)
+ assert lib.globalconst42 == 4321
+ raises(AttributeError, ffi.addressof, lib, 'globalconst42')
+
+ def test_global_const_nonint(self):
+ from re_python_pysrc import ffi
+ lib = ffi.dlopen(self.extmod)
+ assert ffi.string(lib.globalconsthello, 8) == "hello"
+ raises(AttributeError, ffi.addressof, lib, 'globalconsthello')
+
def test_rtld_constants(self):
from re_python_pysrc import ffi
ffi.RTLD_NOW # check that we have the attributes
More information about the pypy-commit
mailing list