Kaydet (Commit) 560da62f authored tarafından Martin v. Löwis's avatar Martin v. Löwis

Rename get_referents to get_referrers. Fixes #483815.

üst 8c1ab14a
...@@ -78,6 +78,13 @@ Return the current collection thresholds as a tuple of ...@@ -78,6 +78,13 @@ Return the current collection thresholds as a tuple of
\code{(\var{threshold0}, \var{threshold1}, \var{threshold2})}. \code{(\var{threshold0}, \var{threshold1}, \var{threshold2})}.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{get_referrers}{*objs}
Return the list of objects that directly refer to any of objs. This
function will only locate those containers which support garbage
collection; extension types which do refer to other objects but do not
support garbage collection will not be found.
\versionadded{2.2}
\end{funcdesc}
The following variable is provided for read-only access (you can The following variable is provided for read-only access (you can
mutate its value but should not rebind it): mutate its value but should not rebind it):
......
...@@ -8,6 +8,8 @@ Core and builtins ...@@ -8,6 +8,8 @@ Core and builtins
Extension modules Extension modules
- gc.get_referents was renamed to gc.get_referrers.
Library Library
Tools/Demos Tools/Demos
...@@ -905,6 +907,8 @@ Library ...@@ -905,6 +907,8 @@ Library
- The `new' module now exposes the CO_xxx flags. - The `new' module now exposes the CO_xxx flags.
- The gc module offers the get_referents function.
New platforms New platforms
C API C API
......
...@@ -648,7 +648,7 @@ gc_get_thresh(PyObject *self, PyObject *args) ...@@ -648,7 +648,7 @@ gc_get_thresh(PyObject *self, PyObject *args)
} }
static int static int
referentsvisit(PyObject* obj, PyObject *objs) referrersvisit(PyObject* obj, PyObject *objs)
{ {
if (PySequence_Contains(objs, obj)) { if (PySequence_Contains(objs, obj)) {
return 1; return 1;
...@@ -657,7 +657,7 @@ referentsvisit(PyObject* obj, PyObject *objs) ...@@ -657,7 +657,7 @@ referentsvisit(PyObject* obj, PyObject *objs)
} }
static int static int
gc_referents_for(PyObject *objs, PyGC_Head *list, PyObject *resultlist) gc_referrers_for(PyObject *objs, PyGC_Head *list, PyObject *resultlist)
{ {
PyGC_Head *gc; PyGC_Head *gc;
PyObject *obj; PyObject *obj;
...@@ -667,7 +667,7 @@ gc_referents_for(PyObject *objs, PyGC_Head *list, PyObject *resultlist) ...@@ -667,7 +667,7 @@ gc_referents_for(PyObject *objs, PyGC_Head *list, PyObject *resultlist)
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, objs)) { if (traverse(obj, (visitproc)referrersvisit, objs)) {
if (PyList_Append(resultlist, obj) < 0) if (PyList_Append(resultlist, obj) < 0)
return 0; /* error */ return 0; /* error */
} }
...@@ -675,17 +675,17 @@ gc_referents_for(PyObject *objs, PyGC_Head *list, PyObject *resultlist) ...@@ -675,17 +675,17 @@ gc_referents_for(PyObject *objs, PyGC_Head *list, PyObject *resultlist)
return 1; /* no error */ return 1; /* no error */
} }
static char gc_get_referents__doc__[]= static char gc_get_referrers__doc__[]=
"get_referents(*objs) -> list\n\ "get_referrers(*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_referrers(PyObject *self, PyObject *args)
{ {
PyObject *result = PyList_New(0); PyObject *result = PyList_New(0);
if (!(gc_referents_for(args, &_PyGC_generation0, result) && if (!(gc_referrers_for(args, &_PyGC_generation0, result) &&
gc_referents_for(args, &generation1, result) && gc_referrers_for(args, &generation1, result) &&
gc_referents_for(args, &generation2, result))) { gc_referrers_for(args, &generation2, result))) {
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;
} }
...@@ -740,7 +740,7 @@ static char gc__doc__ [] = ...@@ -740,7 +740,7 @@ static char gc__doc__ [] =
"set_threshold() -- Set the collection thresholds.\n" "set_threshold() -- Set the collection thresholds.\n"
"get_threshold() -- Return the current the collection thresholds.\n" "get_threshold() -- Return the current the collection thresholds.\n"
"get_objects() -- Return a list of all objects tracked by the collector.\n" "get_objects() -- Return a list of all objects tracked by the collector.\n"
"get_referents() -- Return the list of objects that refer to an object.\n" "get_referrers() -- Return the list of objects that refer to an object.\n"
; ;
static PyMethodDef GcMethods[] = { static PyMethodDef GcMethods[] = {
...@@ -753,8 +753,8 @@ static PyMethodDef GcMethods[] = { ...@@ -753,8 +753,8 @@ static PyMethodDef GcMethods[] = {
{"get_threshold", gc_get_thresh, METH_VARARGS, gc_get_thresh__doc__}, {"get_threshold", gc_get_thresh, METH_VARARGS, gc_get_thresh__doc__},
{"collect", gc_collect, METH_VARARGS, gc_collect__doc__}, {"collect", gc_collect, METH_VARARGS, gc_collect__doc__},
{"get_objects", gc_get_objects,METH_VARARGS, gc_get_objects__doc__}, {"get_objects", gc_get_objects,METH_VARARGS, gc_get_objects__doc__},
{"get_referents", gc_get_referents, METH_VARARGS, {"get_referrers", gc_get_referrers, METH_VARARGS,
gc_get_referents__doc__}, gc_get_referrers__doc__},
{NULL, NULL} /* Sentinel */ {NULL, NULL} /* Sentinel */
}; };
......
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