diff options
author | Tim Peters <tim.peters@gmail.com> | 2003-04-08 16:39:48 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2003-04-08 16:39:48 (GMT) |
commit | 0f81ab6d8895fb6a0b09d517b872a7816060914d (patch) | |
tree | c172bc134bb36ae75702cb40ce24a262fe63c08c /Modules/gcmodule.c | |
parent | fb2ab4d5ae048ee29e98dee30b9f68652a34da85 (diff) | |
download | cpython-0f81ab6d8895fb6a0b09d517b872a7816060914d.zip cpython-0f81ab6d8895fb6a0b09d517b872a7816060914d.tar.gz cpython-0f81ab6d8895fb6a0b09d517b872a7816060914d.tar.bz2 |
Finished implementing gc.get_referrents(): dealt with error and end
cases, wrote docs, added a test.
Diffstat (limited to 'Modules/gcmodule.c')
-rw-r--r-- | Modules/gcmodule.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 9017363..b0faad2 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -857,12 +857,11 @@ gc_get_referrers(PyObject *self, PyObject *args) return result; } +/* Append obj to list; return true if error (out of memory), false if OK. */ static int referrentsvisit(PyObject *obj, PyObject *list) { - if (PyList_Append(list, obj) < 0) - return 1; - return 0; + return PyList_Append(list, obj) < 0; } PyDoc_STRVAR(gc_get_referrents__doc__, @@ -874,13 +873,23 @@ gc_get_referrents(PyObject *self, PyObject *args) { int i; PyObject *result = PyList_New(0); + + if (result == NULL) + return NULL; + for (i = 0; i < PyTuple_GET_SIZE(args); i++) { + traverseproc traverse; PyObject *obj = PyTuple_GET_ITEM(args, i); - traverseproc traverse = obj->ob_type->tp_traverse; - if (!traverse) + + if (! PyObject_IS_GC(obj)) + continue; + traverse = obj->ob_type->tp_traverse; + if (! traverse) continue; - if (traverse(obj, (visitproc)referrentsvisit, result)) + if (traverse(obj, (visitproc)referrentsvisit, result)) { + Py_DECREF(result); return NULL; + } } return result; } |