[pypy-svn] r73413 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
xoraxax at codespeak.net
xoraxax at codespeak.net
Mon Apr 5 17:41:35 CEST 2010
Author: xoraxax
Date: Mon Apr 5 17:41:33 2010
New Revision: 73413
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py
pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py
Log:
Fix leaks in test_object and test_unicodeobject.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py Mon Apr 5 17:41:33 2010
@@ -1,7 +1,7 @@
import py
from pypy.module.cpyext.test.test_api import BaseApiTest
-from pypy.rpython.lltypesystem import rffi
+from pypy.rpython.lltypesystem import rffi, lltype
class TestObject(BaseApiTest):
@@ -44,10 +44,14 @@
assert x.test == 10
def test_getattr_string(self, space, api):
- assert api.PyObject_GetAttrString(space.wrap(""), rffi.str2charp("__len__"))
- assert not api.PyObject_GetAttrString(space.wrap(""), rffi.str2charp("not_real"))
+ charp1 = rffi.str2charp("__len__")
+ charp2 = rffi.str2charp("not_real")
+ assert api.PyObject_GetAttrString(space.wrap(""), charp1)
+ assert not api.PyObject_GetAttrString(space.wrap(""), charp2)
assert api.PyErr_Occurred() is space.w_AttributeError
api.PyErr_Clear()
+ lltype.free(charp1, flavor="raw")
+ lltype.free(charp2, flavor="raw")
def test_getitem(self, space, api):
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py Mon Apr 5 17:41:33 2010
@@ -15,7 +15,8 @@
from pypy.module.cpyext.api import cpython_api, cpython_api_c, cpython_struct, \
PyVarObjectFields, Py_ssize_t, Py_TPFLAGS_READYING, generic_cpy_call, \
Py_TPFLAGS_READY, Py_TPFLAGS_HEAPTYPE, PyStringObject, ADDR, \
- Py_TPFLAGS_HAVE_CLASS, METH_VARARGS, METH_KEYWORDS
+ Py_TPFLAGS_HAVE_CLASS, METH_VARARGS, METH_KEYWORDS, \
+ PyUnicodeObject
from pypy.module.cpyext.pyobject import PyObject, make_ref, from_ref
from pypy.interpreter.module import Module
from pypy.interpreter.function import FunctionWithFixedCode, StaticMethod
@@ -319,6 +320,17 @@
Py_DecRef(space, pto)
@cpython_api([PyObject], lltype.Void, external=False)
+def unicode_dealloc(space, obj):
+ obj = rffi.cast(PyUnicodeObject, obj)
+ pto = obj.c_ob_type
+ if obj.c_buffer:
+ lltype.free(obj.c_buffer, flavor="raw")
+ obj_voidp = rffi.cast(rffi.VOIDP_real, obj)
+ generic_cpy_call(space, pto.c_tp_free, obj_voidp)
+ pto = rffi.cast(PyObject, pto)
+ Py_DecRef(space, pto)
+
+ at cpython_api([PyObject], lltype.Void, external=False)
def type_dealloc(space, obj):
state = space.fromcache(State)
obj_pto = rffi.cast(PyTypeObjectPtr, obj)
@@ -357,6 +369,9 @@
elif space.is_w(w_type, space.w_str):
pto.c_tp_dealloc = llhelper(string_dealloc.api_func.functype,
string_dealloc.api_func.get_wrapper(space))
+ elif space.is_w(w_type, space.w_unicode):
+ pto.c_tp_dealloc = llhelper(unicode_dealloc.api_func.functype,
+ unicode_dealloc.api_func.get_wrapper(space))
else:
pto.c_tp_dealloc = llhelper(subtype_dealloc.api_func.functype,
subtype_dealloc.api_func.get_wrapper(space))
More information about the Pypy-commit
mailing list