Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: Changeset: r52525:5dba8347e4d2 Date: 2012-02-15 19:04 +0100 http://bitbucket.org/pypy/pypy/changeset/5dba8347e4d2/
Log: cpyext: Expose more fields of Py_buffer, if someone wants to use them... 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 @@ -435,16 +435,16 @@ ('buf', rffi.VOIDP), ('obj', PyObject), ('len', Py_ssize_t), - # ('itemsize', Py_ssize_t), + ('itemsize', Py_ssize_t), - # ('readonly', lltype.Signed), - # ('ndim', lltype.Signed), - # ('format', rffi.CCHARP), - # ('shape', Py_ssize_tP), - # ('strides', Py_ssize_tP), - # ('suboffets', Py_ssize_tP), - # ('smalltable', rffi.CFixedArray(Py_ssize_t, 2)), - # ('internal', rffi.VOIDP) + ('readonly', lltype.Signed), + ('ndim', lltype.Signed), + ('format', rffi.CCHARP), + ('shape', Py_ssize_tP), + ('strides', Py_ssize_tP), + ('suboffsets', Py_ssize_tP), + #('smalltable', rffi.CFixedArray(Py_ssize_t, 2)), + ('internal', rffi.VOIDP) )) @specialize.memo() diff --git a/pypy/module/cpyext/include/object.h b/pypy/module/cpyext/include/object.h --- a/pypy/module/cpyext/include/object.h +++ b/pypy/module/cpyext/include/object.h @@ -131,18 +131,18 @@ /* 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; */ + Py_ssize_t itemsize; + int readonly; + int ndim; + char *format; + Py_ssize_t *shape; + Py_ssize_t *strides; + Py_ssize_t *suboffsets; /* static store for shape and strides of mono-dimensional buffers. */ /* Py_ssize_t smalltable[2]; */ - /* void *internal; */ + void *internal; } Py_buffer; diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py --- a/pypy/module/cpyext/object.py +++ b/pypy/module/cpyext/object.py @@ -439,6 +439,8 @@ return 0 +PyBUF_WRITABLE = 0x0001 # Copied from object.h + @cpython_api([lltype.Ptr(Py_buffer), PyObject, rffi.VOIDP, Py_ssize_t, lltype.Signed, lltype.Signed], rffi.INT, error=CANNOT_FAIL) def PyBuffer_FillInfo(space, view, obj, buf, length, readonly, flags): @@ -454,6 +456,18 @@ view.c_len = length view.c_obj = obj Py_IncRef(space, obj) + view.c_itemsize = 1 + if flags & PyBUF_WRITABLE: + rffi.setintfield(view, 'c_readonly', 0) + else: + rffi.setintfield(view, 'c_readonly', 1) + rffi.setintfield(view, 'c_ndim', 0) + view.c_format = lltype.nullptr(rffi.CCHARP.TO) + view.c_shape = lltype.nullptr(Py_ssize_tP.TO) + view.c_strides = lltype.nullptr(Py_ssize_tP.TO) + view.c_suboffsets = lltype.nullptr(Py_ssize_tP.TO) + view.c_internal = lltype.nullptr(rffi.VOIDP.TO) + return 0 _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit