You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add PyFloat_(Pack|Unpack)(2|4|8) to the public C API #91062
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2022-03-14.15:58:36.669>created_at=<Date2022-03-03.03:09:32.087>labels= ['expert-C-API', '3.11']
title='Add PyFloat_(Pack|Unpack)(2|4|8) to the public C API'updated_at=<Date2022-03-14.15:58:36.668>user='https://github.com/methane'
_PyFloat_(Pack|Unpack)(4|8) is very nice API for serializers like msgpack.
Converting double and float into char[] is not trivial and these APIs do it in very efficient way.
And these APIs don't reveal CPython internal strucutre. It just convert double and float into char[].
So please keep these APIs public for libraries like msgpack.
I reopen the issue, I would like to make these functions public :-) I searched for the 6 functions moved to the internal C API and I found 6 projets using it in the top 5000 PyPI projects (at 2022-01-26):
changed the title [-]Make _PyFloat_(Pack|Unpack)(4|8) cpython API, not internal.[/-][+]Add PyFloat_(Pack|Unpack)(2|4|8) to the public C API[/+]on Mar 3, 2022
changed the title [-]Make _PyFloat_(Pack|Unpack)(4|8) cpython API, not internal.[/-][+]Add PyFloat_(Pack|Unpack)(2|4|8) to the public C API[/+]on Mar 3, 2022
Activity
methane commentedon Mar 3, 2022
Original issue. msgpack/msgpack-python#497
_PyFloat_(Pack|Unpack)(4|8) is very nice API for serializers like msgpack.
Converting double and float into char[] is not trivial and these APIs do it in very efficient way.
And these APIs don't reveal CPython internal strucutre. It just convert double and float into char[].
So please keep these APIs public for libraries like msgpack.
vstinner commentedon Mar 3, 2022
I disagree. A function should be either fully public: tested, documented. Or fully internal.
In the past, many functions were in both, in the gray area.
If these functions are useful, please make them *public* and document them. I'm +1 to make these functions public.
methane commentedon Mar 3, 2022
OK. By quick grepping, I found only msgpack and bitstruct use these API.
It is not enough number to make them public.
vstinner commentedon Mar 3, 2022
I reopen the issue, I would like to make these functions public :-) I searched for the 6 functions moved to the internal C API and I found 6 projets using it in the top 5000 PyPI projects (at 2022-01-26):
The 6 functions are used:
[-]Make _PyFloat_(Pack|Unpack)(4|8) cpython API, not internal.[/-][+]Add PyFloat_(Pack|Unpack)(2|4|8) to the public C API[/+][-]Make _PyFloat_(Pack|Unpack)(4|8) cpython API, not internal.[/-][+]Add PyFloat_(Pack|Unpack)(2|4|8) to the public C API[/+]vstinner commentedon Mar 3, 2022
The pack/unpack functions have been moved to the internal C API by this change:
commit 0a883a7
Author: Victor Stinner <vstinner@python.org>
Date: Thu Oct 14 23:41:06 2021 +0200
vstinner commentedon Mar 3, 2022
I prepared a pythoncapi_compat PR to provide these functions to Python 3.10 and older:
python/pythoncapi-compat#26
Note: bpo-11734 (commit 7c4e409) added _PyFloat_Pack2() and _PyFloat_Unpack2() to Python 3.6.0b1.
vstinner commentedon Mar 11, 2022
New changeset 882d809 by Victor Stinner in branch 'main':
bpo-46906: Add PyFloat_Pack8() to the C API (GH-31657)
882d809
vstinner commentedon Mar 11, 2022
PR for msgpack: msgpack/msgpack-python#499
vstinner commentedon Mar 12, 2022
PR for bitstruct: eerimoq/bitstruct#26
vstinner commentedon Mar 12, 2022
zodbpickle issue: zopefoundation/zodbpickle#67
vstinner commentedon Mar 14, 2022
New changeset 11c25b8 by Victor Stinner in branch 'main':
bpo-46906: Mention native endian in PyFloat_Pack8() doc (GH-31866)
11c25b8
vstinner commentedon Mar 14, 2022
msgpack and bitstruct use the newly added functions: my two PRs got merged. msgpack was my main motivation to add these functions :-)
Thanks to great reviews, the functions got a new better documentation!
I close the issue. Thanks again for reviews!