Skip to content

Enhancement request: make pycore_cell.h compile cleanly under C++ #144490

Description

@yoney

This isn’t a “real issue” report, since pycore_cell.h (and the helpers it declares) are internal implementation details, so I understand they’re not part of the stable/public API, not guaranteed to be C++-compatible, and may change or disappear in future CPython versions. I’m still asking about this because the fix is very small.

While adapting CinderX to FT-Python, we include pycore_cell.h from a C++ (in the JIT/codegen path for LOAD_DEREF / STORE_DEREF). This currently fails to compile under C++ unless -fpermissive is used.

pycore_cell.h already has extern "C" guards, so it looks intended to be usable from C++ in at least some capacity. Would it be acceptable to add an explicit cast so it compiles cleanly under C++?``

Linked PRs

Activity

  1. vstinner commented on Feb 5, 2026

    @vstinner
    Member

    What is the error message? What is your compiler (name/version)?

  2. colesbury commented on Feb 5, 2026

    @colesbury
    Contributor

    I think most compilers error or warn for this pattern in C++: https://gcc.godbolt.org/z/dvsoqvPzd

    Typically with something like:

    GCC:

    <source>:8:18: error: invalid conversion from 'void*' to 'Foo*' [-fpermissive]
        8 |     return malloc(sizeof(Foo));
          |            ~~~~~~^~~~~~~~~~~~~
          |                  |
          |                  void*
    Compiler returned: 1
    

    Clang:

    <source>:8:12: error: cannot initialize return object of type 'Foo *' with an rvalue of type 'void *'
        8 |     return malloc(sizeof(Foo));
          |            ^~~~~~~~~~~~~~~~~~~
    
  3. yoney commented on Feb 5, 2026

    @yoney
    ContributorAuthor

    clang version 19.1.2, it should be similar for other compilers, C++ is stricter on implicit conversions.

    internal/pycore_cell.h:56:13: error: assigning to 'PyObject *' (aka '_object *') from incompatible type 'void *'
       56 |     value = _Py_atomic_load_ptr(&cell->ob_ref);
          |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1 error generated.
    
  4. added 3 commits that reference this issue on Feb 6, 2026
  5. added a commit that references this issue on Feb 7, 2026
  6. added a commit that references this issue on Feb 7, 2026
  7. added a commit that references this issue on Feb 7, 2026
  8. added a commit that references this issue on Feb 9, 2026
  9. added 2 commits that reference this issue on Feb 9, 2026
  10. added a commit that references this issue on Feb 9, 2026
  11. added 4 commits that reference this issue on Feb 10, 2026
  12. vstinner commented on Feb 10, 2026

    @vstinner
    Member

    I modified test_cext (C) and test_cppext (C++) to test the internal C API on 3.14 and main branches. test_cppext now includes the pycore_cell.h header file.

    Currently, test_cppext skips pycore_backoff.h and pycore_cell.h since they include mimalloc which emits C++ compiler warnings.

  13. added 4 commits that reference this issue on Feb 15, 2026
  14. added a commit that references this issue on Feb 28, 2026
  15. added 4 commits that reference this issue on Apr 25, 2026
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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions