Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-106320: Re-add some PyLong/PyDict C-API functions#111162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
encukou merged 2 commits intopython:mainfromscoder:readd_pylong_capi
Oct 25, 2023

Conversation

scoder
Copy link
Contributor

@scoderscoder commentedOct 21, 2023
edited
Loading

Re-add _PyLong_FromByteArray(), _PyLong_AsByteArray(),_PyLong_GCD() and _PyDict_Pop() to the public header files.
They are used by third-party packages and there is no efficient replacement.

See#111140
See#111139
See#111262

jcrist, encukou, and osandov reacted with thumbs up emoji
…) and _PyLong_GCD() to the public header files since they are used by third-party packages and there is no efficient replacement.Seepython#111140Seepython#111139
@scoder
Copy link
ContributorAuthor

@vstinner
Copy link
Member

I would prefer to take it as an opportunity to add a nice public API for that. In the meanwhile (until next alpha release), you can just use the internal C API.

@scoder
Copy link
ContributorAuthor

scoder commentedOct 22, 2023 via email

add a nice public API for that
Oh, I'd be happy to. I see the revert as a way to make sure there *is* an API until we have something to replace it. For which, as Serhiy noted, the design and discussion can take arbitrarily long.
encukou reacted with thumbs up emoji

@scoder
Copy link
ContributorAuthor

Just for the record, I micro-benchmarked_PyLong_AsByteArray() against the C-API call toint.to_bytes() and the incremental unpacking of 62 bit chunks usingPyNumber_And(),PyLong_AsLong() andPyNumber_Rshift(). The code complexity increases substantially from first to last in that order.

# int.to_bytes()$ python3.10 -m timeit -s 'from intbench import i128_from_py' 'i128_from_py(2**126)'200000 loops, best of 5: 1.06 usec per loop# incremental unpacking$ python3.10 -m timeit -s 'from intbench import i128_from_py' 'i128_from_py(2**126)'500000 loops, best of 5: 693 nsec per loop# _PyLong_AsByteArray()$ python3.10 -m timeit -s 'from intbench import i128_from_py' 'i128_from_py(2**126)'500000 loops, best of 5: 504 nsec per loop

This suggests to me that making_PyLong_AsByteArray() public is worth it. The replacements are just horrible to implement, and the "obvious replacement" is really slow.

jcrist reacted with thumbs up emoji

@encukou
Copy link
Member

I would prefer adding these back, so that we can take our time to add a proper replacement.
Or, Victor, do you think you can design and add a good replacement in time for the next alpha?

mdickinson reacted with thumbs up emoji

@scoderscoder changed the titlegh-106320: Re-add some PyLong C-API functionsgh-106320: Re-add some PyLong/PyDict C-API functionsOct 25, 2023
Copy link
Member

@encukouencukou left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I still don't see the reason why this API was removed.PEP-387 says that itcan be removed, not that itshould.
We don't have a good replacement for this API. After we add that, it'll be time to start telling people to change their code.

I take@gvanrossum'scomment on another issue as support for reverting the removal:

I strongly prefer revert over fix, for removed APIs that cause problems.

@encukouencukou merged commita8a89fc intopython:mainOct 25, 2023
@scoderscoder deleted the readd_pylong_capi branchOctober 25, 2023 11:12
@vstinner
Copy link
Member

Victor, do you think you can design and add a good replacement in time for the next alpha?

Yes, I plan to add public APIs to replace these useful functions. I created multiple issues to track that: issues listed in the PR description.

aisk pushed a commit to aisk/cpython that referenced this pull requestFeb 11, 2024
…#111162)*pythongh-106320: Re-add _PyLong_FromByteArray(), _PyLong_AsByteArray() and _PyLong_GCD() to the public header files since they are used by third-party packages and there is no efficient replacement.Seepython#111140Seepython#111139*pythongh-111262: Re-add _PyDict_Pop() to have a C-API until a new public one is designed.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull requestSep 2, 2024
…#111162)*pythongh-106320: Re-add _PyLong_FromByteArray(), _PyLong_AsByteArray() and _PyLong_GCD() to the public header files since they are used by third-party packages and there is no efficient replacement.Seepython#111140Seepython#111139*pythongh-111262: Re-add _PyDict_Pop() to have a C-API until a new public one is designed.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@encukouencukouencukou approved these changes

@corona10corona10Awaiting requested review from corona10corona10 is a code owner

@rhettingerrhettingerAwaiting requested review from rhettingerrhettinger is a code owner

@vstinnervstinnerAwaiting requested review from vstinner

@kumaraditya303kumaraditya303Awaiting requested review from kumaraditya303kumaraditya303 is a code owner

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@scoder@vstinner@encukou

[8]ページ先頭

©2009-2025 Movatter.jp