aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-03 11:29:07 +0200
committerGitHub <noreply@github.com>2024-06-03 09:29:07 +0000
commitcc663b7e25539d938bf71bc1b4d69efd8824c2d3 (patch)
tree9b58709b49dc0eff2c65d5e0d68ad79285695d30
parent[3.13] gh-119856: Support exiting help() with just "exit" (GH-119858) (#119967) (diff)
downloadcpython-cc663b7e25539d938bf71bc1b4d69efd8824c2d3.tar.gz
cpython-cc663b7e25539d938bf71bc1b4d69efd8824c2d3.tar.bz2
cpython-cc663b7e25539d938bf71bc1b4d69efd8824c2d3.zip
[3.13] gh-119336: Restore removed _PyLong_NumBits() function (GH-119418) (#119970)
gh-119336: Restore removed _PyLong_NumBits() function (GH-119418) It is used by the pywin32 project. (cherry picked from commit e50fac96e82d857ecc024b4cd4e012493b077064) Co-authored-by: Ethan Smith <ethan@ethanhs.me>
-rw-r--r--Include/cpython/longobject.h9
-rw-r--r--Include/internal/pycore_long.h11
-rw-r--r--Misc/NEWS.d/next/C API/2024-05-22-17-50-48.gh-issue-119336.ff3qnS.rst1
3 files changed, 10 insertions, 11 deletions
diff --git a/Include/cpython/longobject.h b/Include/cpython/longobject.h
index 189229ee103..96815938c82 100644
--- a/Include/cpython/longobject.h
+++ b/Include/cpython/longobject.h
@@ -60,6 +60,15 @@ PyAPI_FUNC(Py_ssize_t) PyUnstable_Long_CompactValue(const PyLongObject* op);
// 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);
+
/* _PyLong_FromByteArray: View the n unsigned bytes as a binary integer in
base 256, and return a Python int with the same numeric value.
If n is 0, the integer is 0. Else:
diff --git a/Include/internal/pycore_long.h b/Include/internal/pycore_long.h
index f04f66d053b..8513695c22e 100644
--- a/Include/internal/pycore_long.h
+++ b/Include/internal/pycore_long.h
@@ -47,17 +47,6 @@ extern "C" {
# error "_PY_LONG_DEFAULT_MAX_STR_DIGITS smaller than threshold."
#endif
-// _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 */
extern PyStatus _PyLong_InitTypes(PyInterpreterState *);
diff --git a/Misc/NEWS.d/next/C API/2024-05-22-17-50-48.gh-issue-119336.ff3qnS.rst b/Misc/NEWS.d/next/C API/2024-05-22-17-50-48.gh-issue-119336.ff3qnS.rst
new file mode 100644
index 00000000000..e530bb45d35
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2024-05-22-17-50-48.gh-issue-119336.ff3qnS.rst
@@ -0,0 +1 @@
+Restore the removed ``_PyLong_NumBits()`` function. It is used by the pywin32 project. Patch by Ethan Smith