Skip to content

Commit a20593e

Browse files
committed
Special refcounting exemption for buggy extensions
google's protobuf library gives away one too many refs to one of its types. This workaround feels excessively specific, but this is a common mistake to make, and it works just fine in CPython, so let people get away with it as well in Pyston.
1 parent 3e10ff4 commit a20593e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/runtime/types.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4847,7 +4847,15 @@ extern "C" void Py_Finalize() noexcept {
48474847
b->getHCAttrsPtr()->_clearRaw();
48484848
Py_CLEAR(b->tp_mro);
48494849
}
4850-
Py_DECREF(b);
4850+
4851+
// Try to support extensions that get away with having one-too-few refs to their class
4852+
// (such as google protobufs)
4853+
if (b->ob_refcnt == 0) {
4854+
RELEASE_ASSERT(!b->is_pyston_class, "%s", b->tp_name);
4855+
RELEASE_ASSERT((b->tp_flags & Py_TPFLAGS_HEAPTYPE) == 0, "%s", b->tp_name);
4856+
} else {
4857+
Py_DECREF(b);
4858+
}
48514859
}
48524860

48534861
clearAllICs();

0 commit comments

Comments
 (0)