Skip to content

C API: Use _Py_PACK_VERSION() in Py_LIMITED_API version checks - #161622

Open
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:use_pack_version
Open

vstinner wants to merge 1 commit into
python:mainfrom
vstinner:use_pack_version

Conversation

@vstinner

@vstinner vstinner commented Nov 8, 2026

Copy link
Copy Markdown
Member

Move _Py_PACK_VERSION() from pymacro.h to patchlevel.h.

PR generated with these shell commands on Linux:

HEADERS=$(find Include -name "*.h")
for minor in $(seq 1 9); do sed -i -e "s#0x030${minor}0000#_Py_PACK_VERSION(3, $minor)#g" $HEADERS; done
sed -i -e "s#0x030[aA]0000#_Py_PACK_VERSION(3, 10)#g" $HEADERS
sed -i -e "s#0x030[bB]0000#_Py_PACK_VERSION(3, 11)#g" $HEADERS
sed -i -e "s#0x030[cC]0000#_Py_PACK_VERSION(3, 12)#g" $HEADERS
sed -i -e "s#0x030[dD]0000#_Py_PACK_VERSION(3, 13)#g" $HEADERS
sed -i -e "s#0x030[eE]0000#_Py_PACK_VERSION(3, 14)#g" $HEADERS
sed -i -e "s#0x030[fF]0000#_Py_PACK_VERSION(3, 15)#g" $HEADERS
sed -i -e "s#0x030a00A7#_Py_PACK_VERSION(3, 10)#g" Include/refcount.h

Manual replacements:

  • 0x03050400 => _Py_PACK_FULL_VERSION(3, 5, 4, 0, 0)
  • 0x03060100 => _Py_PACK_FULL_VERSION(3, 6, 1, 0, 0)

Move _Py_PACK_VERSION() from pymacro.h to patchlevel.h.

PR generated with these shell commands on Linux:

    HEADERS=$(find Include -name "*.h")
    for minor in $(seq 1 9); do sed -i -e "s#0x030${minor}0000#_Py_PACK_VERSION(3, $minor)#g" $HEADERS; done
    sed -i -e "s#0x030[aA]0000#_Py_PACK_VERSION(3, 10)#g" $HEADERS
    sed -i -e "s#0x030[bB]0000#_Py_PACK_VERSION(3, 11)#g" $HEADERS
    sed -i -e "s#0x030[cC]0000#_Py_PACK_VERSION(3, 12)#g" $HEADERS
    sed -i -e "s#0x030[dD]0000#_Py_PACK_VERSION(3, 13)#g" $HEADERS
    sed -i -e "s#0x030[eE]0000#_Py_PACK_VERSION(3, 14)#g" $HEADERS
    sed -i -e "s#0x030[fF]0000#_Py_PACK_VERSION(3, 15)#g" $HEADERS
    sed -i -e "s#0x030a00A7#_Py_PACK_VERSION(3, 10)#g" Include/refcount.h

Manual replacements:

* 0x03050400 => _Py_PACK_FULL_VERSION(3, 5, 4, 0, 0)
* 0x03060100 => _Py_PACK_FULL_VERSION(3, 6, 1, 0, 0)
@vstinner

vstinner commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

cc @encukou @serhiy-storchaka

I'm never able to remind the value of hexadecimal version numbers such as 0x030d0000. I have to run a Python REPL to convert 0xd to decimal. _Py_PACK_VERSION(3, 13) avoids this issue, I can directly read the Python version number.

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.

1 participant