Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PyOS_string_to_double function to C API #50164

Closed
mdickinson opened this issue May 3, 2009 · 5 comments
Closed

Add PyOS_string_to_double function to C API #50164

mdickinson opened this issue May 3, 2009 · 5 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@mdickinson
Copy link
Member

BPO 5914
Nosy @mdickinson, @ericvsmith
Files
  • string_to_double.patch
  • string_to_double_v2.patch
  • 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 = 'https://github.com/mdickinson'
    closed_at = <Date 2009-05-03.20:36:24.613>
    created_at = <Date 2009-05-03.15:27:14.613>
    labels = ['interpreter-core', 'type-feature']
    title = 'Add PyOS_string_to_double function to C API'
    updated_at = <Date 2009-05-03.20:36:24.611>
    user = 'https://github.com/mdickinson'
    

    bugs.python.org fields:

    activity = <Date 2009-05-03.20:36:24.611>
    actor = 'mark.dickinson'
    assignee = 'mark.dickinson'
    closed = True
    closed_date = <Date 2009-05-03.20:36:24.613>
    closer = 'mark.dickinson'
    components = ['Interpreter Core']
    creation = <Date 2009-05-03.15:27:14.613>
    creator = 'mark.dickinson'
    dependencies = []
    files = ['13852', '13853']
    hgrepos = []
    issue_num = 5914
    keywords = ['patch']
    message_count = 5.0
    messages = ['87048', '87049', '87055', '87057', '87068']
    nosy_count = 2.0
    nosy_names = ['mark.dickinson', 'eric.smith']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue5914'
    versions = ['Python 3.1']
    

    @mdickinson
    Copy link
    Member Author

    Here's a patch that adds a PyOS_string_to_double function to complement
    the recently added PyOS_double_to_string function.

    This is supposed to be a more Pythonic version of PyOS_ascii_strtod. It
    raises Python exceptions to correspond to the various possible errors
    (malformed string, overflowing number, malloc failure...) instead of
    requiring the caller to examine errno.

    It's intended for both internal and external use; if this goes in, I
    intend to use it in the Python core in places where PyOS_ascii_strtod or
    PyOS_ascii_atof are currently used.

    @mdickinson mdickinson self-assigned this May 3, 2009
    @mdickinson mdickinson added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels May 3, 2009
    @ericvsmith
    Copy link
    Member

    This looks okay to me (although since it's not hooked up I haven't
    tested it). I particularly like that it doesn't allow leading
    whitespace, and that the caller no longer has to remember errno
    (forgetting to set and/or test it have both caused me problems in the past).

    Does the whitespace change cause any problems for any internal code? I
    wouldn't think so, but I haven't looked at it.

    As long as you're at it, I'd suggest deprecating PyOS_ascii_*.

    @mdickinson
    Copy link
    Member Author

    Thanks for the feedback!

    Here's an updated patch that also deprecates PyOS_ascii_strtod and
    PyOS_ascii_atof and hooks up PyOS_string_to_double everywhere. The
    documentation still needs proper markup, and I'll add some C-API tests.

    @ericvsmith
    Copy link
    Member

    This looks okay to me, and passes the tests.

    In PyOS_string_to_double, you can simplify it by using PyErr_Format
    instead of printing into a buffer and using PyErr_SetString. Sorry I
    didn't catch this earlier.

    @mdickinson
    Copy link
    Member Author

    Thanks. I've committed a version of this patch, with Eric's suggested
    PyErr_Format change, in r72248.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants