[pypy-commit] pypy py3k: store the ref to the owning object in CBuffer instead of the object itself for
pjenvey
noreply at buildbot.pypy.org
Sat Aug 30 22:35:23 CEST 2014
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r73214:c4c79992f1f8
Date: 2014-08-30 13:31 -0700
http://bitbucket.org/pypy/pypy/changeset/c4c79992f1f8/
Log: store the ref to the owning object in CBuffer instead of the object
itself for later Py_DecRef'ing (which acts upon the ref anyway).
simplifies the destructor enough to workaround a del calls to much
translation error
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
@@ -1,6 +1,5 @@
from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.rlib import buffer
-from rpython.rlib.objectmodel import import_from_mixin
from pypy.module.cpyext.api import (
cpython_api, CANNOT_FAIL, Py_buffer)
from pypy.module.cpyext.pyobject import PyObject, Py_DecRef
@@ -13,17 +12,18 @@
# PyPy only supports contiguous Py_buffers for now.
return 1
-class CBufferMixin(object):
+class CBuffer(buffer.Buffer):
- def __init__(self, space, c_buf, c_len, w_obj):
+ _immutable_ = True
+
+ def __init__(self, space, c_buf, c_len, c_obj):
self.space = space
self.c_buf = c_buf
self.c_len = c_len
- self.w_obj = w_obj
+ self.c_obj = c_obj
- def destructor(self):
- assert isinstance(self, CBufferMixin)
- Py_DecRef(self.space, self.w_obj)
+ def __del__(self):
+ Py_DecRef(self.space, self.c_obj)
def getlength(self):
return self.c_len
@@ -34,10 +34,3 @@
def as_str(self):
return rffi.charpsize2str(rffi.cast(rffi.CCHARP, self.c_buf),
self.c_len)
-
-class CBuffer(buffer.Buffer):
- import_from_mixin(CBufferMixin)
- _immutable_ = True
-
- def __del__(self):
- CBufferMixin.destructor(self)
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
@@ -20,6 +20,5 @@
raise oefmt(space.w_ValueError,
"cannot make memory view from a buffer with a NULL data "
"pointer")
- w_obj = from_ref(space, view.c_obj)
- buf = CBuffer(space, view.c_buf, view.c_len, w_obj)
+ buf = CBuffer(space, view.c_buf, view.c_len, view.c_obj)
return space.wrap(W_MemoryView(buf))
More information about the pypy-commit
mailing list