mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
gh-121115: Skip __index__ in PyLong_AsNativeBytes by default (GH-121118)
This commit is contained in:
parent
81a654a342
commit
2894aa14f2
5 changed files with 33 additions and 9 deletions
|
|
@ -1128,13 +1128,17 @@ PyLong_AsNativeBytes(PyObject* vv, void* buffer, Py_ssize_t n, int flags)
|
|||
if (PyLong_Check(vv)) {
|
||||
v = (PyLongObject *)vv;
|
||||
}
|
||||
else {
|
||||
else if (flags != -1 && (flags & Py_ASNATIVEBYTES_ALLOW_INDEX)) {
|
||||
v = (PyLongObject *)_PyNumber_Index(vv);
|
||||
if (v == NULL) {
|
||||
return -1;
|
||||
}
|
||||
do_decref = 1;
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError, "expect int, got %T", vv);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((flags != -1 && (flags & Py_ASNATIVEBYTES_REJECT_NEGATIVE))
|
||||
&& _PyLong_IsNegative(v)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue