[pypy-commit] pypy fix-cpyext-releasebuffer: Call bf_releasebuffer slot from PyBuffer_Release
rlamy
pypy.commits at gmail.com
Thu Mar 2 07:57:19 EST 2017
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: fix-cpyext-releasebuffer
Changeset: r90479:f03c4719447c
Date: 2017-03-02 13:56 +0100
http://bitbucket.org/pypy/pypy/changeset/f03c4719447c/
Log: Call bf_releasebuffer slot from PyBuffer_Release
diff --git a/pypy/module/cpyext/buffer.py b/pypy/module/cpyext/buffer.py
--- a/pypy/module/cpyext/buffer.py
+++ b/pypy/module/cpyext/buffer.py
@@ -2,7 +2,7 @@
from pypy.interpreter.error import oefmt
from pypy.module.cpyext.api import (
cpython_api, CANNOT_FAIL, Py_TPFLAGS_HAVE_NEWBUFFER, cts, Py_buffer,
- Py_ssize_t, Py_ssize_tP,
+ Py_ssize_t, Py_ssize_tP, generic_cpy_call,
PyBUF_WRITABLE, PyBUF_FORMAT, PyBUF_ND, PyBUF_STRIDES)
from pypy.module.cpyext.pyobject import PyObject, Py_IncRef, Py_DecRef
@@ -60,6 +60,15 @@
Release the buffer view. This should be called when the buffer is
no longer being used as it may free memory from it
"""
- Py_DecRef(space, view.c_obj)
+ obj = view.c_obj
+ if not obj:
+ return
+ assert obj.c_ob_type
+ as_buffer = obj.c_ob_type.c_tp_as_buffer
+ if as_buffer:
+ func = as_buffer.c_bf_releasebuffer
+ if func:
+ generic_cpy_call(space, func, obj, view)
+ Py_DecRef(space, obj)
view.c_obj = lltype.nullptr(PyObject.TO)
# XXX do other fields leak memory?
diff --git a/pypy/module/cpyext/test/array.c b/pypy/module/cpyext/test/array.c
--- a/pypy/module/cpyext/test/array.c
+++ b/pypy/module/cpyext/test/array.c
@@ -2023,7 +2023,7 @@
}
static void
-array_releasebuffer(arrayobject* self)
+array_releasebuffer(arrayobject* self, Py_buffer* view)
{
releasebuffer_cnt++;
return;
More information about the pypy-commit
mailing list