summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>2001-08-10 14:46:47 (GMT)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>2001-08-10 14:46:47 (GMT)
commit17e7be60b41b6da2a69a95d6ceab0307389be3c3 (patch)
tree735135ebfb0a7587543f8efc9ba2184b79cda1d4
parenta8b5f7d178cfe3ed7aad27e4741e99e8ea5fb48c (diff)
downloadcpython-17e7be60b41b6da2a69a95d6ceab0307389be3c3.zip
cpython-17e7be60b41b6da2a69a95d6ceab0307389be3c3.tar.gz
cpython-17e7be60b41b6da2a69a95d6ceab0307389be3c3.tar.bz2
Remove "referents" structure (it's not needed). Check return value
of PyList_Append.
-rw-r--r--Modules/gcmodule.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 98a0ee5..dcf0128 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -677,51 +677,48 @@ gc_get_thresh(PyObject *self, PyObject *args)
return Py_BuildValue("(iii)", threshold0, threshold1, threshold2);
}
-struct referents{
- PyObject *objs;
- int seen;
-};
-
static int
-referentsvisit(PyObject* obj, struct referents* refs)
+referentsvisit(PyObject* obj, PyObject *objs)
{
- if (PySequence_Contains (refs->objs, obj)) {
- refs->seen = 1;
+ if (PySequence_Contains(objs, obj)) {
return 1;
}
return 0;
}
-static void
+static int
gc_referents_for(PyObject *objs, PyGC_Head *list, PyObject *resultlist)
{
PyGC_Head *gc;
PyObject *obj;
traverseproc traverse;
- struct referents refs = {objs, 0};
- for (gc = list->gc_next; gc != list; gc = gc->gc_next){
- obj = PyObject_FROM_GC(gc);
+ for (gc = list->gc_next; gc != list; gc = gc->gc_next) {
+ obj = PyObject_FROM_GC(gc);
traverse = obj->ob_type->tp_traverse;
if (obj == objs || obj == resultlist)
continue;
- if (traverse(obj, (visitproc)referentsvisit, &refs)) {
- PyList_Append(resultlist, obj);
- refs.seen = 0;
+ if (traverse(obj, (visitproc)referentsvisit, objs)) {
+ if (PyList_Append(resultlist, obj) < 0)
+ return 0; /* error */
}
}
+ return 1; /* no error */
}
static char gc_get_referents__doc__[]=
"get_referents(*objs) -> list\n\
Return the list of objects that directly refer to any of objs.";
-static PyObject*
-gc_get_referents(PyObject *self, PyObject* args)
+static PyObject *
+gc_get_referents(PyObject *self, PyObject *args)
{
PyObject *result = PyList_New(0);
- gc_referents_for(args, &generation0, result);
- gc_referents_for(args, &generation1, result);
- gc_referents_for(args, &generation2, result);
+ if (!(gc_referents_for(args, &generation0, result) &&
+ gc_referents_for(args, &generation1, result) &&
+ gc_referents_for(args, &generation2, result))) {
+ Py_DECREF(result);
+ return NULL;
+ }
return result;
}