[pypy-svn] r50592 - in pypy/branch/applevel-ctypes2/pypy/rpython/lltypesystem: . test
arigo at codespeak.net
arigo at codespeak.net
Mon Jan 14 14:52:43 CET 2008
Author: arigo
Date: Mon Jan 14 14:52:42 2008
New Revision: 50592
Modified:
pypy/branch/applevel-ctypes2/pypy/rpython/lltypesystem/ll2ctypes.py
pypy/branch/applevel-ctypes2/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
Log:
Bug test and fix.
Modified: pypy/branch/applevel-ctypes2/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/branch/applevel-ctypes2/pypy/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/branch/applevel-ctypes2/pypy/rpython/lltypesystem/ll2ctypes.py Mon Jan 14 14:52:42 2008
@@ -51,7 +51,7 @@
for fieldname in S._names:
FIELDTYPE = S._flds[fieldname]
if max_n is not None and fieldname == S._arrayfld:
- cls = build_ctypes_array(FIELDTYPE, None, max_n)
+ cls = get_ctypes_array_of_size(FIELDTYPE, max_n)
else:
cls = get_ctypes_type(FIELDTYPE)
fields.append((fieldname, cls))
@@ -100,7 +100,7 @@
def _malloc(cls, n=None):
if not isinstance(n, int):
raise TypeError, "array length must be an int"
- biggercls = build_ctypes_array(A, None, n)
+ biggercls = get_ctypes_array_of_size(A, n)
bigarray = biggercls()
if hasattr(bigarray, 'length'):
bigarray.length = n
@@ -136,6 +136,15 @@
CArray._normalized_ctype = get_ctypes_type(A)
return CArray
+def get_ctypes_array_of_size(FIELDTYPE, max_n):
+ if max_n > 0:
+ # no need to cache the results in this case, because the exact
+ # type is never seen - the array instances are cast to the
+ # array's _normalized_ctype, which is always the same.
+ return build_ctypes_array(FIELDTYPE, None, max_n)
+ else:
+ return get_ctypes_type(FIELDTYPE)
+
def get_ctypes_type(T, delayed_builders=None):
try:
return _ctypes_cache[T]
Modified: pypy/branch/applevel-ctypes2/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/branch/applevel-ctypes2/pypy/rpython/lltypesystem/test/test_ll2ctypes.py (original)
+++ pypy/branch/applevel-ctypes2/pypy/rpython/lltypesystem/test/test_ll2ctypes.py Mon Jan 14 14:52:42 2008
@@ -758,3 +758,11 @@
qsort(rffi.cast(rffi.VOIDP, a), 5, rffi.sizeof(rffi.INT), compare)
for i in range(5):
assert a[i] == i + 1
+
+ def test_array_type_bug(self):
+ A = lltype.Array(lltype.Signed)
+ a1 = lltype.malloc(A, 0, flavor='raw')
+ a2 = lltype.malloc(A, 0, flavor='raw')
+ c1 = lltype2ctypes(a1)
+ c2 = lltype2ctypes(a2)
+ assert type(c1) is type(c2)
More information about the Pypy-commit
mailing list