Uh oh!
There was an error while loading. Please reload this page.
feat: add support for array_t<handle> and array_t<object> - #5427
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
MaartenBaert
commented
Nov 16, 2024
It looks like "CI / 🐍 3 • Clang 15 • C++20 • x64" was a spurious failure unrelated to my change. |
rwgk
commented
Nov 16, 2024
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).
rwgk
commented
Nov 16, 2024
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. |
rwgk
commented
Nov 16, 2024
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
objectandhandlehave the same memory layout asPyObject*, i.e.sizeof(object) == sizeof(handle) == sizeof(PyObject*). If this is somehow not the case, theenable_if_ttest 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: