[pypy-svn] r74189 - pypy/branch/cpython-extension/pypy/module/cpyext

afa at codespeak.net afa at codespeak.net
Wed Apr 28 19:03:59 CEST 2010


Author: afa
Date: Wed Apr 28 19:03:57 2010
New Revision: 74189

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/funcobject.py
   pypy/branch/cpython-extension/pypy/module/cpyext/methodobject.py
   pypy/branch/cpython-extension/pypy/module/cpyext/object.py
   pypy/branch/cpython-extension/pypy/module/cpyext/stringobject.py
   pypy/branch/cpython-extension/pypy/module/cpyext/unicodeobject.py
Log:
Most types now call PyObject_dealloc() instead of copying the same code again and again
For some reason this did not work with type_dealloc, why?


Modified: pypy/branch/cpython-extension/pypy/module/cpyext/funcobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/funcobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/funcobject.py	Wed Apr 28 19:03:57 2010
@@ -30,12 +30,8 @@
 def function_dealloc(space, py_obj):
     py_func = rffi.cast(PyFunctionObject, py_obj)
     Py_DecRef(space, py_func.c_func_name)
-    # standard dealloc
-    pto = py_obj.c_ob_type
-    obj_voidp = rffi.cast(rffi.VOIDP_real, py_obj)
-    generic_cpy_call(space, pto.c_tp_free, obj_voidp)
-    pto = rffi.cast(PyObject, pto)
-    Py_DecRef(space, pto)
+    from pypy.module.cpyext.object import PyObject_dealloc
+    PyObject_dealloc(space, py_obj)
 
 @cpython_api([PyObject], PyObject, borrowed=True)
 def PyMethod_Function(space, w_method):

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/methodobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/methodobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/methodobject.py	Wed Apr 28 19:03:57 2010
@@ -54,12 +54,8 @@
 def cfunction_dealloc(space, py_obj):
     py_func = rffi.cast(PyCFunctionObject, py_obj)
     Py_DecRef(space, py_func.c_m_self)
-    # standard dealloc
-    pto = py_obj.c_ob_type
-    obj_voidp = rffi.cast(rffi.VOIDP_real, py_obj)
-    generic_cpy_call(space, pto.c_tp_free, obj_voidp)
-    pto = rffi.cast(PyObject, pto)
-    Py_DecRef(space, pto)
+    from pypy.module.cpyext.object import PyObject_dealloc
+    PyObject_dealloc(space, py_obj)
 
 class W_PyCFunctionObject(Wrappable):
     def __init__(self, space, ml, w_self, doc=None):

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/object.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/object.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/object.py	Wed Apr 28 19:03:57 2010
@@ -31,11 +31,11 @@
 
 @cpython_api([PyObject], lltype.Void)
 def PyObject_dealloc(space, obj):
-    pto = rffi.cast(PyTypeObjectPtr, obj.c_ob_type)
+    pto = obj.c_ob_type
     obj_voidp = rffi.cast(rffi.VOIDP_real, obj)
     generic_cpy_call(space, pto.c_tp_free, obj_voidp)
     if pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE:
-        Py_DecRef(space, rffi.cast(PyObject, obj.c_ob_type))
+        Py_DecRef(space, rffi.cast(PyObject, pto))
 
 @cpython_api([PyTypeObjectPtr], PyObject)
 def _PyObject_GC_New(space, type):

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/stringobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/stringobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/stringobject.py	Wed Apr 28 19:03:57 2010
@@ -51,15 +51,12 @@
     return w_str
 
 @cpython_api([PyObject], lltype.Void, external=False)
-def string_dealloc(space, obj):
-    obj = rffi.cast(PyStringObject, 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)
+def string_dealloc(space, py_obj):
+    py_str = rffi.cast(PyStringObject, py_obj)
+    if py_str.c_buffer:
+        lltype.free(py_str.c_buffer, flavor="raw")
+    from pypy.module.cpyext.object import PyObject_dealloc
+    PyObject_dealloc(space, py_obj)
 
 @cpython_api([CONST_STRING, Py_ssize_t], PyObject)
 def PyString_FromStringAndSize(space, char_p, length):

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/unicodeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/unicodeobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/unicodeobject.py	Wed Apr 28 19:03:57 2010
@@ -40,15 +40,12 @@
     py_unicode.c_buffer = lltype.nullptr(rffi.CWCHARP.TO)
 
 @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)
+def unicode_dealloc(space, py_obj):
+    py_unicode = rffi.cast(PyUnicodeObject, py_obj)
+    if py_unicode.c_buffer:
+        lltype.free(py_unicode.c_buffer, flavor="raw")
+    from pypy.module.cpyext.object import PyObject_dealloc
+    PyObject_dealloc(space, py_obj)
 
 @cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
 def Py_UNICODE_ISSPACE(space, ch):



More information about the Pypy-commit mailing list