pyclass: refactor tp_new
/ tp_dealloc
/ remove PyCellInner
#1657
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a bunch of cleanups to
PyCell
andPyClassInitializer
code for the slot implementations oftp_new
,tp_alloc
,tp_dealloc
andtp_free
:tp_alloc
andtp_free
are only implemented forfreelist
classes, where they provide custom memory allocation / releasetp_new
now does the same thing for all#[pyclass]
(call supertp_new
and initialize thePyCell
contents)tp_dealloc
does the reverse oftp_new
(drop thePyCell
contents and then call supertp_dealloc
)This work seems necessary to me as a precursor to #1647, #1637, #1344 and #991.
While doing this I also found a nasty bug that we don't call
tp_dealloc
of inherited native types, which means that dict subclasses never decrease reference counts of all their contents on drop (for example).I added a benchmark for class instantiation. Sadly these cleanups don't seem to have meaningfully changed the benchmark. I did notice that we're a lot faster than the numbers reported in #661, so there must have been progress over time.