Author: Ronan Lamy <[email protected]>
Branch: rffi-parser-2
Changeset: r89245:cb02fc0344cb
Date: 2016-12-27 16:15 +0100
http://bitbucket.org/pypy/pypy/changeset/cb02fc0344cb/
Log: Add Py_buffer to the pseudo-header
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -624,9 +624,41 @@
typedef struct _typeobject PyTypeObject;
typedef void (*freefunc)(void *);
+
+/* Py3k buffer interface, adapted for PyPy */
+#define Py_MAX_NDIMS 32
+#define Py_MAX_FMT 128
+typedef struct bufferinfo {
+ void *buf;
+ PyObject *obj; /* owned reference */
+ Py_ssize_t len;
+
+ /* This is Py_ssize_t so it can be
+ pointed to by strides in simple case.*/
+ Py_ssize_t itemsize;
+ int readonly;
+ int ndim;
+ char *format;
+ Py_ssize_t *shape;
+ Py_ssize_t *strides;
+ Py_ssize_t *suboffsets; /* alway NULL for app-level objects*/
+ unsigned char _format[Py_MAX_FMT];
+ Py_ssize_t _strides[Py_MAX_NDIMS];
+ Py_ssize_t _shape[Py_MAX_NDIMS];
+ /* static store for shape and strides of
+ mono-dimensional buffers. */
+ /* Py_ssize_t smalltable[2]; */
+ void *internal; /* always NULL for app-level objects */
+} Py_buffer;
+
+
+typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
+typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
+/* end Py3k buffer interface */
+
""")
-Py_ssize_t = lltype.Typedef(h.definitions['Py_ssize_t'], 'Py_ssize_t')
+Py_ssize_t = h.definitions['Py_ssize_t']
Py_ssize_tP = rffi.CArrayPtr(Py_ssize_t)
size_t = rffi.ULONG
ADDR = lltype.Signed
@@ -645,26 +677,9 @@
PyVarObjectStruct = h.definitions['PyVarObject']
PyVarObject = lltype.Ptr(PyVarObjectStruct)
-Py_buffer = cpython_struct(
- "Py_buffer", (
- ('buf', rffi.VOIDP),
- ('obj', PyObject),
- ('len', Py_ssize_t),
- ('itemsize', Py_ssize_t),
+Py_buffer = h.definitions['Py_buffer']
+Py_bufferP = lltype.Ptr(Py_buffer)
- ('readonly', lltype.Signed),
- ('ndim', lltype.Signed),
- ('format', rffi.CCHARP),
- ('shape', Py_ssize_tP),
- ('strides', Py_ssize_tP),
- ('_format', rffi.CFixedArray(rffi.UCHAR, Py_MAX_FMT)),
- ('_shape', rffi.CFixedArray(Py_ssize_t, Py_MAX_NDIMS)),
- ('_strides', rffi.CFixedArray(Py_ssize_t, Py_MAX_NDIMS)),
- ('suboffsets', Py_ssize_tP),
- #('smalltable', rffi.CFixedArray(Py_ssize_t, 2)),
- ('internal', rffi.VOIDP)
- ))
-Py_bufferP = lltype.Ptr(Py_buffer)
@specialize.memo()
def is_PyObject(TYPE):
diff --git a/pypy/module/cpyext/cparser.py b/pypy/module/cpyext/cparser.py
--- a/pypy/module/cpyext/cparser.py
+++ b/pypy/module/cpyext/cparser.py
@@ -666,15 +666,6 @@
self.fields = fields
self.TYPE = TYPE
- def config_fields(self):
- result = []
- for name, value in self.fields:
- if isinstance(value, DelayedStruct):
- result.append((name, value.TYPE))
- else:
- result.append((name, value))
- return result
-
def __repr__(self):
return "<struct {struct_name}>".format(**vars(self))
@@ -725,7 +716,7 @@
configname = type_name.replace(' ', '__')
if configure_now:
setattr(self._Config, configname,
- rffi_platform.Struct(type_name, struct.config_fields()))
+ rffi_platform.Struct(type_name, struct.fields))
self._TYPES[configname] = struct.TYPE
else:
cpython_struct(type_name, struct.fields, forward=struct.TYPE)
diff --git a/pypy/module/cpyext/test/test_api.py
b/pypy/module/cpyext/test/test_api.py
--- a/pypy/module/cpyext/test/test_api.py
+++ b/pypy/module/cpyext/test/test_api.py
@@ -90,9 +90,9 @@
from rpython.translator.c.database import LowLevelDatabase
db = LowLevelDatabase()
assert (api.c_function_signature(db,
api.FUNCTIONS['PyPy_TypedefTest1'])
- == ('Py_ssize_t', 'Py_ssize_t arg0'))
+ == ('Signed', 'Signed arg0'))
assert (api.c_function_signature(db,
api.FUNCTIONS['PyPy_TypedefTest2'])
- == ('Py_ssize_t *', 'Py_ssize_t *arg0'))
+ == ('Signed *', 'Signed *arg0'))
PyPy_TypedefTest1(space, 0)
ppos = lltype.malloc(api.Py_ssize_tP.TO, 1, flavor='raw')
@@ -100,7 +100,7 @@
PyPy_TypedefTest2(space, ppos)
lltype.free(ppos, flavor='raw')
[email protected](os.environ.get('USER')=='root',
[email protected](os.environ.get('USER')=='root',
reason='root can write to all files')
def test_copy_header_files(tmpdir):
api.copy_header_files(tmpdir, True)
diff --git a/pypy/module/cpyext/test/test_cparser.py
b/pypy/module/cpyext/test/test_cparser.py
--- a/pypy/module/cpyext/test/test_cparser.py
+++ b/pypy/module/cpyext/test/test_cparser.py
@@ -100,7 +100,7 @@
includes=['sys/types.h', 'foo.h'])
foo_h = parse_source(cdef, eci=eci)
Object = foo_h.definitions['Object']
- assert isinstance(Object, lltype.ForwardReference) or hash(Object)
+ assert isinstance(Object, lltype.ForwardReference)
def test_recursive(tmpdir):
cdef = """
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit