-
-
Notifications
You must be signed in to change notification settings - Fork 33k
gh-135125: Fix Py_STACKREF_DEBUG build #139475
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
base: main
Are you sure you want to change the base?
gh-135125: Fix Py_STACKREF_DEBUG build #139475
Conversation
CC @markshannon |
This PR is just minimal fix for I suggest to make changes for this build: provide exactly those flags for indexes as for standard GIL build:
And use indexes without flags as real indexes in hash table. For example, |
PyStackRef_Wrap(void *ptr) | ||
{ | ||
assert(ptr != NULL); | ||
return (_PyStackRef){ .index = (uint64_t)ptr }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it is safe to cast void* to uint64 and vice verse. Maybe we should use uintptr_t?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We know that Py_STACKREF_DEBUG
requires 64 bit machine.
IMO, we could use uint64_t
here.
But it's also possible to use uintptr_t bits
as in production build, and save indexes in it.
I provide those changes.
|
CC @mpage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. In the future I'd recommend splitting this into two PRs (and associated issues): one that is the minimal fix for the build and another that unifies the refcounting behavior. I'd like to give Mark a chance to review this as I'm not sure if he wants to preserve the refcounting behavior in the debug build. I've added him as a reviewer.
Thanks! I thought about two separate PRs but I wasn't sure about that. |
There are two problems with PyStackRef debug builds:
_PyStackRef_FromPyObjectBorrow
function.We should provide
Py_INCREF
here, because eachPyStackRef_CLOSE
will usePy_DECREF
in this mode.PyStackRef_Wrap
andPyStackRef_Unwrap
functions.Py_STACKREF_DEBUG
set. #135125