bpo-29843: Raise ValueError instead of OverflowError in case of a negative _length_ in a ctypes.Array subclass#3822
Conversation
Modules/_ctypes/_ctypes.c
Outdated
| PyErr_SetString(PyExc_ValueError, | ||
| "The '_length_' attribute must be non-negative"); | ||
| } | ||
| Py_DECREF(length_attr); |
There was a problem hiding this comment.
I think this can be moved right after PyLong_AsLongAndOverflow().
taleinat
left a comment
There was a problem hiding this comment.
LGTM.
@serhiy-storchaka, can this go in?
|
@orenmn: Can you please update or rebase this change? |
I am sorry, but I am currently very busy, and so I would be happy if someone else did that. |
3dddab3 to
8e3d4ba
Compare
|
It is not so easy, since In addition, there is a behavior difference between |
|
Can we just add a |
I mean |
|
Perhaps. Just now the solution of this issue requires different code. |
|
+1 to keep PyLong_AsSsize_t() but use _PyLong_Sign() to raise the ValueError (for negative number). @taleinat: are you interested to rework this PR or maybe create a new one based on this PR? |
|
This is superseded by PR GH-10029. |
_ctypes.c: add checks to find whether_length_is negative or too big, and raise an error accordingly.test_arrays.py: add tests to verify that the right error is raised for various values of_length_.https://bugs.python.org/issue29843