summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
Diffstat (limited to 'Objects')
-rw-r--r--Objects/fileobject.c2
-rw-r--r--Objects/object.c2
-rw-r--r--Objects/typeobject.c11
-rw-r--r--Objects/weakrefobject.c3
4 files changed, 17 insertions, 1 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 8ebb482..1e3e57c 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -354,6 +354,8 @@ PyFile_SetEncoding(PyObject *f, const char *enc)
{
PyFileObject *file = (PyFileObject*)f;
PyObject *str = PyString_FromString(enc);
+
+ assert(PyFile_Check(f));
if (!str)
return 0;
Py_DECREF(file->f_encoding);
diff --git a/Objects/object.c b/Objects/object.c
index c07a369..065abdc 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -314,7 +314,7 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
/* For debugging convenience. Set a breakpoint here and call it from your DLL */
void
-_Py_Break(void)
+_Py_BreakPoint(void)
{
}
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 1bef208..f716906 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -655,6 +655,17 @@ subtype_dealloc(PyObject *self)
goto endlabel; /* resurrected */
else
_PyObject_GC_UNTRACK(self);
+ /* New weakrefs could be created during the finalizer call.
+ If this occurs, clear them out without calling their
+ finalizers since they might rely on part of the object
+ being finalized that has already been destroyed. */
+ if (type->tp_weaklistoffset && !base->tp_weaklistoffset) {
+ /* Modeled after GET_WEAKREFS_LISTPTR() */
+ PyWeakReference **list = (PyWeakReference **) \
+ PyObject_GET_WEAKREFS_LISTPTR(self);
+ while (*list)
+ _PyWeakref_ClearRef(*list);
+ }
}
/* Clear slots up to the nearest base with a different tp_dealloc */
diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c
index e05788f..7b5b561 100644
--- a/Objects/weakrefobject.c
+++ b/Objects/weakrefobject.c
@@ -57,6 +57,9 @@ clear_weakref(PyWeakReference *self)
PyWeakref_GET_OBJECT(self));
if (*list == self)
+ /* If 'self' is the end of the list (and thus self->wr_next == NULL)
+ then the weakref list itself (and thus the value of *list) will
+ end up being set to NULL. */
*list = self->wr_next;
self->wr_object = Py_None;
if (self->wr_prev != NULL)