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

Clean up special handling of PyCFunction and CyFunction #5739

Merged
merged 6 commits into from Oct 4, 2023

Conversation

scoder
Copy link
Contributor

@scoder scoder commented Oct 2, 2023

This avoids crashes in debug mode where CPython's access functions assert a type check (which fails for CyFunction).

Avoid excluding CyFunction from the fast-call fast-paths for 0/1 args in Python debug mode.
Also include the 1-arg (METH_O) case in the optimisation - I cannot see a reason why only 0-args should be special-cased for CyFunction.

Fix a bug in __Pyx_TryUnpackUnboundCMethod() where we checked for "defined(CYTHON_COMPILING_IN_PYPY)" (which is always true) instead of the defined 0/1 value.

Improves on #5031
Closes #4804

…ion. This avoids crashes in debug mode where CPython's access functions assert a type check (which fails for CyFunction).

Avoid excluding CyFunction from the fast-call fast-paths for 0/1 args in Python debug mode. Also include the 1-arg (METH_O) case in the optimisation - I cannot see a reason why only 0-args should be special-cased for CyFunction.
Fix a bug in __Pyx_TryUnpackUnboundCMethod() where we checked for "defined(CYTHON_COMPILING_IN_PYPY)" (which is always true) instead of the defined 0/1 value.
@scoder scoder added this to the 3.0.3 milestone Oct 2, 2023
@scoder scoder changed the title Clean up and simplify the special handling of PyCFunction and CyFunct Clean up and simplify the special handling of PyCFunction and CyFunction Oct 2, 2023
@scoder scoder changed the title Clean up and simplify the special handling of PyCFunction and CyFunction Clean up the special handling of PyCFunction and CyFunction Oct 2, 2023
@scoder scoder changed the title Clean up the special handling of PyCFunction and CyFunction Clean up special handling of PyCFunction and CyFunction Oct 2, 2023
…ted API and to make the (non-)acceptance of CyFunction (in addition to plain PyCFunction) explicit.
…Function, including subclasses.

Due to a bug, we weren't doing the type check at all before, which meant that PyCFunction_GET_SELF() could actually fail.
@scoder scoder merged commit ed2933b into cython:master Oct 4, 2023
75 of 76 checks passed
@scoder scoder deleted the pycfunction_cleanup branch October 4, 2023 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Assertion failure in PyCFunction_GET_FLAGS on debug mode
2 participants