-
-
Notifications
You must be signed in to change notification settings - Fork 11.9k
BUG: core: result_type(0, np.timedelta64(4)) would seg. fault. #20088
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
Conversation
96cee0b to
2544134
Compare
|
I don't know what went wrong with the Travis CI Python 3.10-dev job, but I suspect it is not related to this PR. The log has just one line: |
Before this change, the line in convert_datatype.c
result = PyArray_CastDescrToDType(all_descriptors[0], common_dtype);
would trigger a seg. fault with a call such as
np.result_type(0, np.timedelta64(4))
The problem was that `all_descriptors[0]` was NULL, and it was
dereferenced in PyArray_CastDescrToDType.
The code in the loop that followed the above line avoided passing
NULL values in all_descriptors[i] to PyArray_CastDescrToDType by
checking that the corresponding input argument to `result_type`
was not a Python scalar. A different code path was taken in that
case. The seg. fault is fixed by applying that same check to the
first argument.
Closes numpygh-20077.
2544134 to
0e9e016
Compare
|
Force-pushed a trivial change. All the tests pass--I guess the Travis CI issue was a transient one. |
seberg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, annoying complexity here with that value-based promotion/casting :(. An obvious fix though, since it just extends the ugly logic from above.
My only comment is to try to be a bit more clear that this helper only makes sense in the context of np.result_type
| * See that function for the meaning and contents of the parameters. | ||
| */ | ||
| static PyArray_Descr * | ||
| get_dtype_from_descr_and_common( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename to get_descr_from_cast_or_value? But not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I am tempted to overindent the arguments, but it is probably just me who does that...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
Thanks Warren. |
Before this change, the line in convert_datatype.c
would trigger a seg. fault with a call such as
The problem was that
all_descriptors[0]was NULL, and it wasdereferenced in PyArray_CastDescrToDType.
The code in the loop that followed the above line avoided passing
NULL values in all_descriptors[i] to PyArray_CastDescrToDType by
checking that the corresponding input argument to
result_typewas not a Python scalar. A different code path was taken in that
case. The seg. fault is fixed by applying that same check to the
first argument.
Closes gh-20077.