Commit 1ff3958
gh-NNNN: Route string→float through _Py_fast_float_strtod
Swap the two in-tree _Py_dg_strtod call sites (pystrtod.c's
_PyOS_ascii_strtod and floatobject.c's double_round) for
_Py_fast_float_strtod. The new shim wraps fast_float::from_chars under
the _Py_dg_strtod calling convention.
fast_float's default `general` chars_format rejects leading '+' and
inf/nan literals. Enable:
* allow_leading_plus — _Py_dg_strtod accepts "+3.14"; so does C
strtod and test_float_with_comma's assertions depend on it.
Leave in place (not enabled):
* skip_white_space — _Py_dg_strtod did not skip whitespace and the
test_capi test_string_to_double asserts that " 0.1" raises
ValueError. Higher-level callers (PyFloat_FromString) strip
whitespace before the strtod call.
* no_infnan stays ON so pystrtod.c's _Py_parse_inf_or_nan fallback
keeps ownership of "inf"/"infinity"/"nan" literal parsing and
continues to produce bit-identical results on those inputs.
Overflow and underflow map cleanly: fast_float returns
`std::errc::result_out_of_range` in both cases, populating `value`
with +/-inf on overflow and the nearest representable value on
underflow; the shim translates that to errno = ERANGE.
Python/dtoa.c is now completely unreachable from the rest of the
tree — commit 8 removes it. The full float-formatting + strtod +
C-API regression suite (1,501 tests across test_float, test_strtod,
test_format, test_capi) passes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 8433b87 commit 1ff3958
3 files changed
Lines changed: 7 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
940 | 940 | | |
941 | 941 | | |
942 | 942 | | |
943 | | - | |
| 943 | + | |
944 | 944 | | |
945 | 945 | | |
946 | 946 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
43 | 46 | | |
44 | 47 | | |
45 | 48 | | |
| 49 | + | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
0 commit comments