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

Skip to content

Conversation

ngoldbaum
Copy link
Member

Fixes #28197.

The change to run_threaded is unrelated but needed for the way I wrote the test to avoid duplicating keyword arguments. My fault for introducing two keywords that do the same thing πŸ™ƒ.

@ngoldbaum ngoldbaum added the 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703) label Jan 20, 2025
@charris
Copy link
Member

charris commented Jan 21, 2025

Should this be backported? My intent in 2.2.x is to get free threading and typing to a more finished state.

@ngoldbaum
Copy link
Member Author

Thanks for checking, I think this one should be safe to backport.

@@ -922,16 +922,23 @@ PyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis)
}
}

/* Fill in dimensions of new array */
npy_intp dims[NPY_MAXDIMS] = {0};
Copy link
Member

@seberg seberg Jan 20, 2025

Choose a reason for hiding this comment

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

Suggested change
npy_intp dims[NPY_MAXDIMS] = {0};
npy_intp dims[NPY_MAXDIMS];

No need to zero 64 (any) elements.

But looks all good to me, thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

I was taught to always zero-initialize as a defensive programming practice and it makes easier for me to reason about code if I know that instead possibly getting garbage when I dereference a pointer or read a variable, I get a sensible default.

Just to give you some context why I send in code that does that. I'm probably going to continue doing it because it's how I was taught to write C and C++. In the future, if you can give me more context about why you think I shouldn't do it besides "it's unnecessary" I'd appreciate it. I know it's unnecessary if everything is bug-free, it's to make the behavior more predictable if there is a bug.

Copy link
Member

Choose a reason for hiding this comment

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

🀷 maybe I should do it more. Although not sure I'll be convinced of it here when the initialization is right below it and any random value is just as wrong as 0 :).

(I wish that the compiler warnings and sanitizers were better about uninitialized stack usage, at which point I would clearly prefer the warning.)

@seberg seberg added the 09 - Backport-Candidate PRs tagged should be backported label Jan 21, 2025
@ngoldbaum ngoldbaum merged commit 5fe9962 into numpy:main Jan 21, 2025
68 checks passed
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jan 21, 2025
@rgommers rgommers added this to the 2.3.0 release milestone Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: segfault in PyArray_Repeat on free-threaded build
4 participants