Skip to content

Add PyFloat_(Pack|Unpack)(2|4|8) to the public C API #91062

Closed

Description

@methane
BPO 46906
Nosy @malemburg, @rhettinger, @mdickinson, @vstinner, @methane
PRs
  • bpo-46906: Move _PyFloat_{Pack,Unpack}{4,8} from internal to cpython #31649
  • bpo-46906: Add PyFloat_Pack8() to the C API #31657
  • bpo-46906: Mention PY_BIG_ENDIAN in PyFloat_Pack8() doc #31832
  • bpo-46906: Mention native endian in PyFloat_Pack8() doc #31866
  • 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 = None
    closed_at = <Date 2022-03-14.15:58:36.669>
    created_at = <Date 2022-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 = <Date 2022-03-14.15:58:36.668>
    user = 'https://github.com/methane'

    bugs.python.org fields:

    activity = <Date 2022-03-14.15:58:36.668>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-03-14.15:58:36.669>
    closer = 'vstinner'
    components = ['C API']
    creation = <Date 2022-03-03.03:09:32.087>
    creator = 'methane'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46906
    keywords = ['patch']
    message_count = 12.0
    messages = ['414401', '414410', '414411', '414416', '414419', '414427', '414944', '414952', '414953', '414954', '415151', '415152']
    nosy_count = 6.0
    nosy_names = ['lemburg', 'rhettinger', 'mark.dickinson', 'vstinner', 'stutzbach', 'methane']
    pr_nums = ['31649', '31657', '31832', '31866']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue46906'
    versions = ['Python 3.11']

    Activity

    1. methane commented on Mar 3, 2022

      @methane
      MemberAuthor

      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.

    2. vstinner commented on Mar 3, 2022

      @vstinner
      Member

      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.

    3. methane commented on Mar 3, 2022

      @methane
      MemberAuthor

      OK. By quick grepping, I found only msgpack and bitstruct use these API.
      It is not enough number to make them public.

    4. vstinner commented on Mar 3, 2022

      @vstinner
      Member

      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):

      • msgpack
      • ddtrace
      • bitstruct
      • pickle5
      • line_profiler
      • zodbpickle

      The 6 functions are used:

      • _PyFloat_Pack2()
      • _PyFloat_Pack4()
      • _PyFloat_Pack8()
      • _PyFloat_Unpack2()
      • _PyFloat_Unpack4()
      • _PyFloat_Unpack8()
    5. 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
    6. 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
    7. vstinner commented on Mar 3, 2022

      @vstinner
      Member

      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

      bpo-35134: Add [Include/cpython/floatobject.h](https://github.com/python/cpython/blob/main/Include/cpython/floatobject.h) (GH-28957)
      
      Split [Include/floatobject.h](https://github.com/python/cpython/blob/main/Include/floatobject.h) into sub-files: add
      [Include/cpython/floatobject.h](https://github.com/python/cpython/blob/main/Include/cpython/floatobject.h) and
      [Include/internal/pycore_floatobject.h](https://github.com/python/cpython/blob/main/Include/internal/pycore_floatobject.h).
      
    8. vstinner commented on Mar 3, 2022

      @vstinner
      Member

      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.

    9. vstinner commented on Mar 11, 2022

      @vstinner
      Member

      New changeset 882d809 by Victor Stinner in branch 'main':
      bpo-46906: Add PyFloat_Pack8() to the C API (GH-31657)
      882d809

    10. vstinner commented on Mar 11, 2022

      @vstinner
      Member
    11. vstinner commented on Mar 12, 2022

      @vstinner
      Member

      PR for bitstruct: eerimoq/bitstruct#26

    12. vstinner commented on Mar 12, 2022

      @vstinner
      Member
    13. vstinner commented on Mar 14, 2022

      @vstinner
      Member

      New changeset 11c25b8 by Victor Stinner in branch 'main':
      bpo-46906: Mention native endian in PyFloat_Pack8() doc (GH-31866)
      11c25b8

    14. vstinner commented on Mar 14, 2022

      @vstinner
      Member

      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!

    15. transferred this issue fromon Apr 10, 2022
    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

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions