Skip to content

Commit

Permalink
pythongh-119336: Restore _PyLong_NumBits
Browse files Browse the repository at this point in the history
This is used in pywin32, and the function being moved to internal headers
broke with 3.13. Restore it for now to eventually be considered for being
made a public symbol.

See also pythongh-112026 (previous restoration) and pythongh-111481 (public replacements)
  • Loading branch information
ethanhs committed May 22, 2024
1 parent a463cd8 commit 6a12039
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
9 changes: 9 additions & 0 deletions Include/cpython/longobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 0 additions & 11 deletions Include/internal/pycore_long.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down

0 comments on commit 6a12039

Please sign in to comment.