-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add support for array_t<handle> and array_t<object> #5427
Conversation
It looks like "CI / 🐍 3 • Clang 15 • C++20 • x64" was a spurious failure unrelated to my change. |
Yes, certainly unrelated. Similarly, "🐍 3 • Clang dev • C++11 • x64", it seems to be stuck on a wget for 2+ hours. |
This was meant to further stress-test correctness of refcount handling. All modified test functions were manually leak-checked (`while True`, top command, Python 3.12.3, Ubuntu 24.01, gcc 13.2.0).
Looks good, thanks for the great work on the tests! I added one commit: a1b7094 I also git merged master. Waiting for GitHub Actions to finish. |
The "CI / 🐍 3 • windows-latest • mingw32 (pull_request)" is also definitely unrelated. Everything else works. Merging. Thanks @MaartenBaert! |
Description
This commit adds improved support for NumPy arrays with object dtype, by allowing users to access such arrays as
array_t<handle>
orarray_t<object>
, which are more convenient thanarray_t<PyObject*>
(which was introduced in PR #4674). In particular,array_t<object>
provides automatic memory management.This feature relies on the fact that
object
andhandle
have the same memory layout asPyObject*
, i.e.sizeof(object) == sizeof(handle) == sizeof(PyObject*)
. If this is somehow not the case, theenable_if_t
test should automatically disable this feature.I have also extended and improved the tests related to this feature with additional tests to detect memory leaks due to incorrect refcounts.
Suggested changelog entry: