Skip to content

Conversation

@vstinner
Copy link
Member

@vstinnervstinner commented Sep 1, 2023

Move the private _PyLong_IsCompact() and _PyLong_CompactValue() functions to the internal C API (pycore_long.h). Public PyUnstable_Long_IsCompact() and PyUnstable_Long_CompactValue() functions can be used instead.

Remove "const" qualifier from PyUnstable_Long_IsCompact() and PyUnstable_Long_CompactValue() parameter type.


📚 Documentation preview 📚: https://cpython-previews--108742.org.readthedocs.build/

@vstinner
Copy link
MemberAuthor

With this change, PyUnstable_Long_IsCompact() and PyUnstable_Long_CompactValue() become regular opaque function calls. They are no longer implemented as static inline functions. That's needed to be able remove the 2 associated static inline functions from the public C API.

Remove "const" qualifier from PyUnstable_Long_IsCompact() and PyUnstable_Long_CompactValue() parameter type.

When I tried to use the const qualified in the public C API in the past, I had issues :-( I prefer to avoid it. For the internal C API with static inline functions, that's fine.

See:

Move the private _PyLong_IsCompact() and _PyLong_CompactValue() functions to the internal C API (pycore_long.h). Public PyUnstable_Long_IsCompact() and PyUnstable_Long_CompactValue() functions can be used instead. Remove "const" qualifier from PyUnstable_Long_IsCompact() and PyUnstable_Long_CompactValue() parameter type.
@vstinnervstinnerforce-pushed the remove_pylong_iscompat branch from 1969769 to c6be6f8CompareSeptember 1, 2023 07:15
@vstinnervstinner added the needs backport to 3.12 only security fixes label Sep 1, 2023
@vstinner
Copy link
MemberAuthor

@gvanrossum@markshannon: Are the private _PyLong_IsCompact() and _PyLong_CompactValue() functions exposed by <Python.h> on purpose? Or are you are ok to move them to the internal C API?

I don't know the impact on performance. I'm more in favor of hiding implementation details.

If these functions are moved to the internal C API, are you ok to also make this change in Python 3.12?

Remove "const" qualifier from PyUnstable_Long_IsCompact() and PyUnstable_Long_CompactValue() parameter type.

I don't have a strong opinion on that, I'm also fine with keeping const if you prefer :-) It's just that in the past, I tried to use const in the public C API and "I got issues".

@gvanrossum
Copy link
Member

Please don’t touch these. They are meant to be exported.

@gvanrossum
Copy link
Member

Also it’s too late for 3.12.

@vstinner
Copy link
MemberAuthor

Please don’t touch these. They are meant to be exported.

Ok, let's keep them.

@vstinnervstinner closed this Sep 1, 2023
@vstinnervstinner deleted the remove_pylong_iscompat branch September 1, 2023 15:04
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@vstinner@gvanrossum@bedevere-bot