summaryrefslogtreecommitdiffstats
path: root/Objects/weakrefobject.c
diff options
context:
space:
mode:
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>2002-03-27 15:18:21 (GMT)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>2002-03-27 15:18:21 (GMT)
commit38a8916134adaa0222c0e8d904c2b2b840cfb79b (patch)
tree42d025203f6fc678e3be54fcabd60653fa86f241 /Objects/weakrefobject.c
parent9e38c100ab6135b0f7953ee8cf4e47d85ddecbc8 (diff)
downloadcpython-38a8916134adaa0222c0e8d904c2b2b840cfb79b.zip
cpython-38a8916134adaa0222c0e8d904c2b2b840cfb79b.tar.gz
cpython-38a8916134adaa0222c0e8d904c2b2b840cfb79b.tar.bz2
Remove weakref free list. This has the side effect of fixing a memory
management bug. Also, move some duplicated code into the new_weakref fucntion.
Diffstat (limited to 'Objects/weakrefobject.c')
-rw-r--r--Objects/weakrefobject.c37
1 files changed, 11 insertions, 26 deletions
diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c
index 2e02cf2..021670a 100644
--- a/Objects/weakrefobject.c
+++ b/Objects/weakrefobject.c
@@ -5,9 +5,6 @@
#define GET_WEAKREFS_LISTPTR(o) \
((PyWeakReference **) PyObject_GET_WEAKREFS_LISTPTR(o))
-static PyWeakReference *
-free_list = NULL;
-
long
_PyWeakref_GetWeakrefCount(PyWeakReference *head)
@@ -23,21 +20,18 @@ _PyWeakref_GetWeakrefCount(PyWeakReference *head)
static PyWeakReference *
-new_weakref(void)
+new_weakref(PyObject *ob, PyObject *callback)
{
PyWeakReference *result;
- if (free_list != NULL) {
- result = free_list;
- free_list = result->wr_next;
- result->ob_type = &_PyWeakref_RefType;
- _Py_NewReference((PyObject *)result);
- }
- else {
- result = PyObject_GC_New(PyWeakReference, &_PyWeakref_RefType);
- }
- if (result)
+ result = PyObject_GC_New(PyWeakReference, &_PyWeakref_RefType);
+ if (result) {
result->hash = -1;
+ result->wr_object = ob;
+ Py_XINCREF(callback);
+ result->wr_callback = callback;
+ PyObject_GC_Track(result);
+ }
return result;
}
@@ -76,8 +70,7 @@ weakref_dealloc(PyWeakReference *self)
{
PyObject_GC_UnTrack((PyObject *)self);
clear_weakref(self);
- self->wr_next = free_list;
- free_list = self;
+ PyObject_GC_Del(self);
}
@@ -580,11 +573,8 @@ PyWeakref_NewRef(PyObject *ob, PyObject *callback)
if (result != NULL)
Py_XINCREF(result);
else {
- result = new_weakref();
+ result = new_weakref(ob, callback);
if (result != NULL) {
- Py_XINCREF(callback);
- result->wr_callback = callback;
- result->wr_object = ob;
if (callback == NULL) {
insert_head(result, list);
}
@@ -596,7 +586,6 @@ PyWeakref_NewRef(PyObject *ob, PyObject *callback)
else
insert_after(result, prev);
}
- PyObject_GC_Track(result);
}
}
return (PyObject *) result;
@@ -624,7 +613,7 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
if (result != NULL)
Py_XINCREF(result);
else {
- result = new_weakref();
+ result = new_weakref(ob, callback);
if (result != NULL) {
PyWeakReference *prev;
@@ -632,9 +621,6 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
result->ob_type = &_PyWeakref_CallableProxyType;
else
result->ob_type = &_PyWeakref_ProxyType;
- result->wr_object = ob;
- Py_XINCREF(callback);
- result->wr_callback = callback;
if (callback == NULL)
prev = ref;
else
@@ -644,7 +630,6 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
insert_head(result, list);
else
insert_after(result, prev);
- PyObject_GC_Track(result);
}
}
return (PyObject *) result;