Skip to content

Commit cc663b7

Browse files
[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 e50fac9) Co-authored-by: Ethan Smith <ethan@ethanhs.me>
1 parent c3fc3a2 commit cc663b7

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

Include/cpython/longobject.h

+9
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ PyAPI_FUNC(Py_ssize_t) PyUnstable_Long_CompactValue(const PyLongObject* op);
6060
// There are no error cases.
6161
PyAPI_FUNC(int) _PyLong_Sign(PyObject *v);
6262

63+
/* _PyLong_NumBits. Return the number of bits needed to represent the
64+
absolute value of a long. For example, this returns 1 for 1 and -1, 2
65+
for 2 and -2, and 2 for 3 and -3. It returns 0 for 0.
66+
v must not be NULL, and must be a normalized long.
67+
(size_t)-1 is returned and OverflowError set if the true result doesn't
68+
fit in a size_t.
69+
*/
70+
PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v);
71+
6372
/* _PyLong_FromByteArray: View the n unsigned bytes as a binary integer in
6473
base 256, and return a Python int with the same numeric value.
6574
If n is 0, the integer is 0. Else:

Include/internal/pycore_long.h

-11
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,6 @@ extern "C" {
4747
# error "_PY_LONG_DEFAULT_MAX_STR_DIGITS smaller than threshold."
4848
#endif
4949

50-
// _PyLong_NumBits. Return the number of bits needed to represent the
51-
// absolute value of a long. For example, this returns 1 for 1 and -1, 2
52-
// for 2 and -2, and 2 for 3 and -3. It returns 0 for 0.
53-
// v must not be NULL, and must be a normalized long.
54-
// (size_t)-1 is returned and OverflowError set if the true result doesn't
55-
// fit in a size_t.
56-
//
57-
// Export for 'math' shared extension.
58-
PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v);
59-
60-
6150
/* runtime lifecycle */
6251

6352
extern PyStatus _PyLong_InitTypes(PyInterpreterState *);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Restore the removed ``_PyLong_NumBits()`` function. It is used by the pywin32 project. Patch by Ethan Smith

0 commit comments

Comments
 (0)