From 169163b2f1fbdcf9031b20fcba0fce55afa637f4 Mon Sep 17 00:00:00 2001 From: Rudi Chen Date: Fri, 17 Jul 2015 18:09:18 +0000 Subject: [PATCH] Use weakref's original tp_dealloc. --- from_cpython/Objects/weakrefobject.c | 4 +++- src/runtime/types.cpp | 10 +--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/from_cpython/Objects/weakrefobject.c b/from_cpython/Objects/weakrefobject.c index e17e45dc7..b499163d0 100644 --- a/from_cpython/Objects/weakrefobject.c +++ b/from_cpython/Objects/weakrefobject.c @@ -544,7 +544,9 @@ proxy_dealloc(PyWeakReference *self) if (self->wr_callback != NULL) PyObject_GC_UnTrack((PyObject *)self); clear_weakref(self); - PyObject_GC_Del(self); + // Pyston change: we monkey-patch this function to use the Pyston GC + // Shouldn't need to call tp_free either. + // PyObject_GC_Del(self); } /* sequence slots */ diff --git a/src/runtime/types.cpp b/src/runtime/types.cpp index cf5b8f0a8..4930934f8 100644 --- a/src/runtime/types.cpp +++ b/src/runtime/types.cpp @@ -1152,11 +1152,6 @@ static void proxy_to_tp_traverse(GCVisitor* v, Box* b) { b->cls->tp_traverse(b, call_gc_visit, v); } -static void proxy_to_tp_clear(Box* b) { - assert(b->cls->tp_clear); - b->cls->tp_clear(b); -} - // This probably belongs in tuple.cpp? extern "C" void tupleGCHandler(GCVisitor* v, Box* b) { boxGCHandler(v, b); @@ -2936,11 +2931,8 @@ extern "C" PyUnicodeObject* _PyUnicode_New(Py_ssize_t length) noexcept { // like weak references, we still rely on reference-counting to some extent. static void setTypeGCProxy(BoxedClass* cls) { cls->tp_alloc = PystonType_GenericAlloc; + cls->tp_free = default_free; cls->gc_visit = proxy_to_tp_traverse; - - // We can't use the original tp_dealloc here, the dealloc method of some - // types like ProxyType explicitely frees itself without using tp_free. - cls->tp_dealloc = proxy_to_tp_clear; cls->has_safe_tp_dealloc = true; cls->is_pyston_class = true; }