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

Skip __index__ handling in PyLong_AsNativeBytes #121115

Closed
zooba opened this issue Jun 28, 2024 · 0 comments
Closed

Skip __index__ handling in PyLong_AsNativeBytes #121115

zooba opened this issue Jun 28, 2024 · 0 comments
Assignees
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes

Comments

@zooba
Copy link
Member

zooba commented Jun 28, 2024

As per the discussion in capi-workgroup/decisions#32 (and some other bugs here that I haven't bothered to look up), having int conversion functions call back into Python to evaluate __index__ can be problematic or unexpected (Python code may cause the GIL to be released, which could break threading invariants in the calling code).

We should disable __index__ handling by default in PyLong_AsNativeBytes and provide a flag to reenable it. In general, calling __index__ is only really useful on user-provided arguments, which are easily distinguishable from "private" variables in the caller's code.

This allows the caller to omit PyLong_Check before calling the conversion function (if they need to guarantee they retain the thread), or to provide a single flag if they will allow it. They'll discover they need the flag due to a TypeError, which is safe, rather than a crash or native threading related issue, which is unsafe.

Linked PRs

@zooba zooba added 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Jun 28, 2024
@zooba zooba self-assigned this Jun 28, 2024
@zooba zooba changed the title Allow skipping __index__ handling in PyLong_AsNativeBytes Skip __index__ handling in PyLong_AsNativeBytes Jun 28, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 28, 2024
…ythonGH-121118)

(cherry picked from commit 2894aa1)

Co-authored-by: Steve Dower <steve.dower@python.org>
zooba added a commit that referenced this issue Jun 28, 2024
(cherry picked from commit 2894aa1)

Co-authored-by: Steve Dower <steve.dower@python.org>
@zooba zooba closed this as completed Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes
Projects
None yet
Development

No branches or pull requests

1 participant