[pypy-dev] [PATCH] Rework borrowed-ref bookkeeping, to fix a crash

Amaury Forgeot d'Arc amauryfa at gmail.com
Sat Mar 12 15:40:55 CET 2011


Hi,

2011/3/12 Greg Price <greg at quora.com>:
> +                 """
> +                    PyObject *t = PyTuple_New(1);
> +                    PyObject *i = PyInt_FromLong(42);
> +                    PyTuple_SetItem(t, 0, i);
> +                    i = PyTuple_GetItem(t, 0);
> +                    PyTuple_GetItem(t, 0);
> +                    Py_DECREF(t);
> +                    return PyInt_FromLong(PyInt_AsLong(i));
> +                 """),

This example is wrong: you don't own the reference to int(42);
after the tuple is released, PyInt_AsLong(i) is illegal.

-- 
Amaury Forgeot d'Arc



More information about the Pypy-dev mailing list