[pypy-svn] r68019 - in pypy/trunk/pypy: rlib rpython/lltypesystem rpython/lltypesystem/test
arigo at codespeak.net
arigo at codespeak.net
Wed Sep 30 12:43:14 CEST 2009
Author: arigo
Date: Wed Sep 30 12:43:13 2009
New Revision: 68019
Modified:
pypy/trunk/pypy/rlib/rposix.py
pypy/trunk/pypy/rpython/lltypesystem/rffi.py
pypy/trunk/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
Log:
"Solve" the ambiguity of rffi.INT versus rffi.LONG in
rffi.CExternVariable by requiring an explicit C type.
Fix the test to make it pass on both 32- and 64-bits machines.
Modified: pypy/trunk/pypy/rlib/rposix.py
==============================================================================
--- pypy/trunk/pypy/rlib/rposix.py (original)
+++ pypy/trunk/pypy/rlib/rposix.py Wed Sep 30 12:43:13 2009
@@ -24,7 +24,7 @@
_get_errno, _set_errno = CExternVariable(INT, 'errno', errno_eci,
CConstantErrno, sandboxsafe=True,
- _nowrapper=True)
+ _nowrapper=True, c_type='int')
# the default wrapper for set_errno is not suitable for use in critical places
# like around GIL handling logic, so we provide our own wrappers.
Modified: pypy/trunk/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/rffi.py (original)
+++ pypy/trunk/pypy/rpython/lltypesystem/rffi.py Wed Sep 30 12:43:13 2009
@@ -439,7 +439,8 @@
return lltype.Ptr(COpaque(*args, **kwds))
def CExternVariable(TYPE, name, eci, _CConstantClass=CConstant,
- sandboxsafe=False, _nowrapper=False):
+ sandboxsafe=False, _nowrapper=False,
+ c_type=None):
"""Return a pair of functions - a getter and a setter - to access
the given global C variable.
"""
@@ -447,16 +448,17 @@
from pypy.translator.tool.cbuild import ExternalCompilationInfo
# XXX we cannot really enumerate all C types here, do it on a case-by-case
# basis
- if TYPE == CCHARPP:
- c_type = 'char **'
- elif TYPE == CCHARP:
- c_type = 'char *'
- elif TYPE == INT:
- c_type = 'int'
- else:
- c_type = PrimitiveType[TYPE]
- assert c_type.endswith(' @')
- c_type = c_type[:-2] # cut the trailing ' @'
+ if c_type is None:
+ if TYPE == CCHARPP:
+ c_type = 'char **'
+ elif TYPE == CCHARP:
+ c_type = 'char *'
+ elif TYPE == INT or TYPE == LONG:
+ assert False, "ambiguous type on 32-bit machines: give a c_type"
+ else:
+ c_type = PrimitiveType[TYPE]
+ assert c_type.endswith(' @')
+ c_type = c_type[:-2] # cut the trailing ' @'
getter_name = 'get_' + name
setter_name = 'set_' + name
Modified: pypy/trunk/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/test/test_ll2ctypes.py (original)
+++ pypy/trunk/pypy/rpython/lltypesystem/test/test_ll2ctypes.py Wed Sep 30 12:43:13 2009
@@ -753,6 +753,7 @@
#include <stdlib.h>
static long x = 3;
+ static int y = 5;
char **z = NULL;
#endif /* _SOME_H */
@@ -763,7 +764,8 @@
eci = ExternalCompilationInfo(includes=['stdio.h', str(h_file.basename)],
include_dirs=[str(udir)])
- get_x, set_x = rffi.CExternVariable(rffi.LONG, 'x', eci)
+ get_x, set_x = rffi.CExternVariable(rffi.LONG, 'x', eci, c_type='long')
+ get_y, set_y = rffi.CExternVariable(rffi.INT, 'y', eci, c_type='int')
get_z, set_z = rffi.CExternVariable(rffi.CCHARPP, 'z', eci)
def f():
@@ -771,6 +773,11 @@
set_x(13)
return one + get_x()
+ def fy():
+ one = rffi.cast(lltype.Signed, get_y())
+ set_y(rffi.cast(rffi.INT, 13))
+ return one + rffi.cast(lltype.Signed, get_y())
+
def g():
l = rffi.liststr2charpp(["a", "b", "c"])
try:
@@ -781,7 +788,10 @@
res = f()
assert res == 16
- assert g() == "c"
+ res = fy()
+ assert res == 18
+ res = g()
+ assert res == "c"
def test_c_callback(self):
c_source = py.code.Source("""
More information about the Pypy-commit
mailing list