[pypy-svn] r60511 - in pypy/trunk/pypy: rpython/lltypesystem translator/c translator/c/test
fijal at codespeak.net
fijal at codespeak.net
Tue Dec 16 15:48:20 CET 2008
Author: fijal
Date: Tue Dec 16 15:48:19 2008
New Revision: 60511
Modified:
pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py
pypy/trunk/pypy/translator/c/node.py
pypy/trunk/pypy/translator/c/test/test_lltyped.py
Log:
enough hacks to pass those two tests. Really obscure and unsupported :(
Modified: pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py Tue Dec 16 15:48:19 2008
@@ -386,6 +386,19 @@
def setitem(self, index, value):
self._storage._setitem(index, value, boundscheck=False)
+ def getitems(self):
+ _items = []
+ i = 0
+ while 1:
+ nextitem = self.getitem(i)
+ if nextitem == '\x00':
+ _items.append('\x00')
+ return _items
+ _items.append(nextitem)
+ i += 1
+
+ items = property(getitems)
+
# ____________________________________________________________
def _find_parent(llobj):
Modified: pypy/trunk/pypy/translator/c/node.py
==============================================================================
--- pypy/trunk/pypy/translator/c/node.py (original)
+++ pypy/trunk/pypy/translator/c/node.py Tue Dec 16 15:48:19 2008
@@ -595,7 +595,10 @@
yield '\t%s' % length.rstrip(', ')
yield '}'
elif self.T.OF == Char:
- s = ''.join(self.obj.items)
+ if len(self.obj.items) and self.obj.items[0] is None:
+ s = ''.join([self.obj.getitem(i) for i in range(len(self.obj.items))])
+ else:
+ s = ''.join(self.obj.items)
yield '\t%s%s' % (length, c_char_array_constant(s))
yield '}'
else:
Modified: pypy/trunk/pypy/translator/c/test/test_lltyped.py
==============================================================================
--- pypy/trunk/pypy/translator/c/test/test_lltyped.py (original)
+++ pypy/trunk/pypy/translator/c/test/test_lltyped.py Tue Dec 16 15:48:19 2008
@@ -650,6 +650,49 @@
fn = self.getcompiled(llf)
fn()
+ def test_prebuilt_ll2ctypes_array(self):
+ from pypy.rpython.lltypesystem import rffi, ll2ctypes
+ A = rffi.CArray(Char)
+ a = malloc(A, 6, flavor='raw')
+ a[0] = 'a'
+ a[1] = 'b'
+ a[2] = 'c'
+ a[3] = 'd'
+ a[4] = '\x00'
+ a[5] = '\x00'
+ # side effects when converting to c structure
+ ll2ctypes.lltype2ctypes(a)
+ def llf():
+ s = ''
+ for i in range(4):
+ s += a[i]
+ return 'abcd' == s
+
+ fn = self.getcompiled(llf)
+ assert fn()
+
+ def test_ll2ctypes_array_from_c(self):
+ from pypy.rpython.lltypesystem import rffi, ll2ctypes
+ A = rffi.CArray(Char)
+ a = malloc(A, 6, flavor='raw')
+ a[0] = 'a'
+ a[1] = 'b'
+ a[2] = 'c'
+ a[3] = 'd'
+ a[4] = '\x00'
+ a[5] = '\x00'
+ # side effects when converting to c structure
+ c = ll2ctypes.lltype2ctypes(a)
+ a = ll2ctypes.ctypes2lltype(Ptr(A), c)
+ def llf():
+ s = ''
+ for i in range(4):
+ s += a[i]
+ print s
+ return s == 'abcd'
+ fn = self.getcompiled(llf)
+ assert fn()
+
def test_cast_to_void_array(self):
from pypy.rpython.lltypesystem import rffi
def llf():
More information about the Pypy-commit
mailing list