Skip to content

Add a minimal decimal capsule API #85496

Closed

Description

@skrah
mannequin
BPO 41324
Nosy @rhettinger, @mdickinson, @pitrou, @dvarrazzo, @skrah, @mattip
PRs
  • bpo-41324 Add a minimal decimal capsule API #21519
  • 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 2020-08-10.14:34:29.785>
    created_at = <Date 2020-07-17.10:55:47.337>
    labels = ['expert-C-API', 'type-feature', '3.10']
    title = 'Add a minimal decimal capsule API'
    updated_at = <Date 2021-05-10.13:51:05.722>
    user = 'https://github.com/skrah'

    bugs.python.org fields:

    activity = <Date 2021-05-10.13:51:05.722>
    actor = 'piro'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-08-10.14:34:29.785>
    closer = 'skrah'
    components = ['C API']
    creation = <Date 2020-07-17.10:55:47.337>
    creator = 'skrah'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41324
    keywords = ['patch']
    message_count = 12.0
    messages = ['373823', '373829', '373831', '373842', '373910', '374012', '375121', '388134', '388233', '389244', '393395', '393396']
    nosy_count = 6.0
    nosy_names = ['rhettinger', 'mark.dickinson', 'pitrou', 'piro', 'skrah', 'mattip']
    pr_nums = ['21519']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue41324'
    versions = ['Python 3.10']

    Activity

    1. self-assigned this
      on Jul 17, 2020
    2. self-assigned this
      on Jul 17, 2020
    3. skrah commented on Jul 17, 2020

      skrahmannequin
      MannequinAuthor

      This adds a minimal decimal capsule API. As can be seen from the patch,
      adding anything to decimal while doing it properly is quite labor and
      testing intensive, so the intent is to *keep* the API minimal!

      That said, some functions are really necessary:

      1. PyDec_TypeCheck() -- for obvious reasons.

      2. PyDec_Alloc() -- create new decimals.

      3. PyDec_Get() -- get the mpd_t, enables the use of all libmpdec functions.

      4. PyDec_AsUint128Triple() -- export the decimal as (sign, hi, lo, exp).

      5. PyDec_FromUint128Triple() -- create a decimal from (sign, hi, lo, exp).

      6. and 5) have been requested by Antoine for a real world use case. (hi, lo)
        is the coefficient as a __uint128_t split in two uint64_t.

      Antoine, could you verify that this is sufficient for the database use case?

    4. skrah commented on Jul 17, 2020

      skrahmannequin
      MannequinAuthor

      Also as a note for Mark and Raymond: This API is for exact conversions
      and avoids the use of the context except for raising ConversionSyntax.

      I'll add documentation once Antoine has tried it out for his use case.

    5. skrah commented on Jul 17, 2020

      skrahmannequin
      MannequinAuthor

      Adding Daniele Varrazzo, in case this is useful for the PostgreSQL
      adapter.

    6. pitrou commented on Jul 17, 2020

      @pitrou
      Member

      I probably won't try it out explicitly (it's basically cumbersome for us to test with non-release Pythons, because of our dependencies to Numpy and Cython), but reviewing the API should be enough anyway.

    7. skrah commented on Jul 18, 2020

      skrahmannequin
      MannequinAuthor

      It looks like the API would be usable, so the PR now has documentation.

    8. changed the title [-]Add a minimal decimal capsule API[/-] [+]En az ondalık kapsül API ekleme[/+] on Jul 19, 2020
    9. changed the title [-]Add a minimal decimal capsule API[/-] [+]En az ondalık kapsül API ekleme[/+] on Jul 19, 2020
    10. 3 remaining items

    11. skrah commented on Aug 10, 2020

      skrahmannequin
      MannequinAuthor

      New changeset 39042e0 by Stefan Krah in branch 'master':
      bpo-41324 Add a minimal decimal capsule API (bpo-21519)
      39042e0

    12. mattip commented on Mar 4, 2021

      @mattip
      Contributor

      Was expanding the C-API discussed on the mailing list or in any wider forum? It seems vstinner is working hard to reduce the public API exposure while this issue + PR makes it even larger. Please reconsider putting this in for 3.10.

    13. pitrou commented on Mar 7, 2021

      @pitrou
      Member
    14. pitrou commented on Mar 21, 2021

      @pitrou
      Member

      For the record, this is going to be reverted at Stefan's request in bpo-43422.

    15. dvarrazzo commented on May 10, 2021

      dvarrazzomannequin
      Mannequin

      FYI, will try to use this API in psycopg3, which supports the PostgreSQL decimal binary format. Thank you very much: it seems exactly what needed.

      Binary conversion with Python Decimal currently has disappointing performances and is slower than the text format conversion. This is likely caused by the use of Decimal.as_tuple(), which creates tuples for the return value and the digits and requires Python calls to access their values.

      I have considered using libmpdec directly: personally I wouldn't be opposed to that, but the additional dependency on libmpdec-dev would earn the project no new fan :\

      Ref. psycopg/psycopg#54

    16. dvarrazzo commented on May 10, 2021

      dvarrazzomannequin
      Mannequin

      Ah, just noticed that this has been now reverted. Oh well, I'll see what to do then :(

    17. 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

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions