Author: Ronan Lamy <ronan.l...@gmail.com> Branch: cpyext-leakchecking Changeset: r91962:c99247c01177 Date: 2017-07-25 11:58 +0200 http://bitbucket.org/pypy/pypy/changeset/c99247c01177/
Log: Tweak CPyBuffer.releasebuffer() to make ll2ctypes happy diff --git a/pypy/interpreter/executioncontext.py b/pypy/interpreter/executioncontext.py --- a/pypy/interpreter/executioncontext.py +++ b/pypy/interpreter/executioncontext.py @@ -605,6 +605,7 @@ e.write_unraisable(space, where, w_obj) e.clear(space) # break up reference cycles else: + raise addrstring = w_obj.getaddrstring(space) msg = ("RPython exception %s in %s<%s at 0x%s> ignored\n" % ( str(e), where, space.type(w_obj).name, addrstring)) @@ -615,7 +616,7 @@ def make_finalizer_queue(W_Root, space): """Make a FinalizerQueue subclass which responds to GC finalizer events by 'firing' the UserDelAction class above. It does not - directly fetches the objects to finalize at all; they stay in the + directly fetches the objects to finalize at all; they stay in the GC-managed queue, and will only be fetched by UserDelAction (between bytecodes).""" 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 @@ -73,19 +73,24 @@ if self.needs_decref: if self.releasebufferproc: func_target = rffi.cast(releasebufferproc, self.releasebufferproc) - with lltype.scoped_alloc(Py_buffer) as pybuf: - pybuf.c_buf = self.ptr - pybuf.c_len = self.size - pybuf.c_ndim = cts.cast('int', self.ndim) - pybuf.c_shape = cts.cast('Py_ssize_t*', pybuf.c__shape) - pybuf.c_strides = cts.cast('Py_ssize_t*', pybuf.c__strides) - for i in range(self.ndim): - pybuf.c_shape[i] = self.shape[i] - pybuf.c_strides[i] = self.strides[i] - with rffi.scoped_str2charp( - self.format if self.format else "B") as fmt: - pybuf.c_format = fmt - generic_cpy_call(self.space, func_target, self.pyobj, pybuf) + size = rffi.sizeof(cts.gettype('Py_buffer')) + pybuf = lltype.malloc(rffi.VOIDP.TO, size, flavor='raw', zero=True) + pybuf = cts.cast('Py_buffer*', pybuf) + pybuf.c_buf = self.ptr + pybuf.c_len = self.size + pybuf.c_ndim = cts.cast('int', self.ndim) + pybuf.c_shape = cts.cast('Py_ssize_t*', pybuf.c__shape) + pybuf.c_strides = cts.cast('Py_ssize_t*', pybuf.c__strides) + for i in range(self.ndim): + pybuf.c_shape[i] = self.shape[i] + pybuf.c_strides[i] = self.strides[i] + fmt = rffi.str2charp(self.format if self.format else "B") + try: + pybuf.c_format = fmt + generic_cpy_call(self.space, func_target, self.pyobj, pybuf) + finally: + lltype.free(fmt, flavor='raw') + lltype.free(pybuf, flavor='raw') decref(self.space, self.pyobj) self.pyobj = lltype.nullptr(PyObject.TO) else: diff --git a/pypy/module/cpyext/test/test_cpyext.py b/pypy/module/cpyext/test/test_cpyext.py --- a/pypy/module/cpyext/test/test_cpyext.py +++ b/pypy/module/cpyext/test/test_cpyext.py @@ -109,9 +109,9 @@ except leakfinder.MallocMismatch as e: result = e.args[0] filtered_result = {} - for obj in result: + for obj, value in result.iteritems(): if not is_allowed_to_leak(self.space, obj): - filtered_result[obj] = result[obj] + filtered_result[obj] = value if filtered_result: raise leakfinder.MallocMismatch(filtered_result) assert not self.space.finalizer_queue.next_dead() diff --git a/rpython/tool/leakfinder.py b/rpython/tool/leakfinder.py --- a/rpython/tool/leakfinder.py +++ b/rpython/tool/leakfinder.py @@ -6,6 +6,7 @@ # So far, this is used for lltype.malloc(flavor='raw'). TRACK_ALLOCATIONS = False ALLOCATED = {} +TB_LINES = 76 class MallocMismatch(Exception): def __str__(self): @@ -13,8 +14,8 @@ dict2 = {} for obj, traceback in dict.items(): traceback = traceback.splitlines() - if len(traceback) > 8: - traceback = [' ...'] + traceback[-6:] + if len(traceback) > TB_LINES + 2: + traceback = [' ...'] + traceback[-TB_LINES:] traceback = '\n'.join(traceback) dict2.setdefault(traceback, []) dict2[traceback].append(obj) @@ -58,7 +59,7 @@ if TRACK_ALLOCATIONS: frame = sys._getframe(framedepth) sio = cStringIO.StringIO() - traceback.print_stack(frame, limit=10, file=sio) + traceback.print_stack(frame, limit=40, file=sio) tb = sio.getvalue() ALLOCATED[obj] = tb _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit