[pypy-svn] r79854 - in pypy/trunk/pypy/module/cpyext: . src
arigo at codespeak.net
arigo at codespeak.net
Mon Dec 6 18:20:35 CET 2010
Author: arigo
Date: Mon Dec 6 18:20:32 2010
New Revision: 79854
Added:
pypy/trunk/pypy/module/cpyext/pypyintf.py
Modified:
pypy/trunk/pypy/module/cpyext/__init__.py
pypy/trunk/pypy/module/cpyext/src/getargs.c
Log:
Rewrite getargs.c to use PyPy_Borrow(), a new function that
register a borrowing dependency from C code.
Modified: pypy/trunk/pypy/module/cpyext/__init__.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/__init__.py (original)
+++ pypy/trunk/pypy/module/cpyext/__init__.py Mon Dec 6 18:20:32 2010
@@ -69,6 +69,7 @@
import pypy.module.cpyext.weakrefobject
import pypy.module.cpyext.funcobject
import pypy.module.cpyext.classobject
+import pypy.module.cpyext.pypyintf
# now that all rffi_platform.Struct types are registered, configure them
api.configure_types()
Added: pypy/trunk/pypy/module/cpyext/pypyintf.py
==============================================================================
--- (empty file)
+++ pypy/trunk/pypy/module/cpyext/pypyintf.py Mon Dec 6 18:20:32 2010
@@ -0,0 +1,9 @@
+from pypy.module.cpyext.api import cpython_api
+from pypy.module.cpyext.pyobject import PyObject, borrow_from
+
+
+ at cpython_api([PyObject, PyObject], PyObject)
+def PyPy_Borrow(space, w_parentobj, w_obj):
+ """Returns a borrowed reference to 'obj', borrowing from the 'parentobj'.
+ """
+ return borrow_from(w_parentobj, w_obj)
Modified: pypy/trunk/pypy/module/cpyext/src/getargs.c
==============================================================================
--- pypy/trunk/pypy/module/cpyext/src/getargs.c (original)
+++ pypy/trunk/pypy/module/cpyext/src/getargs.c Mon Dec 6 18:20:32 2010
@@ -445,22 +445,19 @@
for (i = 0; i < n; i++) {
char *msg;
PyObject *item;
- /* CPython uses PySequence_GetItem() and Py_XDECREF() here,
- exposing a crash (see http://bugs.python.org/issue6083).
- It always crashes with PyPy, so we apply the fix being
- discussed: we only allow a tuple. */
- item = PyTuple_GetItem(arg, i);
+ item = PySequence_GetItem(arg, i);
if (item == NULL) {
PyErr_Clear();
levels[0] = i+1;
levels[1] = 0;
- strncpy(msgbuf, "is not retrievable (subargument "
- "must be a real tuple with PyPy)",
- bufsize);
+ strncpy(msgbuf, "is not retrievable", bufsize);
return msgbuf;
}
+ PyPy_Borrow(arg, item);
msg = convertitem(item, &format, p_va, flags, levels+1,
msgbuf, bufsize, freelist);
+ /* PySequence_GetItem calls tp->sq_item, which INCREFs */
+ Py_XDECREF(item);
if (msg != NULL) {
levels[0] = i+1;
return msg;
More information about the Pypy-commit
mailing list