Author: Armin Rigo <[email protected]>
Branch:
Changeset: r92685:386fcca6c58f
Date: 2017-10-09 16:54 +0200
http://bitbucket.org/pypy/pypy/changeset/386fcca6c58f/
Log: merge heads
diff --git a/pypy/module/cpyext/dictobject.py b/pypy/module/cpyext/dictobject.py
--- a/pypy/module/cpyext/dictobject.py
+++ b/pypy/module/cpyext/dictobject.py
@@ -258,7 +258,7 @@
if w_dict is None:
return 0
if not space.isinstance_w(w_dict, space.w_dict):
- return 0
+ return 0
pos = ppos[0]
py_obj = as_pyobj(space, w_dict)
py_dict = rffi.cast(PyDictObject, py_obj)
@@ -266,6 +266,8 @@
# Store the current keys in the PyDictObject.
decref(space, py_dict.c__tmpkeys)
w_keys = space.call_method(space.w_dict, "keys", w_dict)
+ # w_keys must use the object strategy in order to keep the keys alive
+ w_keys.switch_to_object_strategy()
py_dict.c__tmpkeys = create_ref(space, w_keys)
Py_IncRef(space, py_dict.c__tmpkeys)
else:
@@ -278,10 +280,10 @@
decref(space, py_dict.c__tmpkeys)
py_dict.c__tmpkeys = lltype.nullptr(PyObject.TO)
return 0
- w_key = space.listview(w_keys)[pos]
+ w_key = space.listview(w_keys)[pos] # fast iff w_keys uses object strat
w_value = space.getitem(w_dict, w_key)
if pkey:
- pkey[0] = as_pyobj(space, w_key)
+ pkey[0] = as_pyobj(space, w_key)
if pvalue:
pvalue[0] = as_pyobj(space, w_value)
return 1
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
@@ -15,7 +15,7 @@
from rpython.rlib.objectmodel import keepalive_until_here
from rpython.rtyper.annlowlevel import llhelper
from rpython.rlib import rawrefcount, jit
-from rpython.rlib.debug import fatalerror
+from rpython.rlib.debug import ll_assert, fatalerror
#________________________________________________________
@@ -243,6 +243,11 @@
py_obj = rawrefcount.from_obj(PyObject, w_obj)
if not py_obj:
py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
+ #
+ # Try to crash here, instead of randomly, if we don't keep w_obj alive
+ ll_assert(py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY,
+ "Bug in cpyext: The W_Root object was garbage-collected "
+ "while being converted to PyObject.")
return py_obj
else:
return lltype.nullptr(PyObject.TO)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit