Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyclass: fix reference count issue in subclass new #1365

Merged
merged 1 commit into from Jan 8, 2021

Conversation

davidhewitt
Copy link
Member

@davidhewitt davidhewitt commented Jan 5, 2021

This fixes a missing reference count increase (to work around a cpython bug) on Python versions 3.7 and older - see #1363 (comment)

It's a fairly nasty bug which leads to pretty immediate weird behaviour / crashes when tripped, so I think it is worth releasing 0.13.1 once this is merged.

Closes #1363

@davidhewitt
Copy link
Member Author

davidhewitt commented Jan 5, 2021

Hmm the tests ran fine on my local Python 3.9 and 3.6, I'll take another look tomorrow...

Copy link
Member

@kngwyu kngwyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thanks!

src/freelist.rs Outdated Show resolved Hide resolved
src/pyclass.rs Show resolved Hide resolved
@davidhewitt
Copy link
Member Author

@kngwyu I think this is ready for another look!

src/pyclass.rs Outdated

// Must check version at runtime because of abi3 wheels which could run against a higher
// version than the config.
static IS_NOT_PYTHON_3_8: GILOnceCell<bool> = GILOnceCell::new();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about checking the current refcount instead of the version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a way to detect this case using the type reference count - it increases by one on all versions I tested.

I guess I need to make this check only with Py_Limited_API, so I could avoid checking the version in more cases.

@davidhewitt
Copy link
Member Author

I pushed a new version of this PR which only does the runtime version check if Py_LIMITED_API is set.

Let me know if there's any other changes you would like to this. Once you're happy, I'll merge this and release 0.13.1 after.

@davidhewitt davidhewitt force-pushed the fix-tp-dealloc branch 3 times, most recently from b080946 to f6077d2 Compare January 7, 2021 23:53
@kngwyu
Copy link
Member

kngwyu commented Jan 8, 2021

LGTM, thanks!

@davidhewitt davidhewitt merged commit 364b7c2 into PyO3:master Jan 8, 2021
@davidhewitt davidhewitt deleted the fix-tp-dealloc branch January 8, 2021 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python subclassing doesn't inherit from pyclass on py3.6 or 3.7
2 participants