]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106320: Remove private _PyLong_Sign() (#108743)
authorVictor Stinner <vstinner@python.org>
Fri, 1 Sep 2023 07:13:07 +0000 (09:13 +0200)
committerGitHub <noreply@github.com>
Fri, 1 Sep 2023 07:13:07 +0000 (09:13 +0200)
Move the private _PyLong_Sign() and _PyLong_NumBits() functions
to the internal C API (pycore_long.h).

Modules/_testcapi/long.c now uses the internal C API.

Include/cpython/longobject.h
Include/internal/pycore_long.h
Modules/_io/_iomodule.c
Modules/_testcapi/long.c

index 32c40b083b7ab67250de605c8a5f407c30d9ab9e..57834173490c99b7db2c0e413b38d9aa6ddb2356 100644 (file)
@@ -4,21 +4,6 @@
 
 PyAPI_FUNC(PyObject*) PyLong_FromUnicodeObject(PyObject *u, int base);
 
-/* _PyLong_Sign.  Return 0 if v is 0, -1 if v < 0, +1 if v > 0.
-   v must not be NULL, and must be a normalized long.
-   There are no error cases.
-*/
-PyAPI_FUNC(int) _PyLong_Sign(PyObject *v);
-
-/* _PyLong_NumBits.  Return the number of bits needed to represent the
-   absolute value of a long.  For example, this returns 1 for 1 and -1, 2
-   for 2 and -2, and 2 for 3 and -3.  It returns 0 for 0.
-   v must not be NULL, and must be a normalized long.
-   (size_t)-1 is returned and OverflowError set if the true result doesn't
-   fit in a size_t.
-*/
-PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v);
-
 PyAPI_FUNC(int) PyUnstable_Long_IsCompact(const PyLongObject* op);
 PyAPI_FUNC(Py_ssize_t) PyUnstable_Long_CompactValue(const PyLongObject* op);
 
index c411ac654387c3d5ad6e82d465a83ec179be5ad7..3c253ed7ff556bdd711b1e7d8a5edc1a92db31ca 100644 (file)
@@ -58,6 +58,23 @@ PyAPI_FUNC(PyLongObject*) _PyLong_FromDigits(
     Py_ssize_t digit_count,
     digit *digits);
 
+// _PyLong_Sign.  Return 0 if v is 0, -1 if v < 0, +1 if v > 0.
+// v must not be NULL, and must be a normalized long.
+// There are no error cases.
+//
+// Export for '_pickle' shared extension.
+PyAPI_FUNC(int) _PyLong_Sign(PyObject *v);
+
+// _PyLong_NumBits.  Return the number of bits needed to represent the
+// absolute value of a long.  For example, this returns 1 for 1 and -1, 2
+// for 2 and -2, and 2 for 3 and -3.  It returns 0 for 0.
+// v must not be NULL, and must be a normalized long.
+// (size_t)-1 is returned and OverflowError set if the true result doesn't
+// fit in a size_t.
+//
+// Export for 'math' shared extension.
+PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v);
+
 
 /* runtime lifecycle */
 
index cc844527da5838a3e4c1c2520a521fdda5fba36e..173f5b55e5f732f6159e78bf12fc73f74c4850ed 100644 (file)
@@ -10,6 +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_pyerrors.h"      // _PyErr_ChainExceptions1()
 #include "pycore_pystate.h"       // _PyInterpreterState_GET()
 
index 6b74e0ab8e0d1cc2651a6f42c9b390bbd7393e00..c1d2d42a2c434e38c502b1e2bd6623f5abec84d2 100644 (file)
@@ -1,5 +1,10 @@
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "parts.h"
 #include "clinic/long.c.h"
+#include "pycore_long.h"          // _PyLong_Sign()
 
 /*[clinic input]
 module _testcapi