[pypy-commit] pypy cffi-1.0: arrays
arigo
noreply at buildbot.pypy.org
Sat May 2 21:55:24 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r76986:e315aa35d652
Date: 2015-05-02 21:47 +0200
http://bitbucket.org/pypy/pypy/changeset/e315aa35d652/
Log: arrays
diff --git a/pypy/module/_cffi_backend/newtype.py b/pypy/module/_cffi_backend/newtype.py
--- a/pypy/module/_cffi_backend/newtype.py
+++ b/pypy/module/_cffi_backend/newtype.py
@@ -191,6 +191,7 @@
raise oefmt(space.w_ValueError, "array item of unknown size: '%s'",
ctitem.name)
if length < 0:
+ assert length == -1
arraysize = -1
extra = '[]'
else:
diff --git a/pypy/module/_cffi_backend/realize_c_type.py b/pypy/module/_cffi_backend/realize_c_type.py
--- a/pypy/module/_cffi_backend/realize_c_type.py
+++ b/pypy/module/_cffi_backend/realize_c_type.py
@@ -78,6 +78,11 @@
realize_cache.all_primitives[num] = w_ctype
return w_ctype
+def get_array_type(ffi, opcodes, itemindex, length):
+ w_ctitem = realize_c_type(ffi, opcodes, itemindex)
+ w_ctitemptr = newtype.new_pointer_type(ffi.space, w_ctitem)
+ return newtype._new_array_type(ffi.space, w_ctitemptr, length)
+
def realize_c_type(ffi, opcodes, index):
"""Interpret an opcodes[] array. If opcodes == ffi.ctxobj.ctx.c_types,
@@ -97,14 +102,24 @@
#...
case = getop(op)
+
if case == cffi_opcode.OP_PRIMITIVE:
x = get_primitive_type(ffi.space, getarg(op))
+
elif case == cffi_opcode.OP_POINTER:
y = _realize_c_type_or_func(ffi, opcodes, getarg(op))
if isinstance(y, W_CType):
x = newtype.new_pointer_type(ffi.space, y)
else:
yyyyyyyyy
+
+ elif case == cffi_opcode.OP_ARRAY:
+ x = get_array_type(ffi, opcodes, getarg(op),
+ rffi.cast(rffi.SIGNED, opcodes[index + 1]))
+
+ elif case == cffi_opcode.OP_OPEN_ARRAY:
+ x = get_array_type(ffi, opcodes, getarg(op), -1)
+
else:
raise oefmt(ffi.space.w_NotImplementedError, "op=%d", case)
More information about the pypy-commit
mailing list