Skip to content

BUG: Fix reference counting for subarrays containing objects #12781

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

Merged
merged 1 commit into from
Jan 17, 2019

Conversation

charris
Copy link
Member

@charris charris commented Jan 17, 2019

Backport of #12650.

  • BUG: Fix dtype object subarrays for INCREF/DECREF and zeros/empty init

  • BUG: VOID_copyswap cannot fast path nontrivial subarrays

Especially object dtypes need reference counting, so cannot use
memcpy. Subarrays that include fields also have data which should
not be overwritten.

  • BUG: Copying subarrays with objects must decref original objects

When not using the dtype transfer function, the buffers are initialized
to NULL, and then just copied in full. Thus, at no point decref'ing
happens on the data that is originally in the array.

  • TST: Test subarray field reference counting

Tests initialization, copying and repeating (incrementing) as
well as advanced indexing (uses copyswap currently) and assignment

  • TST: Test sparse subarray field assignments

Assigning to subarray fields should not change the output in
between the fields. This currently still happens for normal
assignment, but not for advanced indexing.

The second test is marked as pytest.mark.valgrind_error to make
it clear that it is expected to show errors in valgrind, and give
at least the theoretical the possibility to skip it during testing.

…2650)

* BUG: Fix dtype object subarrays for INCREF/DECREF and zeros/empty init

* BUG: VOID_copyswap cannot fast path nontrivial subarrays

Especially object dtypes need reference counting, so cannot use
memcpy. Subarrays that include fields also have data which should
not be overwritten.

* BUG: Copying subarrays with objects must decref original objects

When not using the dtype transfer function, the buffers are initialized
to NULL, and then just copied in full. Thus, at no point decref'ing
happens on the data that is originally in the array.

* TST: Test subarray field reference counting

Tests initialization, copying and repeating (incrementing) as
well as advanced indexing (uses copyswap currently) and assignment

* TST: Test sparse subarray field assignments

Assigning to subarray fields should not change the output in
between the fields. This currently still happens for normal
assignment, but not for advanced indexing.

The second test is marked as `pytest.mark.valgrind_error` to make
it clear that it is expected to show errors in valgrind, and give
at least the theoretical the possibility to skip it during testing.
@charris charris added this to the 1.16.1 release milestone Jan 17, 2019
@charris charris merged commit 5708476 into numpy:maintenance/1.16.x Jan 17, 2019
@charris charris deleted the backport-12650 branch January 17, 2019 18:02
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.

2 participants