Visitar URL original
ENH: Limited API fallbacks for `Py_SETREF` and `pythoncapi-compat` by prathamhole14 · Pull Request #32864 · numpy/numpy · GitHub
Skip to content

ENH: Limited API fallbacks for Py_SETREF and pythoncapi-compat - #32864

Closed
prathamhole14 wants to merge 6 commits into
numpy:mainfrom
prathamhole14:limited_api_fallback_header
Closed

prathamhole14 wants to merge 6 commits into
numpy:mainfrom
prathamhole14:limited_api_fallback_header

Conversation

@prathamhole14

@prathamhole14 prathamhole14 commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

PR summary

Part of the Limited API work for _multiarray_umath.

  • Py_SETREF and Py_XSETREF are written like CPython's own definition npy_config.h. This was discussed in ENH: Build _reduction_loop_tests against the Limited API #32256 (comment).

  • npy_pycompat.h skip pythoncapi-compat which does not compile under the Limited API and define the two functions NumPy uses from it PyTuple_FromArray and PyLong_IsZero.

  • Reverted the hand written use of Py_SETREF / Py_XSETREF from #32256 and 32251.

Related to: #31913

AI Disclosure

Wrote the code myself, took help from AI to review the changes made and applied those changes. Took help to write PyTuple_FromArray and PyLong_IsZero, most changes were already mentioned in #32256 (comment)
Edit: used AI to add npy_pycompat.h header to necessary files

@prathamhole14
prathamhole14 marked this pull request as ready for review October 3, 2026 06:46
Comment thread numpy/_core/src/common/npy_config.h Outdated

/*
* TODO: remove when all supported Pythons define these in the Limited API,
* see https://github.com/capi-workgroup/decisions/issues/110

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like pythoncapi-compat doesn't have any support for the limited API. I opened python/pythoncapi-compat#183 to see if there's any possibility of adding that support, which would allow skipping these.

Also why is this in npy_config.h and not npy_pycompat.h? Seems to me it makes more sense in the latter header.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
Every C file gets npy_config.h automatically through npy_common.h. I initially kept it in npy_pycompat.h but then it had to be included by hand so I avoided it because if someone in future uses Py_SETREF they will have to include the header, although it will only fail for LIMITED API builds and CI will inform but something to be considered. Do you prefer I move it npy_pycompat.h?

@ngoldbaum ngoldbaum Oct 4, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I’d prefer this be moved to the logical spot for this.

@vstinner

vstinner commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Update: I added limited C API support to pythoncapi-compat, and I created python/pythoncapi-compat#187 to add Py_SETREF/XSETREF to old limited C API versions.

@prathamhole14

Copy link
Copy Markdown
Member Author

Thanks @vstinner, closing this one in favour of #32871 since it has all the commits from this PR already as well.

@prathamhole14
prathamhole14 deleted the limited_api_fallback_header branch October 8, 2026 13:04
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.

3 participants