Kaydet (Commit) 17e7be60 authored tarafından Neil Schemenauer's avatar Neil Schemenauer

Remove "referents" structure (it's not needed). Check return value

of PyList_Append.
üst a8b5f7d1
...@@ -677,51 +677,48 @@ gc_get_thresh(PyObject *self, PyObject *args) ...@@ -677,51 +677,48 @@ gc_get_thresh(PyObject *self, PyObject *args)
return Py_BuildValue("(iii)", threshold0, threshold1, threshold2); return Py_BuildValue("(iii)", threshold0, threshold1, threshold2);
} }
struct referents{
PyObject *objs;
int seen;
};
static int static int
referentsvisit(PyObject* obj, struct referents* refs) referentsvisit(PyObject* obj, PyObject *objs)
{ {
if (PySequence_Contains (refs->objs, obj)) { if (PySequence_Contains(objs, obj)) {
refs->seen = 1;
return 1; return 1;
} }
return 0; return 0;
} }
static void static int
gc_referents_for(PyObject *objs, PyGC_Head *list, PyObject *resultlist) gc_referents_for(PyObject *objs, PyGC_Head *list, PyObject *resultlist)
{ {
PyGC_Head *gc; PyGC_Head *gc;
PyObject *obj; PyObject *obj;
traverseproc traverse; traverseproc traverse;
struct referents refs = {objs, 0}; for (gc = list->gc_next; gc != list; gc = gc->gc_next) {
for (gc = list->gc_next; gc != list; gc = gc->gc_next){ obj = PyObject_FROM_GC(gc);
obj = PyObject_FROM_GC(gc);
traverse = obj->ob_type->tp_traverse; traverse = obj->ob_type->tp_traverse;
if (obj == objs || obj == resultlist) if (obj == objs || obj == resultlist)
continue; continue;
if (traverse(obj, (visitproc)referentsvisit, &refs)) { if (traverse(obj, (visitproc)referentsvisit, objs)) {
PyList_Append(resultlist, obj); if (PyList_Append(resultlist, obj) < 0)
refs.seen = 0; return 0; /* error */
} }
} }
return 1; /* no error */
} }
static char gc_get_referents__doc__[]= static char gc_get_referents__doc__[]=
"get_referents(*objs) -> list\n\ "get_referents(*objs) -> list\n\
Return the list of objects that directly refer to any of objs."; Return the list of objects that directly refer to any of objs.";
static PyObject* static PyObject *
gc_get_referents(PyObject *self, PyObject* args) gc_get_referents(PyObject *self, PyObject *args)
{ {
PyObject *result = PyList_New(0); PyObject *result = PyList_New(0);
gc_referents_for(args, &generation0, result); if (!(gc_referents_for(args, &generation0, result) &&
gc_referents_for(args, &generation1, result); gc_referents_for(args, &generation1, result) &&
gc_referents_for(args, &generation2, result); gc_referents_for(args, &generation2, result))) {
Py_DECREF(result);
return NULL;
}
return result; return result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment