[Python] Start switching ROOT pythonizations to Python Limited C API#21680
Merged
guitargeek merged 1 commit intoroot-project:masterfrom Mar 25, 2026
Merged
[Python] Start switching ROOT pythonizations to Python Limited C API#21680guitargeek merged 1 commit intoroot-project:masterfrom
guitargeek merged 1 commit intoroot-project:masterfrom
Conversation
bf21670 to
d7056b8
Compare
Test Results 20 files 20 suites 2d 22h 3m 19s ⏱️ Results for commit d7056b8. |
vepadulano
approved these changes
Mar 25, 2026
Member
vepadulano
left a comment
There was a problem hiding this comment.
Very nice! I believe the changes are already good as is, nonetheless I left a couple of minor comments for consideration. Make sure the PR is merged only once the CI is green.
This patch replaces usage of CPython macros and non-stable APIs with functions compatible with the Python Limited C API (stable ABI). Replace direct macros with API functions: * `PyBytes_AS_STRING` : `PyBytes_AsString` * `PyBytes_GET_SIZE` : `PyBytes_Size` * `PyTuple_GET_SIZE` : `PyTuple_Size` * `PyTuple_SET_ITEM` : `PyTuple_SetItem` * `PyList_GET_ITEM` : `PyList_GetItem` * `PyList_GET_SIZE` : `PyList_Size` * `PyInt_AS_LONG` : `PyInt_AsLong` * `Py_DECREF` : `Py_DecRef` * `Py_XDECREF` : `Py_DecRef` Furthermore, replace `PyUnicode_AsUTF8` with a helper based on the stable `PyUnicode_AsUTF8AndSize`. Also, replace `<Python.h>` with `"PythonLimitedAPI.h"`, where the `Py_LIMITED_API` macro is set. This change is part of enabling PyROOT to build against the Python stable ABI.
d7056b8 to
57f3a0f
Compare
Contributor
Author
|
Thanks @vepadulano, you are right about the error handling. I have fixed this, and then the code also becomes such that a helper function for getting the unicode strings inline becomes unnecessary, because one has to do the error checking separately anyway. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch replaces usage of CPython macros and non-stable APIs with functions compatible with the Python Limited C API (stable ABI).
Replace direct macros with API functions:
PyBytes_AS_STRING:PyBytes_AsStringPyBytes_GET_SIZE:PyBytes_SizePyTuple_GET_SIZE:PyTuple_SizePyTuple_SET_ITEM:PyTuple_SetItemPyList_GET_ITEM:PyList_GetItemPyList_GET_SIZE:PyList_SizePyInt_AS_LONG:PyInt_AsLongPy_DECREF:Py_DecRefPy_XDECREF:Py_DecRefFurthermore, replace
PyUnicode_AsUTF8with a helper based on the stablePyUnicode_AsUTF8AndSize. Also, replace<Python.h>with"PythonLimitedAPI.h", where thePy_LIMITED_APImacro is set.This change is part of enabling PyROOT to build against the Python stable ABI.