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

FIX: import internal cpython headers to fix for py311 #4667

Merged
merged 4 commits into from
Mar 12, 2022

Conversation

tacaswell
Copy link
Contributor

In 18b5dd68c6b616257ae243c0b6bb965ffc885a23 /
python/cpython#31530 /
https://bugs.python.org/issue46836

The _frame struct was moved to an internal header, however the public API is
primarily read-only, and cython needs to build _frame objects so still import
the internal headers.

The version bounding is wrong (the problem commit won't be out until a6, but this condition will compile against the current CPYthon main branch.

I'm not at all sure that this is the right fix, but it compiled!

@tacaswell tacaswell marked this pull request as draft February 26, 2022 23:38
@tacaswell
Copy link
Contributor Author

I was fooled by faliing to fully rebuild before and missed in include (I had just removed the line number setting while testing 🤦🏻 ).

I am very confused by I could not get the version getting in ModuleSetup.c to work so this is currently broken for every other version 😞 so made a draft.

@scoder scoder marked this pull request as ready for review February 27, 2022 14:49
@tacaswell
Copy link
Contributor Author

@scoder I can confirm that this works and squashed it down to one commit.

Copy link
Contributor

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Oh nice, I didn't know that there was already a PR! I wrote a simpler change: https://github.com/cython/cython/pull/4671/files (closed).

@@ -499,6 +499,9 @@ static int __pyx_Generator_init(PyObject *module); /*proto*/
//@requires: ModuleSetupCode.c::IncludeStructmemberH

#include <frameobject.h>
#if PY_VERSION_HEX >= 0x030b00a5
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically, the include will only be needed since 0x030b00a6 but it's fine to include it in Python 3.11 alpha 5. I suggest to define the Py_BUILD_CORE macro to include an internal C API header file. Right now, it's not needed, but I consider requiring it later.

#  ifndef Py_BUILD_CORE
#    define Py_BUILD_CORE 1
#  endif

Same remarks for the other modified files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair, but then it would not work for me locally. What is the best way to test this sort of thing in the "interstitial" time? I guess I could just locally patch my CPython source to be the next release prematurely?

Should I also include the !CYTHON_COMPILING_IN_PYSTON check everywhere?

Copy link
Contributor

Choose a reason for hiding this comment

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

3.11a6 will hopefully be out quite soon. Maybe faster than this gets merged. Not sure when it will become available on Github Actions, though.

In 18b5dd68c6b616257ae243c0b6bb965ffc885a23 /
python/cpython#31530 /
https://bugs.python.org/issue46836

The `_frame` struct was moved to an internal header, however the public API is
primarily read-only, and cython needs to build _frame objects so still import
the internal headers.
@tacaswell
Copy link
Contributor Author

I fixed the version gating and addeng the Py_BUILD_CORE define in a second commit (to make it easy to strip if needed).

Should I also include the !CYTHON_COMPILING_IN_PYSTON check everywhere?

I did not add this check as it looks like PYSTON is pinned to 3.8?

@scoder
Copy link
Contributor

scoder commented Mar 5, 2022

I fixed the version gating and addeng the Py_BUILD_CORE define in a second commit (to make it easy to strip if needed).

I'm still not happy about the fact that we now have to do that. We currently set the macro at a somewhat late point, and since we do it in more than one place, it might happen that other CPython header files get included afterwards (e.g. traceback.h in this case, although we could at least move that before the frame header include).

@vstinner, I think we should unset it directly after including the frame header file. In that case, the #ifndef check seems counterproductive. Although, I guess a (very) few users might actually want to access CPython internals themselves, in their own code… Can we somehow save the old define and restore it? I would basically like to have a way to say "define it for this specific header and don't interfere with anything else". Or would you consider it "not a problem" if it's defined?

Should I also include the !CYTHON_COMPILING_IN_PYSTON check everywhere?

I did not add this check as it looks like PYSTON is pinned to 3.8?

Pyston should be fine. It's based on CPython now. If they need something different in a later version, we'll adapt at that point.

Cython/Utility/Exceptions.c Outdated Show resolved Hide resolved
Cython/Utility/Profile.c Outdated Show resolved Hide resolved
Copy link
Contributor

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

@vstinner
Copy link
Contributor

@scoder @da-woods: Python 3.11 alpha6 has been released, can this PR be merged now?

@scoder
Copy link
Contributor

scoder commented Mar 12, 2022

Thanks

scoder pushed a commit that referenced this pull request Mar 12, 2022
In python/cpython#31530
https://bugs.python.org/issue46836

the `_frame` struct was moved to an internal header, however the public API is
primarily read-only, and Cython needs to build PyFrameObjects so still import
the internal headers.

Also sets the Py_BUILD_CORE define for py311a6, trying to restrict it to the frame header.
@scoder scoder added this to the 0.29.29 milestone Mar 12, 2022
@scoder
Copy link
Contributor

scoder commented Mar 12, 2022

Backported to 0.29.x in afc00fc
(Let's see if I missed something)

@vstinner
Copy link
Contributor

Great, thank you :-)

@tacaswell tacaswell deleted the fix_py311_internals branch March 14, 2022 14:31
@ncoghlan
Copy link
Contributor

ncoghlan commented Mar 19, 2022

Please comment on https://discuss.python.org/t/proposal-rename-pyinterpreterframe-struct-as-py-framedata/14213/7 if any of the adjustments proposed there would affect Cython.

@ncoghlan
Copy link
Contributor

Don't worry about my previous comment - we'll make sure code that works against 3.11a6 keeps working until faster-cpython/ideas#309 provides a proper public API for the relevant frame manipulation tasks (although feel free to chime in there on the public API that you'd like to see to avoid having to delve into frame object internals)

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.

4 participants