8000 gh-106320: Remove private _PyLong_Sign() (#108743) · python/cpython@3edcf74 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3edcf74

Browse files
authored
gh-106320: Remove private _PyLong_Sign() (#108743)
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.
1 parent c1e2f3b commit 3edcf74

File tree

4 files changed

+23
-15
lines changed
  • Include
  • Modules
  • 4 files changed

    +23
    -15
    lines changed

    Include/cpython/longobject.h

    Lines changed: 0 additions & 15 deletions
    Original file line numberDiff line numberDiff line change
    @@ -4,21 +4,6 @@
    44

    55
    PyAPI_FUNC(PyObject*) PyLong_FromUnicodeObject(PyObject *u, int base);
    66

    7-
    /* _PyLong_Sign. Return 0 if v is 0, -1 if v < 0, +1 if v > 0.
    8-
    v must not be NULL, and must be a normalized long.
    9-
    There are no error cases.
    10-
    */
    11-
    PyAPI_FUNC(int) _PyLong_Sign(PyObject *v);
    12-
    13-
    /* _PyLong_NumBits. Return the number of bits needed to represent the
    14-
    absolute value of a long. For example, this returns 1 for 1 and -1, 2
    15-
    for 2 and -2, and 2 for 3 and -3. It returns 0 for 0.
    16-
    v must not be NULL, and must be a normalized long.
    17-
    (size_t)-1 is returned and OverflowError set if the true result doesn't
    18-
    fit in a size_t.
    19-
    */
    20-
    PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v);
    21-
    227
    PyAPI_FUNC(int) PyUnstable_Long_IsCompact(const PyLongObject* op);
    238
    PyAPI_FUNC(Py_ssize_t) PyUnstable_Long_CompactValue(const PyLongObject* op);
    249

    Include/internal/pycore_long.h

    Lines changed: 17 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -58,6 +58,23 @@ PyAPI_FUNC(PyLongObject*) _PyLong_FromDigits(
    5858
    Py_ssize_t digit_count,
    5959
    digit *digits);
    6060

    61+
    // _PyLong_Sign. Return 0 if v is 0, -1 if v < 0, +1 if v > 0.
    62+
    // v must not be NULL, and must be a normalized long.
    63+
    // There are no error cases.
    64+
    //
    65+
    // Export for '_pickle' shared extension.
    66+
    PyAPI_FUNC(int) _PyLong_Sign(PyObject *v);
    67+
    68+
    // _PyLong_NumBits. Return the number of bits needed to represent the
    69+
    // absolute value of a long. For example, this returns 1 for 1 and -1, 2
    70+
    // for 2 and -2, and 2 for 3 and -3. It returns 0 for 0.
    71+
    // v must not be NULL, and must be a normalized long.
    72+
    // (size_t)-1 is returned and OverflowError set if the true result doesn't
    73+
    // fit in a size_t.
    74+
    //
    75+
    // Export for 'math' shared extension.
    76+
    PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v);
    77+
    6178

    6279
    /* runtime lifecycle */
    6380

    Modules/_io/_iomodule.c

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -10,6 +10,7 @@
    1010
    #include "Python.h"
    1111
    #include "pycore_abstract.h" // _PyNumber_Index()
    1212
    #include "pycore_initconfig.h" // _PyStatus_OK()
    13+
    #include "pycore_long.h" // _PyLong_Sign()
    1314
    #include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
    1415
    #include "pycore_pystate.h" // _PyInterpreterState_GET()
    1516

    Modules/_testcapi/long.c

    Lines changed: 5 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,5 +1,10 @@
    1+
    #ifndef Py_BUILD_CORE_BUILTIN
    2+
    # define Py_BUILD_CORE_MODULE 1
    3+
    #endif
    4+
    15
    #include "parts.h"
    26
    #include "clinic/long.c.h"
    7+
    #include "pycore_long.h" // _PyLong_Sign()
    38

    49
    /*[clinic input]
    510
    module _testcapi

    0 commit comments

    Comments
     (0)
    0