summaryrefslogtreecommitdiff
path: root/Modules/_weakref.c
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2004-07-02 18:57:45 +0000
committerFred Drake <fdrake@acm.org>2004-07-02 18:57:45 +0000
commit0a4dd390bf653128de8bc2e99da64967c8cdf86e (patch)
tree9c3b3989bc85eda1277464459cda1eae87f5d7a5 /Modules/_weakref.c
parent813914049de32303ce31cae11abe9c5a49a08a4e (diff)
downloadcpython-git-0a4dd390bf653128de8bc2e99da64967c8cdf86e.tar.gz
Make weak references subclassable:
- weakref.ref and weakref.ReferenceType will become aliases for each other - weakref.ref will be a modern, new-style class with proper __new__ and __init__ methods - weakref.WeakValueDictionary will have a lighter memory footprint, using a new weakref.ref subclass to associate the key with the value, allowing us to have only a single object of overhead for each dictionary entry (currently, there are 3 objects of overhead per entry: a weakref to the value, a weakref to the dictionary, and a function object used as a weakref callback; the weakref to the dictionary could be avoided without this change) - a new macro, PyWeakref_CheckRefExact(), will be added - PyWeakref_CheckRef() will check for subclasses of weakref.ref This closes SF patch #983019.
Diffstat (limited to 'Modules/_weakref.c')
-rw-r--r--Modules/_weakref.c25
1 files changed, 3 insertions, 22 deletions
diff --git a/Modules/_weakref.c b/Modules/_weakref.c
index 21521150ae..2dfdc1424d 100644
--- a/Modules/_weakref.c
+++ b/Modules/_weakref.c
@@ -57,26 +57,6 @@ weakref_getweakrefs(PyObject *self, PyObject *object)
}
-PyDoc_STRVAR(weakref_ref__doc__,
-"ref(object[, callback]) -- create a weak reference to 'object';\n"
-"when 'object' is finalized, 'callback' will be called and passed\n"
-"a reference to the weak reference object when 'object' is about\n"
-"to be finalized.");
-
-static PyObject *
-weakref_ref(PyObject *self, PyObject *args)
-{
- PyObject *object;
- PyObject *callback = NULL;
- PyObject *result = NULL;
-
- if (PyArg_UnpackTuple(args, "ref", 1, 2, &object, &callback)) {
- result = PyWeakref_NewRef(object, callback);
- }
- return result;
-}
-
-
PyDoc_STRVAR(weakref_proxy__doc__,
"proxy(object[, callback]) -- create a proxy object that weakly\n"
"references 'object'. 'callback', if given, is called with a\n"
@@ -104,8 +84,6 @@ weakref_functions[] = {
weakref_getweakrefs__doc__},
{"proxy", weakref_proxy, METH_VARARGS,
weakref_proxy__doc__},
- {"ref", weakref_ref, METH_VARARGS,
- weakref_ref__doc__},
{NULL, NULL, 0, NULL}
};
@@ -119,6 +97,9 @@ init_weakref(void)
"Weak-reference support module.");
if (m != NULL) {
Py_INCREF(&_PyWeakref_RefType);
+ PyModule_AddObject(m, "ref",
+ (PyObject *) &_PyWeakref_RefType);
+ Py_INCREF(&_PyWeakref_RefType);
PyModule_AddObject(m, "ReferenceType",
(PyObject *) &_PyWeakref_RefType);
Py_INCREF(&_PyWeakref_ProxyType);