Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: py3.5
Changeset: r92458:8d9b5b766682
Date: 2017-09-24 19:52 +0100
http://bitbucket.org/pypy/pypy/changeset/8d9b5b766682/

Log:    fix

diff --git a/pypy/module/cpyext/genobject.py b/pypy/module/cpyext/genobject.py
--- a/pypy/module/cpyext/genobject.py
+++ b/pypy/module/cpyext/genobject.py
@@ -1,7 +1,8 @@
+from rpython.rtyper.lltypesystem import lltype
 from pypy.interpreter.generator import GeneratorIterator, Coroutine
 from pypy.module.cpyext.api import (
-    build_type_checkers, cts, parse_dir, bootstrap_function)
-from pypy.module.cpyext.pyobject import make_typedescr, as_pyobj
+    build_type_checkers, cts, parse_dir, bootstrap_function, slot_function)
+from pypy.module.cpyext.pyobject import PyObject, make_typedescr, as_pyobj
 from pypy.module.cpyext.object import _dealloc
 
 cts.parse_header(parse_dir / 'cpyext_genobject.h')
@@ -11,7 +12,7 @@
     make_typedescr(GeneratorIterator.typedef,
                    basestruct=cts.gettype('PyGenObject'),
                    attach=gi_attach,
-                   dealloc=_dealloc)
+                   dealloc=gi_dealloc)
 
 
 PyGen_Check, PyGen_CheckExact = build_type_checkers("Gen", GeneratorIterator)
@@ -19,11 +20,12 @@
 _, PyCoro_CheckExact = build_type_checkers("Coro", Coroutine)
 
 def gi_attach(space, py_obj, w_obj, w_userdata=None):
-    py_obj.c_gi_code = as_pyobj(space, w_obj.pycode)
+    cts.cast('PyGenObject*', py_obj).c_gi_code = as_pyobj(space, w_obj.pycode)
 
 def gi_realize(space, py_obj):
     raise NotImplementedError(
         "PyPy doesn't support creation of generators from the C-API.")
 
+@slot_function([PyObject], lltype.Void)
 def gi_dealloc(space, py_obj):
     _dealloc(space, py_obj)
diff --git a/pypy/module/cpyext/include/Python.h 
b/pypy/module/cpyext/include/Python.h
--- a/pypy/module/cpyext/include/Python.h
+++ b/pypy/module/cpyext/include/Python.h
@@ -127,6 +127,7 @@
 #include "pycapsule.h"
 #include "bytesobject.h"
 #include "sliceobject.h"
+#include "genobject.h"
 #include "datetime.h"
 #include "pystate.h"
 #include "fileobject.h"
diff --git a/pypy/module/cpyext/test/test_genobject.py 
b/pypy/module/cpyext/test/test_genobject.py
--- a/pypy/module/cpyext/test/test_genobject.py
+++ b/pypy/module/cpyext/test/test_genobject.py
@@ -40,15 +40,16 @@
              else
                 Py_RETURN_FALSE;
              ''')])
+
         def it():
             yield 42
 
         print(module.is_coroutine(it()))
         assert module.is_coroutine(it()) is False
+        self.debug_collect()  # don't crash while deallocating
         from types import coroutine
         assert module.is_coroutine(coroutine(it)()) is True
 
-
     def test_await(self):
         """
         module = self.import_extension('test_coroutine', [
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to