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

code.h uses MS-only C++ extensions #101907

Closed
zooba opened this issue Feb 14, 2023 · 3 comments
Closed

code.h uses MS-only C++ extensions #101907

zooba opened this issue Feb 14, 2023 · 3 comments
Labels
3.12 bugs and security fixes build The build process and cross-build

Comments

@zooba
Copy link
Member

zooba commented Feb 14, 2023

Issue #100222 added a struct to Include/cpython/code.h (which is included by default by Python.h) that is not compliant C++:

typedef union {
    uint16_t cache;
    struct {
        uint8_t opcode;
        uint8_t oparg;
    };
} _Py_CODEUNIT;

The struct member requires a name, as only anonymous structs are currently permitted in standard C++.

(And since the original issue invokes PEP 7, I'll do the same and point out that "The public C API should be compatible with C++". The intention of this clause is that standard C++ can #include <Python.h>, which is currently broken.)

Linked PRs

@zooba zooba added build The build process and cross-build 3.12 bugs and security fixes labels Feb 14, 2023
zooba added a commit to zooba/cpython that referenced this issue Feb 14, 2023
@markshannon
Copy link
Member

Rather than replace all the .opcode and .oparg with SHOUTY MACROS, how about:

typedef union {
    uint16_t cache;
    struct {
        uint8_t code;
        uint8_t arg;
    } op;
} _Py_CODEUNIT;

Then i.oparg becomes i.op.arg which is still readable.

@zooba
Copy link
Member Author

zooba commented Feb 14, 2023

Do we want that to be the API then? And so we should remove the macros entirely?

If we're going to have macros, I'd rather they be the only place we have to make a change like this.

@markshannon
Copy link
Member

Personally, I'd say get rid of the macros.

At least the uses of them. We should probably keep the declarations in case any third-party code is using them.

zooba added a commit to zooba/cpython that referenced this issue Feb 14, 2023
markshannon pushed a commit that referenced this issue Feb 20, 2023
* gh-101907: Removes use of non-standard C++ extension from Include/cpython/code.h

* Make cases_generator correct on Windows
@zooba zooba closed this as completed Feb 20, 2023
jaraco pushed a commit to jaraco/cpython that referenced this issue Feb 20, 2023
…onGH-101912)

* pythongh-101907: Removes use of non-standard C++ extension from Include/cpython/code.h

* Make cases_generator correct on Windows
carljm added a commit to carljm/cpython that referenced this issue Feb 20, 2023
* main: (60 commits)
  pythongh-102056: Fix a few bugs in error handling of exception printing code (python#102078)
  pythongh-102011: use sys.exception() instead of sys.exc_info() in docs where possible (python#102012)
  pythongh-101566: Sync with zipp 3.14. (pythonGH-102018)
  pythonGH-99818: improve the documentation for zipfile.Path and Traversable (pythonGH-101589)
  pythongh-88233: zipfile: handle extras after a zip64 extra (pythonGH-96161)
  pythongh-101981: Apply HOMEBREW related environment variables (pythongh-102074)
  pythongh-101907: Stop using `_Py_OPCODE` and `_Py_OPARG` macros (pythonGH-101912)
  pythongh-101819: Adapt _io types to heap types, batch 1 (pythonGH-101949)
  pythongh-101981: Build macOS as recommended by the devguide (pythonGH-102070)
  pythongh-97786: Fix compiler warnings in pytime.c (python#101826)
  pythongh-101578: Amend PyErr_{Set,Get}RaisedException docs (python#101962)
  Misc improvements to the float tutorial (pythonGH-102052)
  pythongh-85417: Clarify behaviour on branch cuts in cmath module (python#102046)
  pythongh-100425: Update tutorial docs related to sum() accuracy (FH-101854)
  Add missing 'is' to `cmath.log()` docstring (python#102049)
  pythongh-100210: Correct the comment link for unescaping HTML (python#100212)
  pythongh-97930: Also include subdirectory in makefile. (python#102030)
  pythongh-99735: Use required=True in argparse subparsers example (python#100927)
  Fix incorrectly documented attribute in csv docs (python#101250)
  pythonGH-84783: Make the slice object hashable (pythonGH-101264)
  ...
carljm added a commit to carljm/cpython that referenced this issue Feb 22, 2023
* main: (225 commits)
  pythongh-102056: Fix a few bugs in error handling of exception printing code (python#102078)
  pythongh-102011: use sys.exception() instead of sys.exc_info() in docs where possible (python#102012)
  pythongh-101566: Sync with zipp 3.14. (pythonGH-102018)
  pythonGH-99818: improve the documentation for zipfile.Path and Traversable (pythonGH-101589)
  pythongh-88233: zipfile: handle extras after a zip64 extra (pythonGH-96161)
  pythongh-101981: Apply HOMEBREW related environment variables (pythongh-102074)
  pythongh-101907: Stop using `_Py_OPCODE` and `_Py_OPARG` macros (pythonGH-101912)
  pythongh-101819: Adapt _io types to heap types, batch 1 (pythonGH-101949)
  pythongh-101981: Build macOS as recommended by the devguide (pythonGH-102070)
  pythongh-97786: Fix compiler warnings in pytime.c (python#101826)
  pythongh-101578: Amend PyErr_{Set,Get}RaisedException docs (python#101962)
  Misc improvements to the float tutorial (pythonGH-102052)
  pythongh-85417: Clarify behaviour on branch cuts in cmath module (python#102046)
  pythongh-100425: Update tutorial docs related to sum() accuracy (FH-101854)
  Add missing 'is' to `cmath.log()` docstring (python#102049)
  pythongh-100210: Correct the comment link for unescaping HTML (python#100212)
  pythongh-97930: Also include subdirectory in makefile. (python#102030)
  pythongh-99735: Use required=True in argparse subparsers example (python#100927)
  Fix incorrectly documented attribute in csv docs (python#101250)
  pythonGH-84783: Make the slice object hashable (pythonGH-101264)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes build The build process and cross-build
Projects
None yet
Development

No branches or pull requests

2 participants