This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Add PyOS_string_to_double function to C API
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.1
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: eric.smith, mark.dickinson
Priority: normal Keywords: patch

Created on 2009-05-03 15:27 by mark.dickinson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
string_to_double.patch mark.dickinson, 2009-05-03 15:27
string_to_double_v2.patch mark.dickinson, 2009-05-03 17:45
Messages (5)
msg87048 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-05-03 15:27
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.
msg87049 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2009-05-03 15:36
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_*.
msg87055 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-05-03 17:45
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.
msg87057 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2009-05-03 18:32
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.
msg87068 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-05-03 20:36
Thanks.  I've committed a version of this patch, with Eric's suggested 
PyErr_Format change, in r72248.
Date User Action Args
2022-04-11 14:56:48adminsetgithub: 50164
2009-05-03 20:36:24mark.dickinsonsetstatus: open -> closed
resolution: accepted
messages: + msg87068

stage: patch review -> resolved
2009-05-03 18:32:27eric.smithsetmessages: + msg87057
2009-05-03 17:45:26mark.dickinsonsetfiles: + string_to_double_v2.patch

messages: + msg87055
2009-05-03 15:36:23eric.smithsetmessages: + msg87049
stage: patch review
2009-05-03 15:27:14mark.dickinsoncreate