Author: Armin Rigo <[email protected]>
Branch: cpyext-avoid-roundtrip
Changeset: r92553:d9618818e9a5
Date: 2017-10-02 12:42 +0200
http://bitbucket.org/pypy/pypy/changeset/d9618818e9a5/

Log:    Kill PyObject_dealloc()

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -1085,6 +1085,9 @@
     state.C._PyPy_subtype_dealloc = rffi.llexternal(
         '_PyPy_subtype_dealloc', [PyObject], lltype.Void,
         compilation_info=eci, _nowrapper=True)
+    state.C._PyPy_object_dealloc = rffi.llexternal(
+        '_PyPy_object_dealloc', [PyObject], lltype.Void,
+        compilation_info=eci, _nowrapper=True)
 
 
 def init_function(func):
diff --git a/pypy/module/cpyext/include/object.h 
b/pypy/module/cpyext/include/object.h
--- a/pypy/module/cpyext/include/object.h
+++ b/pypy/module/cpyext/include/object.h
@@ -336,6 +336,7 @@
 #define PyObject_Length PyObject_Size
 #define _PyObject_GC_Del PyObject_GC_Del
 PyAPI_FUNC(void) _PyPy_subtype_dealloc(PyObject *);
+PyAPI_FUNC(void) _PyPy_object_dealloc(PyObject *);
 
 
 #ifdef __cplusplus
diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
--- a/pypy/module/cpyext/object.py
+++ b/pypy/module/cpyext/object.py
@@ -54,10 +54,6 @@
         w_obj = PyObject_InitVar(space, py_objvar, type, itemcount)
     return py_obj
 
-@slot_function([PyObject], lltype.Void)
-def PyObject_dealloc(space, obj):
-    return _dealloc(space, obj)
-
 def _dealloc(space, obj):
     # This frees an object after its refcount dropped to zero, so we
     # assert that it is really zero here.
diff --git a/pypy/module/cpyext/pyobject.py b/pypy/module/cpyext/pyobject.py
--- a/pypy/module/cpyext/pyobject.py
+++ b/pypy/module/cpyext/pyobject.py
@@ -106,9 +106,12 @@
             def allocate(self, space, w_type, itemcount=0, immortal=False):
                 return tp_alloc(space, w_type, itemcount)
 
-        if tp_dealloc:
+        if hasattr(tp_dealloc, 'api_func'):
             def get_dealloc(self, space):
                 return tp_dealloc.api_func.get_llhelper(space)
+        elif tp_dealloc:
+            def get_dealloc(self, space):
+                return tp_dealloc
 
         if tp_attach:
             def attach(self, space, pyobj, w_obj, w_userdata=None):
@@ -124,10 +127,10 @@
 
 @bootstrap_function
 def init_pyobject(space):
-    from pypy.module.cpyext.object import PyObject_dealloc
     # typedescr for the 'object' type
+    state = space.fromcache(State)
     make_typedescr(space.w_object.layout.typedef,
-                   dealloc=PyObject_dealloc)
+                   dealloc=state.C._PyPy_object_dealloc)
     # almost all types, which should better inherit from object.
     make_typedescr(None)
 
diff --git a/pypy/module/cpyext/src/object.c b/pypy/module/cpyext/src/object.c
--- a/pypy/module/cpyext/src/object.c
+++ b/pypy/module/cpyext/src/object.c
@@ -16,10 +16,22 @@
 
 Py_ssize_t _pypy_rawrefcount_w_marker_deallocating;  /* set from pyobject.py */
 
-void _Py_Dealloc(PyObject *obj)
+void
+_Py_Dealloc(PyObject *obj)
 {
     PyTypeObject *pto = obj->ob_type;
     /* this is the same as rawrefcount.mark_deallocating() */
     obj->ob_pypy_link = _pypy_rawrefcount_w_marker_deallocating;
     pto->tp_dealloc(obj);
 }
+
+void
+_PyPy_object_dealloc(PyObject *obj)
+{
+    PyTypeObject *pto;
+    assert(obj->ob_refcnt == 0);
+    pto = obj->ob_type;
+    pto->tp_free(obj);
+    if (pto->tp_flags & Py_TPFLAGS_HEAPTYPE)
+        Py_DECREF(pto);
+}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to