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

Issue with PYTHONCAPI_COMPAT_SPEC on macOS #131

Closed
cdce8p opened this issue Jan 26, 2025 · 5 comments
Closed

Issue with PYTHONCAPI_COMPAT_SPEC on macOS #131

cdce8p opened this issue Jan 26, 2025 · 5 comments

Comments

@cdce8p
Copy link
Contributor

cdce8p commented Jan 26, 2025

This issue seems to be specific to MacOS. Encountered while testing with mypy / mypyc.

The traceback below is with Python 3.13.1 (v3.13.1:06714517797, Dec 3 2024, 14:00:22) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin, however a slightly different error is also reproducible in CI with Python 3.9. See link below.

In file included from /.../mypyc/lib-rt/pythonsupport.h:11:
/.../mypyc/lib-rt/pythoncapi_compat.h:2086:9: error: no member named 'use_system_logger' in 'PyConfig'
        PYTHONCAPI_COMPAT_SPEC(use_system_logger, BOOL, _Py_NULL),
        ^                      ~~~~~~~~~~~~~~~~~
/.../mypyc/lib-rt/pythoncapi_compat.h:2000:15: note: expanded from macro 'PYTHONCAPI_COMPAT_SPEC'
    {#MEMBER, offsetof(PyConfig, MEMBER), \
              ^                  ~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/stddef.h:105:24: note: expanded from macro 'offsetof'
#define offsetof(t, d) __builtin_offsetof(t, d)
                       ^                     ~
In file included from /.../mypyc/lib-rt/pythonsupport.h:11:
/.../mypyc/lib-rt/pythoncapi_compat.h:2098:26: error: invalid application of 'sizeof' to an incomplete type 'const PyConfigSpec[]'
    for (size_t i=0; i < Py_ARRAY_LENGTH(config_spec); i++) {
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Frameworks/Python.framework/Versions/3.13/include/python3.13/pymacro.h:100:12: note: expanded from macro 'Py_ARRAY_LENGTH'
    (sizeof(array) / sizeof((array)[0]) \

python/mypy#18535
https://github.com/python/mypy/actions/runs/12973783593/job/36182870602?pr=18535#step:9:118

@vstinner
Copy link
Member

Oh right, PyConfig.use_system_logger will only be available on Python 3.13.2 which is not available yet! I just removed the member in 03043e3. I modified the CI to test more Python versions on macOS.

however a slightly different error is also reproducible in CI with Python 3.9. See link below.

I cannot reproduce the Python 3.9 error. Can you please retry with updated pythoncapi_compat.h?

If you still have the bug, you may try to replace Py_ARRAY_LENGTH(config_spec) with sizeof(config_spec) / sizeof(config_spec[0]).


By the way, I'm curious, why do you update pythoncapi_compat.h?

@vstinner
Copy link
Member

Oh, I see that Py_ARRAY_LENGTH() is still causing troubles after PyConfig.use_system_logger removal. I wrote 4c53701 to replace Py_ARRAY_LENGTH() with sizeof().

@cdce8p
Copy link
Contributor Author

cdce8p commented Jan 26, 2025

Looks good now. Thanks for the quick fixes!

By the way, I'm curious, why do you update pythoncapi_compat.h?

Did you mean the fix I applied manually in the PR? That was just #130.
Aside from that another maybe better name for the mypy PR would be "Sync pythoncapi_compat.h" :)

@cdce8p cdce8p closed this as completed Jan 26, 2025
@vstinner
Copy link
Member

If you don't need new functions, you don't have to update pythoncapi_compat.h.

But I'm glad that you did it, to report regressions :-)

Looks good now. Thanks for the quick fixes!

Good. You're welcome.

@cdce8p
Copy link
Contributor Author

cdce8p commented Jan 26, 2025

If you don't need new functions, you don't have to update pythoncapi_compat.h.

True.

But I'm glad that you did it, to report regressions :-)

Always good to stay on top of it. Especially with mypyc you never know when you're going to need one of these ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants