Skip to content

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

Merged
scoder merged 4 commits into
cython:masterfrom
tacaswell:fix_py311_internals
Mar 12, 2022
Merged

FIX: import internal cpython headers to fix for py311#4667
scoder merged 4 commits into
cython:masterfrom
tacaswell:fix_py311_internals

Conversation

@tacaswell

Copy link
Copy Markdown
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
Copy Markdown
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
Comment thread Cython/Utility/ModuleSetupCode.c Outdated
@tacaswell

Copy link
Copy Markdown
Contributor Author

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

@vstinner vstinner left a comment

Copy link
Copy Markdown
Contributor

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).

Comment thread Cython/Utility/Coroutine.c Outdated
//@requires: ModuleSetupCode.c::IncludeStructmemberH

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
tacaswell force-pushed the fix_py311_internals branch from 952fc89 to fb678f3 Compare March 4, 2022 23:52
@tacaswell

Copy link
Copy Markdown
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

scoder commented Mar 5, 2022

Copy link
Copy Markdown
Contributor

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.

Comment thread Cython/Utility/Exceptions.c Outdated
Comment thread Cython/Utility/Profile.c Outdated

@vstinner vstinner left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

@vstinner

Copy link
Copy Markdown
Contributor

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

@scoder

scoder commented Mar 12, 2022

Copy link
Copy Markdown
Contributor

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

scoder commented Mar 12, 2022

Copy link
Copy Markdown
Contributor

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

@vstinner

Copy link
Copy Markdown
Contributor

Great, thank you :-)

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

ncoghlan commented Mar 19, 2022

Copy link
Copy Markdown
Contributor

@ncoghlan

Copy link
Copy Markdown
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