Author: Ronan Lamy <ronan.l...@gmail.com> Branch: Changeset: r91669:bb398c8ed6e0 Date: 2017-07-03 18:35 +0100 http://bitbucket.org/pypy/pypy/changeset/bb398c8ed6e0/
Log: Define PyMemoryViewObject from C code diff --git a/pypy/module/cpyext/include/memoryobject.h b/pypy/module/cpyext/include/memoryobject.h --- a/pypy/module/cpyext/include/memoryobject.h +++ b/pypy/module/cpyext/include/memoryobject.h @@ -5,14 +5,7 @@ extern "C" { #endif -/* The struct is declared here but it shouldn't - be considered public. Don't access those fields directly, - use the functions instead! */ -typedef struct { - PyObject_HEAD - Py_buffer view; -} PyMemoryViewObject; - +#include "cpyext_memoryobject.h" /* Get a pointer to the memoryview's private copy of the exporter's buffer. */ #define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view) diff --git a/pypy/module/cpyext/memoryobject.py b/pypy/module/cpyext/memoryobject.py --- a/pypy/module/cpyext/memoryobject.py +++ b/pypy/module/cpyext/memoryobject.py @@ -1,11 +1,8 @@ -from rpython.rlib.objectmodel import keepalive_until_here -from pypy.interpreter.error import oefmt from pypy.module.cpyext.api import ( - cpython_api, Py_buffer, CANNOT_FAIL, Py_MAX_FMT, Py_MAX_NDIMS, - build_type_checkers, Py_ssize_tP, PyObjectFields, cpython_struct, - bootstrap_function, Py_bufferP, slot_function, generic_cpy_call) + cpython_api, CANNOT_FAIL, Py_MAX_FMT, Py_MAX_NDIMS, build_type_checkers, + Py_ssize_tP, cts, parse_dir, bootstrap_function, Py_bufferP, slot_function) from pypy.module.cpyext.pyobject import ( - PyObject, make_ref, as_pyobj, decref, from_ref, make_typedescr, + PyObject, make_ref, decref, from_ref, make_typedescr, get_typedescr, track_reference) from rpython.rtyper.lltypesystem import lltype, rffi from rpython.rlib.rarithmetic import widen @@ -13,17 +10,12 @@ from pypy.module.cpyext.object import _dealloc from pypy.module.cpyext.import_ import PyImport_Import +cts.parse_header(parse_dir / 'cpyext_memoryobject.h') +PyMemoryViewObject = cts.gettype('PyMemoryViewObject*') + PyMemoryView_Check, PyMemoryView_CheckExact = build_type_checkers("MemoryView") -PyMemoryViewObjectStruct = lltype.ForwardReference() -PyMemoryViewObject = lltype.Ptr(PyMemoryViewObjectStruct) -PyMemoryViewObjectFields = PyObjectFields + \ - (("view", Py_buffer),) -cpython_struct( - "PyMemoryViewObject", PyMemoryViewObjectFields, PyMemoryViewObjectStruct, - level=2) - @bootstrap_function def init_memoryobject(space): "Type description of PyDictObject" @@ -32,7 +24,7 @@ attach=memory_attach, dealloc=memory_dealloc, realize=memory_realize, - ) + ) def memory_attach(space, py_obj, w_obj, w_userdata=None): """ _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit