Skip to content

Issue with PYTHONCAPI_COMPAT_SPEC on macOS #131

Closed

Description

@cdce8p

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

Activity

  1. vstinner commented on Jan 26, 2025

    @vstinner
    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?

  2. vstinner commented on Jan 26, 2025

    @vstinner
    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().

  3. cdce8p commented on Jan 26, 2025

    @cdce8p
    ContributorAuthor

    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" :)

  4. vstinner commented on Jan 26, 2025

    @vstinner
    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.

  5. cdce8p commented on Jan 26, 2025

    @cdce8p
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions