mirror of
https://github.com/python/cpython.git
synced 2025-12-31 12:33:28 +00:00
gh-135763: AC: Implement `allow_negative for Py_ssize_t` (#138150)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
parent
7c92497e5c
commit
47bc10e6b3
7 changed files with 200 additions and 24 deletions
|
|
@ -33,6 +33,19 @@ _Py_convert_optional_to_ssize_t(PyObject *obj, void *result)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
_Py_convert_optional_to_non_negative_ssize_t(PyObject *obj, void *result)
|
||||
{
|
||||
if (!_Py_convert_optional_to_ssize_t(obj, result)) {
|
||||
return 0;
|
||||
}
|
||||
if (obj != Py_None && *((Py_ssize_t *)result) < 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "argument cannot be negative");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Helper for mkvalue() to scan the length of a format */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue