]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Use _PyLong_IsNegative instead of _PyLong_Sign if appropriate. (GH-120493)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 24 Jun 2024 06:49:01 +0000 (09:49 +0300)
committerGitHub <noreply@github.com>
Mon, 24 Jun 2024 06:49:01 +0000 (09:49 +0300)
It is faster and more obvious.

Modules/_ctypes/_ctypes.c
Modules/_interpretersmodule.c
Modules/_io/_iomodule.c

index 1d9534671a4ee836790da4f40635b736e4832b2c..222700b4b7cc694d624a40f0a179c168afde21d8 100644 (file)
@@ -1606,7 +1606,7 @@ PyCArrayType_init(PyObject *self, PyObject *args, PyObject *kwds)
         goto error;
     }
 
-    if (_PyLong_Sign(length_attr) == -1) {
+    if (_PyLong_IsNegative((PyLongObject *)length_attr)) {
         Py_DECREF(length_attr);
         PyErr_SetString(PyExc_ValueError,
                         "The '_length_' attribute must not be negative");
index 6df6952dfe384f9c1511d01691343b0c7a33d926..6f3392fe6ea28ddca08d0114880de450bad31c43 100644 (file)
@@ -10,7 +10,6 @@
 #include "pycore_crossinterp.h"   // struct _xid
 #include "pycore_interp.h"        // _PyInterpreterState_IDIncref()
 #include "pycore_initconfig.h"    // _PyErr_SetFromPyStatus()
-#include "pycore_long.h"          // _PyLong_IsNegative()
 #include "pycore_modsupport.h"    // _PyArg_BadArgument()
 #include "pycore_namespace.h"     // _PyNamespace_New()
 #include "pycore_pybuffer.h"      // _PyBuffer_ReleaseInInterpreterAndRawFree()
index 269070fe2b0a4244e33673cd35da60f0d0565400..d236098e6977e8116bd5c12f045d7c714241bd2a 100644 (file)
@@ -10,7 +10,7 @@
 #include "Python.h"
 #include "pycore_abstract.h"      // _PyNumber_Index()
 #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_pystate.h"       // _PyInterpreterState_GET()
 
@@ -544,10 +544,7 @@ PyNumber_AsOff_t(PyObject *item, PyObject *err)
      */
     if (!err) {
         assert(PyLong_Check(value));
-        /* Whether or not it is less than or equal to
-           zero is determined by the sign of ob_size
-        */
-        if (_PyLong_Sign(value) < 0)
+        if (_PyLong_IsNegative((PyLongObject *)value))
             result = PY_OFF_T_MIN;
         else
             result = PY_OFF_T_MAX;