Author: Matti Picus <matti.pi...@gmail.com> Branch: issue2444 Changeset: r89028:c8c4d41979cd Date: 2016-12-12 18:43 +0200 http://bitbucket.org/pypy/pypy/changeset/c8c4d41979cd/
Log: test for calling bf_releasebuffer, pases with -A diff --git a/pypy/module/cpyext/test/test_bufferobject.py b/pypy/module/cpyext/test/test_bufferobject.py --- a/pypy/module/cpyext/test/test_bufferobject.py +++ b/pypy/module/cpyext/test/test_bufferobject.py @@ -64,3 +64,57 @@ b = buffer(a) assert module.roundtrip(b) == 'text' + def test_releasebuffer(self): + module = self.import_extension('foo', [ + ("create_test", "METH_NOARGS", + """ + PyObject *obj; + obj = PyObject_New(PyObject, (PyTypeObject*)type); + return obj; + """), + ("get_cnt", "METH_NOARGS", + 'return PyLong_FromLong(cnt);')], prologue=""" + static float test_data = 42.f; + static int cnt=0; + static PyHeapTypeObject * type=NULL; + + int getbuffer(PyObject *obj, Py_buffer *view, int flags) { + + cnt ++; + memset(view, 0, sizeof(Py_buffer)); + view->obj = obj; + view->ndim = 0; + view->buf = (void *) &test_data; + view->itemsize = sizeof(float); + view->len = 1; + view->strides = NULL; + view->shape = NULL; + view->format = "f"; + return 0; + } + + void releasebuffer(PyObject *obj, Py_buffer *view) { + cnt --; + } + """, more_init=""" + type = (PyHeapTypeObject *) PyType_Type.tp_alloc(&PyType_Type, 0); + + type->ht_type.tp_name = "Test"; + type->ht_type.tp_basicsize = sizeof(PyObject); + type->ht_name = PyString_FromString("Test"); + type->ht_type.tp_flags |= Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | + Py_TPFLAGS_HEAPTYPE | Py_TPFLAGS_HAVE_NEWBUFFER; + type->ht_type.tp_flags &= ~Py_TPFLAGS_HAVE_GC; + + type->ht_type.tp_as_buffer = &type->as_buffer; + type->as_buffer.bf_getbuffer = getbuffer; + type->as_buffer.bf_releasebuffer = releasebuffer; + + if (PyType_Ready(&type->ht_type) < 0) INITERROR; + """, ) + import gc + assert module.get_cnt() == 0 + a = memoryview(module.create_test()) + assert module.get_cnt() == 1 + del a + assert module.get_cnt() == 0 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit