Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use weakref's original tp_dealloc.
Browse files Browse the repository at this point in the history
rudi-c committed Jul 17, 2015
1 parent 22b388e commit 169163b
Showing 2 changed files with 4 additions and 10 deletions.
4 changes: 3 additions & 1 deletion from_cpython/Objects/weakrefobject.c
Original file line number Diff line number Diff line change
@@ -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 */
10 changes: 1 addition & 9 deletions src/runtime/types.cpp
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 169163b

Please sign in to comment.