BUG: core: result_type(0, np.timedelta64(4)) would seg. fault.#20088
BUG: core: result_type(0, np.timedelta64(4)) would seg. fault.#20088charris merged 3 commits intonumpy:mainfrom
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.
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.
Maybe rename to get_descr_from_cast_or_value? But not sure.
There was a problem hiding this comment.
(I am tempted to overindent the arguments, but it is probably just me who does that...)
Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
|
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.