Use _PyLong_IsNegative instead of _PyLong_Sign if appropriate. (GH-120493)
It is faster and more obvious.
This commit is contained in:
parent
35e998f560
commit
02df679574
3 changed files with 3 additions and 7 deletions
|
|
@ -1606,7 +1606,7 @@ PyCArrayType_init(PyObject *self, PyObject *args, PyObject *kwds)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyLong_Sign(length_attr) == -1) {
|
if (_PyLong_IsNegative((PyLongObject *)length_attr)) {
|
||||||
Py_DECREF(length_attr);
|
Py_DECREF(length_attr);
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
"The '_length_' attribute must not be negative");
|
"The '_length_' attribute must not be negative");
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@
|
||||||
#include "pycore_crossinterp.h" // struct _xid
|
#include "pycore_crossinterp.h" // struct _xid
|
||||||
#include "pycore_interp.h" // _PyInterpreterState_IDIncref()
|
#include "pycore_interp.h" // _PyInterpreterState_IDIncref()
|
||||||
#include "pycore_initconfig.h" // _PyErr_SetFromPyStatus()
|
#include "pycore_initconfig.h" // _PyErr_SetFromPyStatus()
|
||||||
#include "pycore_long.h" // _PyLong_IsNegative()
|
|
||||||
#include "pycore_modsupport.h" // _PyArg_BadArgument()
|
#include "pycore_modsupport.h" // _PyArg_BadArgument()
|
||||||
#include "pycore_namespace.h" // _PyNamespace_New()
|
#include "pycore_namespace.h" // _PyNamespace_New()
|
||||||
#include "pycore_pybuffer.h" // _PyBuffer_ReleaseInInterpreterAndRawFree()
|
#include "pycore_pybuffer.h" // _PyBuffer_ReleaseInInterpreterAndRawFree()
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "pycore_abstract.h" // _PyNumber_Index()
|
#include "pycore_abstract.h" // _PyNumber_Index()
|
||||||
#include "pycore_initconfig.h" // _PyStatus_OK()
|
#include "pycore_initconfig.h" // _PyStatus_OK()
|
||||||
#include "pycore_long.h" // _PyLong_Sign()
|
#include "pycore_long.h" // _PyLong_IsNegative()
|
||||||
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
|
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
|
||||||
#include "pycore_pystate.h" // _PyInterpreterState_GET()
|
#include "pycore_pystate.h" // _PyInterpreterState_GET()
|
||||||
|
|
||||||
|
|
@ -544,10 +544,7 @@ PyNumber_AsOff_t(PyObject *item, PyObject *err)
|
||||||
*/
|
*/
|
||||||
if (!err) {
|
if (!err) {
|
||||||
assert(PyLong_Check(value));
|
assert(PyLong_Check(value));
|
||||||
/* Whether or not it is less than or equal to
|
if (_PyLong_IsNegative((PyLongObject *)value))
|
||||||
zero is determined by the sign of ob_size
|
|
||||||
*/
|
|
||||||
if (_PyLong_Sign(value) < 0)
|
|
||||||
result = PY_OFF_T_MIN;
|
result = PY_OFF_T_MIN;
|
||||||
else
|
else
|
||||||
result = PY_OFF_T_MAX;
|
result = PY_OFF_T_MAX;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue