Author: Armin Rigo <[email protected]>
Branch:
Changeset: r55601:b69ff31d84ff
Date: 2012-06-11 20:35 +0200
http://bitbucket.org/pypy/pypy/changeset/b69ff31d84ff/
Log: (Ab)use the mecanism to find sizeof(void*) from the C compiler too,
and use it to answer rffi.sizeof(ptrtype). Check that it gives the
same result as rffi.sizeof(lltype.Signed) with an assert.
diff --git a/pypy/rpython/lltypesystem/rffi.py
b/pypy/rpython/lltypesystem/rffi.py
--- a/pypy/rpython/lltypesystem/rffi.py
+++ b/pypy/rpython/lltypesystem/rffi.py
@@ -435,7 +435,8 @@
TYPES += ['signed char', 'unsigned char',
'long long', 'unsigned long long',
'size_t', 'time_t', 'wchar_t',
- 'uintptr_t', 'intptr_t']
+ 'uintptr_t', 'intptr_t',
+ 'void*'] # generic pointer type
_TYPES_ARE_UNSIGNED = set(['size_t', 'uintptr_t']) # plus "unsigned *"
if os.name != 'nt':
TYPES.append('mode_t')
@@ -903,7 +904,7 @@
size = llmemory.sizeof(tp) # a symbolic result in this case
return size
if isinstance(tp, lltype.Ptr) or tp is llmemory.Address:
- tp = lltype.Signed
+ return globals()['r_void*'].BITS/8
if tp is lltype.Char or tp is lltype.Bool:
return 1
if tp is lltype.UniChar:
@@ -934,11 +935,16 @@
offsetof._annspecialcase_ = 'specialize:memo'
# check that we have a sane configuration
-assert maxint == (1 << (8 * platform._size_of_Signed - 1)) - 1, (
+assert maxint == (1 << (8 * sizeof(llmemory.Address) - 1)) - 1, (
"Mixed configuration of the word size of the machine:\n\t"
"the underlying Python was compiled with maxint=%d,\n\t"
"but the C compiler says that 'long' is %d bytes" % (
- maxint, sizeof(lltype.Signed)))
+ maxint, sizeof(llmemory.Address)))
+assert sizeof(lltype.Signed) == sizeof(llmemory.Address), (
+ "Bad configuration: we should manage to get lltype.Signed "
+ "be an integer type of the same size as llmemory.Address, "
+ "but we got %s != %s" % (sizeof(lltype.Signed),
+ sizeof(llmemory.Address)))
# ********************** some helpers *******************
diff --git a/pypy/rpython/tool/rfficache.py b/pypy/rpython/tool/rfficache.py
--- a/pypy/rpython/tool/rfficache.py
+++ b/pypy/rpython/tool/rfficache.py
@@ -67,8 +67,6 @@
def _make_type(self, name, signed, size):
inttype = rarithmetic.build_int('r_' + name, signed, size*8)
tp = lltype.build_number(name, inttype)
- if tp is lltype.Signed:
- self._size_of_Signed = size
self.numbertype_to_rclass[tp] = inttype
self.types[name] = tp
return tp
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit