Author: Ronan Lamy <[email protected]>
Branch: cpyext-nowrapper
Changeset: r92576:cdc783955b0e
Date: 2017-10-03 16:44 +0200
http://bitbucket.org/pypy/pypy/changeset/cdc783955b0e/

Log:    (antocuni, ronan, arigo around) Make _Py_Dealloc no_gc and fix its
        calling from RPython

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
@@ -353,7 +353,21 @@
 
     def get_unwrapper(self):
         if self.no_gc:
-            return self.callable
+            @specialize.ll()
+            @rgc.no_collect
+            def unwrapper(*args):
+                # see "Handling of the GIL" above
+                tid = rthread.get_ident()
+                assert cpyext_glob_tid_ptr[0] == 0
+                cpyext_glob_tid_ptr[0] = tid
+                try:
+                    # Call the function
+                    return self.callable(*args)
+                finally:
+                    assert cpyext_glob_tid_ptr[0] == tid
+                    cpyext_glob_tid_ptr[0] = 0
+            return unwrapper
+
         names = self.argnames
         argtypesw = zip(self.argtypes,
                         [_name.startswith("w_") for _name in self.argnames])
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
@@ -323,7 +323,7 @@
             assert obj.c_ob_pypy_link == 0 or obj.c_ob_refcnt > 
rawrefcount.REFCNT_FROM_PYPY
             obj.c_ob_refcnt -= 1
             if obj.c_ob_refcnt == 0:
-                _Py_Dealloc(space, obj)
+                _Py_Dealloc(obj)
             #else:
             #    w_obj = rawrefcount.to_obj(W_Root, ref)
             #    if w_obj is not None:
@@ -348,14 +348,11 @@
     assert isinstance(w_type, W_TypeObject)
     get_typedescr(w_type.layout.typedef).realize(space, obj)
 
-@cpython_api([PyObject], lltype.Void)
-def _Py_Dealloc(space, obj):
-    from pypy.module.cpyext.api import generic_cpy_call
+@cpython_api([PyObject], lltype.Void, no_gc=True)
+def _Py_Dealloc(obj):
     pto = obj.c_ob_type
-    #print >>sys.stderr, "Calling dealloc slot", pto.c_tp_dealloc, "of", obj, \
-    #      "'s type which is", rffi.charp2str(pto.c_tp_name)
     rawrefcount.mark_deallocating(w_marker_deallocating, obj)
-    generic_cpy_call(space, pto.c_tp_dealloc, obj)
+    pto.c_tp_dealloc(obj)
 
 @cpython_api([rffi.VOIDP], lltype.Signed, error=CANNOT_FAIL)
 def _Py_HashPointer(space, ptr):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to