GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — '_PyLong_NumBits': identifier not found in 3.13 · Issue #119336 · python/cpython

'_PyLong_NumBits': identifier not found in 3.13 #119336

New issue
Copy link
New issue
Copy link
Closed
Closed
'_PyLong_NumBits': identifier not found in 3.13#119336
Copy link
Labels
topic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@clin1234
clin1234
opened on May 21, 2024
Issue body actions

Bug report

Bug description:

While fixing pywin32 to let CI builds work in Python 3.13, the build process complained of not being able to find _PyLong_NumBits. All other Python versions in the CI built successfully.

BOOL PyCom_VariantFromPyObject(PyObject *obj, VARIANT *var)
{
    // ...
    if (PyLong_Check(obj)) {
        int sign = _PyLong_Sign(obj);
        size_t nbits = _PyLong_NumBits(obj);
        if (nbits == (size_t)-1 && PyErr_Occurred())
            return FALSE;
    // ...
}

The function still exists in main, apparently inaccessible via the public C API since 3.13. What's the recommended replacement?

CPython versions tested on:

3.8, 3.9, 3.10, 3.11, 3.12, 3.13

Operating systems tested on:

Windows

Linked PRs

  • gh-119336: Restore _PyLong_NumBits #119418
  • [3.13] gh-119336: Restore removed _PyLong_NumBits() function (GH-119418) #119970
Reacted by Avasam

Activity

  1. clin1234
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on May 21, 2024
  2. mdboom
    added
    topic-C-API
    on May 22, 2024
  3. emmatyping commented on May 22, 2024

    @emmatyping
    emmatyping
    on May 22, 2024
    Member
    More actions

    In 5846924 Victor restored

    • _PyLong_Copy()
    • _PyLong_FromDigits()
    • _PyLong_New()
    • _PyLong_Sign()

    It seems reasonable to include _PyLong_NumBits as well, since like the others there isn't a great replacement.

  4. clin1234 commented on May 22, 2024

    @clin1234
    clin1234
    on May 22, 2024
    ContributorAuthor
    More actions

    Will it be restored in the next beta 3.13 release, or will I have to wait until the first 3.14 alpha release?

  5. emmatyping
    added a commit that references this issue on May 22, 2024

    pythongh-119336: Restore _PyLong_NumBits

    6a12039
  6. emmatyping commented on May 22, 2024

    @emmatyping
    emmatyping
    on May 22, 2024
    Member
    More actions

    I cannot make that call, but I made #119418 against 3.14 for now (it can be backported for 3.13 if that's what people decide). Eventually it seems like a good idea to make this public.

  7. vstinner commented on May 28, 2024

    @vstinner
    vstinner
    on May 28, 2024
    Member
    More actions

    You can modify pywin32 to call the bit_length() method which returns a Python int object. Then if you need a size_t, you can call PyLong_AsSize_t.

    If this function is called by one project, we should consider making it public, rather than restoring the old private function.

  8. clin1234 commented on May 28, 2024

    @clin1234
    clin1234
    on May 28, 2024
    ContributorAuthor
    More actions

    You can modify pywin32 to call the bit_length() method which returns a Python int object. Then if you need a size_t, you can call PyLong_AsSize_t.

    If this function is called by one project, we should consider making it public, rather than restoring the old private function.

    How would I access the built-in bit_length() method within the C API?

  9. da-woods commented on May 29, 2024

    @da-woods
    da-woods
    on May 29, 2024
    Contributor
    More actions

    How would I access the built-in bit_length() method within the C API?

    PyObject_CallMethod(obj, "bit_length", NULL)

    (Not taking a view on whether that justifies not restoring the function though)

  10. vstinner commented on May 29, 2024

    @vstinner
    vstinner
    on May 29, 2024
    Member
    More actions

    A code search in PyPI top 7,500 projects found other projects:

    • mariadb (1.1.10)
    • pickle5 (0.0.12)
    • zodbpickle (3.2)

    pickle5 and zodbpickle contain copies of the Python source code, but MariaDB is a good usage example. So maybe it's worth it to add a function.

    I created issue gh-119714: [C API] Add PyLong_GetNumBits() function.

  11. vstinner commented on May 29, 2024

    @vstinner
    vstinner
    on May 29, 2024
    Member
    More actions

    A code search in PyPI top 7,500 projects found other projects:

    @encukou also identified that panda3d uses it: https://github.com/panda3d/panda3d/blob/adb92428856853019583f398d27c5d34e44a9343/panda/src/putil/bitArray_ext.cxx#L28

  12. vstinner
    added a commit that references this issue on May 30, 2024

    gh-119336: Restore removed _PyLong_NumBits() function (#119418)

    e50fac9
  13. vstinner commented on Jun 3, 2024

    @vstinner
    vstinner
    on Jun 3, 2024
    Member
    More actions

    Function restored by commit e50fac9

  14. vstinner
    closed this as completedon Jun 3, 2024
  15. miss-islington
    added a commit that references this issue on Jun 3, 2024

    pythongh-119336: Restore removed _PyLong_NumBits() function (pythonGH…

    bf67508
  16. vstinner
    added a commit that references this issue on Jun 3, 2024

    [3.13] gh-119336: Restore removed _PyLong_NumBits() function (GH-119418…

    cc663b7
  17. estyxx
    added a commit that references this issue on Jul 17, 2024

    pythongh-119336: Restore removed _PyLong_NumBits() function (python#1…

    468b614
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.