Author: Maciej Fijalkowski <[email protected]>
Branch: backend-vector-ops
Changeset: r52008:3db72c7b6012
Date: 2012-02-01 13:23 +0200
http://bitbucket.org/pypy/pypy/changeset/3db72c7b6012/
Log: (fijal, arigo) aligned arrays support for ll2ctypes
diff --git a/pypy/rpython/lltypesystem/ll2ctypes.py
b/pypy/rpython/lltypesystem/ll2ctypes.py
--- a/pypy/rpython/lltypesystem/ll2ctypes.py
+++ b/pypy/rpython/lltypesystem/ll2ctypes.py
@@ -183,7 +183,11 @@
('items', max_n * ctypes_item)]
else:
_fields_ = [('items', max_n * ctypes_item)]
-
+ if A._hints.get('memory_position_alignment'):
+ # This pack means the same as #pragma pack in MSVC and *not*
+ # in gcc
+ _pack_ = A._hints.get('memory_position_alignment')
+
@classmethod
def _malloc(cls, n=None):
if not isinstance(n, int):
diff --git a/pypy/rpython/lltypesystem/lltype.py
b/pypy/rpython/lltypesystem/lltype.py
--- a/pypy/rpython/lltypesystem/lltype.py
+++ b/pypy/rpython/lltypesystem/lltype.py
@@ -179,6 +179,8 @@
raise TypeError, "%r cannot be inlined in structure" % self
def _install_extras(self, adtmeths={}, hints={}):
+ if not isinstance(self, Array):
+ assert not 'memory_position_alignment' in hints
self._adtmeths = frozendict(adtmeths)
self._hints = frozendict(hints)
@@ -422,6 +424,10 @@
% (self.OF._gckind,))
self.OF._inline_is_varsize(False)
+ if 'memory_position_alignment' in kwds.get('_hints', {}):
+ assert kwds['_hints']['nolength'], 'alignment only for raw
non-lenght arrays'
+ assert self._gckind == 'raw', 'alignment only for raw non-lenght
arrays'
+ assert kwds['_hints']['memory_position_alignment'] in (1, 2, 4, 8,
16)
self._install_extras(**kwds)
def _inline_is_varsize(self, last):
diff --git a/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
b/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
--- a/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
+++ b/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
@@ -1356,6 +1356,19 @@
a2 = ctypes2lltype(lltype.Ptr(A), lltype2ctypes(a))
assert a2._obj.getitem(0)._obj._parentstructure() is a2._obj
+ def test_aligned_alloc(Self):
+ A = lltype.Array(lltype.Signed,
+ hints={'memory_position_alignment': 16,
+ 'nolength': True})
+ l = []
+ for i in range(10):
+ a = lltype.malloc(A, 5, flavor='raw')
+ ca = lltype2ctypes(a)
+ assert ctypes.cast(ca, ctypes.c_void_p).value % 16 == 0
+ l.append(a)
+ for i in range(10):
+ lltype.free(l[i], 'raw')
+
class TestPlatform(object):
def test_lib_on_libpaths(self):
from pypy.translator.platform import platform
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit