Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: core: Don't call INCREF/DECREF on descr in NpyStringAcquireAllocator.#31456

Merged
ngoldbaum merged 2 commits into
numpy:mainfrom
WarrenWeckesser:fix-gh-31415
May 18, 2026
Merged

BUG: core: Don't call INCREF/DECREF on descr in NpyStringAcquireAllocator.#31456
ngoldbaum merged 2 commits into
numpy:mainfrom
WarrenWeckesser:fix-gh-31415

Conversation

@WarrenWeckesser
Copy link
Copy Markdown
Member

Remove incorrect calls of Py_INCREF(descr) and Py_DECREF(descr) in the RAII object NpyStringAcquireAllocator.

Closes gh-31415.

AI Disclosure

No AI tools used.

@WarrenWeckesser
Copy link
Copy Markdown
Member Author

WarrenWeckesser commented May 17, 2026

I included the crasher that @jeromekelleher provided in gh-31415 as a test. By increasing n_cols to 10, I could get the crash to occur with high probability even with the duration of the test reduced to 2 seconds. Still, I'm not sure we want to include this in the test suite.

@WarrenWeckesser WarrenWeckesser marked this pull request as draft May 17, 2026 18:48
@WarrenWeckesser WarrenWeckesser marked this pull request as ready for review May 17, 2026 18:53
@charris charris added 00 - Bug 09 - Backport-Candidate PRs tagged should be backported labels May 17, 2026
@charris charris added this to the 2.4.6 release milestone May 17, 2026
@jeromekelleher
Copy link
Copy Markdown

jeromekelleher commented May 18, 2026

Thanks for the speedy fix @WarrenWeckesser ❤️

@rgommers
Copy link
Copy Markdown
Member

Still, I'm not sure we want to include this in the test suite.

We may want to have a multi-threaded test, but not with explicit time.sleep(2). There must be better patterns already in the test suite already, probably @ngoldbaum can point at an example here.

@seberg
Copy link
Copy Markdown
Member

seberg commented May 18, 2026

We may want to have a multi-threaded test, but not with explicit time.sleep(2). There must be better patterns

Was just confirming that it works: But we don't need any threading at all. We just need to add a parametrization for existing tests with >500 elements or so (let's do 2000 maybe).

We have debug test runs in the test-suite, and these already hit it reliably, the only problem is that the tests don't cover larger tests.
(May be nice to also add to other tests generally, e.g. unique or some ufuncs)

@WarrenWeckesser
Copy link
Copy Markdown
Member Author

But we don't need any threading at all. We just need to add a parametrization for existing tests with >500 elements or so (let's do 2000 maybe).

Which tests are those?

@seberg
Copy link
Copy Markdown
Member

seberg commented May 18, 2026

The TestStringLikeCasts will do the trick (we use it for bytes casting).

EDIT: E.g. ["short", "12345678"] * 1000, works...

This case is a regression test for numpygh-31415 when run in a debug build.
@WarrenWeckesser
Copy link
Copy Markdown
Member Author

I removed the multi-threaded test and added the test case suggested by @seberg.

@ngoldbaum
Copy link
Copy Markdown
Member

Thanks Warren!

@ngoldbaum ngoldbaum merged commit b668e0a into numpy:main May 18, 2026
86 checks passed
@WarrenWeckesser
Copy link
Copy Markdown
Member Author

@ngoldbaum, thanks for finding my mistake 😳.

@ngoldbaum
Copy link
Copy Markdown
Member

No problem, I really appreciate you taking on the fix :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: SIGABRT / heap corruption when two threads operate on basic-slice views of a 2-D StringDType array

6 participants