Skip to content

Commit 68af50b

Browse files
committed
Issue #5988: Delete deprecated functions PyOS_ascii_formatd, PyOS_ascii_strtod, and PyOS_ascii_atof.
1 parent 9d2d327 commit 68af50b

File tree

6 files changed

+17
-171
lines changed

6 files changed

+17
-171
lines changed

Doc/c-api/conversion.rst

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,6 @@ The return value (*rv*) for these functions should be interpreted as follows:
5151
The following functions provide locale-independent string to number conversions.
5252

5353

54-
.. cfunction:: double PyOS_ascii_strtod(const char *nptr, char **endptr)
55-
56-
Convert a string to a :ctype:`double`. This function behaves like the Standard C
57-
function :cfunc:`strtod` does in the C locale. It does this without changing the
58-
current locale, since that would not be thread-safe.
59-
60-
:cfunc:`PyOS_ascii_strtod` should typically be used for reading configuration
61-
files or other non-user input that should be locale independent.
62-
63-
See the Unix man page :manpage:`strtod(2)` for details.
64-
65-
.. deprecated:: 3.1
66-
Use :cfunc:`PyOS_string_to_double` instead.
67-
68-
6954
.. cfunction:: double PyOS_string_to_double(const char *s, char **endptr, PyObject *overflow_exception)
7055

7156
Convert a string ``s`` to a :ctype:`double`, raising a Python
@@ -100,20 +85,6 @@ The following functions provide locale-independent string to number conversions.
10085
.. versionadded:: 3.1
10186

10287

103-
.. cfunction:: char* PyOS_ascii_formatd(char *buffer, size_t buf_len, const char *format, double d)
104-
105-
Convert a :ctype:`double` to a string using the ``'.'`` as the decimal
106-
separator. *format* is a :cfunc:`printf`\ -style format string specifying the
107-
number format. Allowed conversion characters are ``'e'``, ``'E'``, ``'f'``,
108-
``'F'``, ``'g'`` and ``'G'``.
109-
110-
The return value is a pointer to *buffer* with the converted string or NULL if
111-
the conversion failed.
112-
113-
.. deprecated:: 3.1
114-
Use :cfunc:`PyOS_double_to_string` instead.
115-
116-
11788
.. cfunction:: char* PyOS_double_to_string(double val, char format_code, int precision, int flags, int *ptype)
11889

11990
Convert a :ctype:`double` *val* to a string using supplied
@@ -148,16 +119,6 @@ The following functions provide locale-independent string to number conversions.
148119
.. versionadded:: 3.1
149120

150121

151-
.. cfunction:: double PyOS_ascii_atof(const char *nptr)
152-
153-
Convert a string to a :ctype:`double` in a locale-independent way.
154-
155-
See the Unix man page :manpage:`atof(2)` for details.
156-
157-
.. deprecated:: 3.1
158-
Use :cfunc:`PyOS_string_to_double` instead.
159-
160-
161122
.. cfunction:: char* PyOS_stricmp(char *s1, char *s2)
162123

163124
Case insensitive comparison of strings. The function works almost

Include/pystrtod.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ extern "C" {
66
#endif
77

88

9-
PyAPI_FUNC(double) PyOS_ascii_strtod(const char *str, char **ptr);
10-
PyAPI_FUNC(double) PyOS_ascii_atof(const char *str);
11-
PyAPI_FUNC(char *) PyOS_ascii_formatd(char *buffer, size_t buf_len, const char *format, double d);
129
PyAPI_FUNC(double) PyOS_string_to_double(const char *str,
1310
char **endptr,
1411
PyObject *overflow_exception);

Lib/test/test_ascii_formatd.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ What's New in Python 3.2 Alpha 1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #5988: Remove deprecated functions PyOS_ascii_formatd,
16+
PyOS_ascii_strtod, and PyOS_ascii_atof. Use PyOS_double_to_string
17+
and PyOS_string_to_double instead. See issue #5835 for the original
18+
deprecations.
19+
1520
- Issue #7385: Fix a crash in `MemoryView_FromObject` when
1621
`PyObject_GetBuffer` fails. Patch by Florent Xicluna.
1722

PC/os2emx/python27.def

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,11 +1048,6 @@ EXPORTS
10481048
"_PyThreadState_Current"
10491049
"_PyThreadState_GetFrame"
10501050

1051-
; From python26_s.lib(pystrtod)
1052-
"PyOS_ascii_strtod"
1053-
"PyOS_ascii_formatd"
1054-
"PyOS_ascii_atof"
1055-
10561051
; From python26_s.lib(pythonrun)
10571052
"Py_IgnoreEnvironmentFlag"
10581053
"Py_DebugFlag"

Python/pystrtod.c

Lines changed: 12 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ _Py_parse_inf_or_nan(const char *p, char **endptr)
5858
}
5959

6060
/**
61-
* PyOS_ascii_strtod:
61+
* _PyOS_ascii_strtod:
6262
* @nptr: the string to convert to a numeric value.
6363
* @endptr: if non-%NULL, it returns the character after
6464
* the last character used in the conversion.
@@ -88,7 +88,7 @@ _Py_parse_inf_or_nan(const char *p, char **endptr)
8888

8989
#ifndef PY_NO_SHORT_FLOAT_REPR
9090

91-
double
91+
static double
9292
_PyOS_ascii_strtod(const char *nptr, char **endptr)
9393
{
9494
double result;
@@ -121,7 +121,7 @@ _PyOS_ascii_strtod(const char *nptr, char **endptr)
121121
correctly rounded results.
122122
*/
123123

124-
double
124+
static double
125125
_PyOS_ascii_strtod(const char *nptr, char **endptr)
126126
{
127127
char *fail_pos;
@@ -270,48 +270,10 @@ _PyOS_ascii_strtod(const char *nptr, char **endptr)
270270

271271
#endif
272272

273-
/* PyOS_ascii_strtod is DEPRECATED in Python 3.1 */
274-
275-
double
276-
PyOS_ascii_strtod(const char *nptr, char **endptr)
277-
{
278-
char *fail_pos;
279-
const char *p;
280-
double x;
281-
282-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
283-
"PyOS_ascii_strtod and PyOS_ascii_atof are "
284-
"deprecated. Use PyOS_string_to_double "
285-
"instead.", 1) < 0)
286-
return -1.0;
287-
288-
/* _PyOS_ascii_strtod already does everything that we want,
289-
except that it doesn't parse leading whitespace */
290-
p = nptr;
291-
while (Py_ISSPACE(*p))
292-
p++;
293-
x = _PyOS_ascii_strtod(p, &fail_pos);
294-
if (fail_pos == p)
295-
fail_pos = (char *)nptr;
296-
if (endptr)
297-
*endptr = (char *)fail_pos;
298-
return x;
299-
}
300-
301-
/* PyOS_ascii_strtod is DEPRECATED in Python 3.1 */
302-
303-
double
304-
PyOS_ascii_atof(const char *nptr)
305-
{
306-
return PyOS_ascii_strtod(nptr, NULL);
307-
}
308-
309-
/* PyOS_string_to_double is the recommended replacement for the deprecated
310-
PyOS_ascii_strtod and PyOS_ascii_atof functions. It converts a
311-
null-terminated byte string s (interpreted as a string of ASCII characters)
312-
to a float. The string should not have leading or trailing whitespace (in
313-
contrast, PyOS_ascii_strtod allows leading whitespace but not trailing
314-
whitespace). The conversion is independent of the current locale.
273+
/* PyOS_string_to_double converts a null-terminated byte string s (interpreted
274+
as a string of ASCII characters) to a float. The string should not have
275+
leading or trailing whitespace. The conversion is independent of the
276+
current locale.
315277
316278
If endptr is NULL, try to convert the whole string. Raise ValueError and
317279
return -1.0 if the string is not a valid representation of a floating-point
@@ -369,6 +331,8 @@ PyOS_string_to_double(const char *s,
369331
return result;
370332
}
371333

334+
#ifdef PY_NO_SHORT_FLOAT_REPR
335+
372336
/* Given a string that may have a decimal point in the current
373337
locale, change it back to a dot. Since the string cannot get
374338
longer, no need for a maximum buffer size parameter. */
@@ -618,12 +582,13 @@ ensure_decimal_point(char* buffer, size_t buf_size, int precision)
618582
#define FLOAT_FORMATBUFLEN 120
619583

620584
/**
621-
* PyOS_ascii_formatd:
585+
* _PyOS_ascii_formatd:
622586
* @buffer: A buffer to place the resulting string in
623587
* @buf_size: The length of the buffer.
624588
* @format: The printf()-style format to use for the
625589
* code to use for converting.
626590
* @d: The #gdouble to convert
591+
* @precision: The precision to use when formatting.
627592
*
628593
* Converts a #gdouble to a string, using the '.' as
629594
* decimal point. To format the number you pass in
@@ -636,7 +601,7 @@ ensure_decimal_point(char* buffer, size_t buf_size, int precision)
636601
* Return value: The pointer to the buffer with the converted string.
637602
* On failure returns NULL but does not set any Python exception.
638603
**/
639-
char *
604+
static char *
640605
_PyOS_ascii_formatd(char *buffer,
641606
size_t buf_size,
642607
const char *format,
@@ -716,22 +681,6 @@ _PyOS_ascii_formatd(char *buffer,
716681
return buffer;
717682
}
718683

719-
char *
720-
PyOS_ascii_formatd(char *buffer,
721-
size_t buf_size,
722-
const char *format,
723-
double d)
724-
{
725-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
726-
"PyOS_ascii_formatd is deprecated, "
727-
"use PyOS_double_to_string instead", 1) < 0)
728-
return NULL;
729-
730-
return _PyOS_ascii_formatd(buffer, buf_size, format, d, -1);
731-
}
732-
733-
#ifdef PY_NO_SHORT_FLOAT_REPR
734-
735684
/* The fallback code to use if _Py_dg_dtoa is not available. */
736685

737686
PyAPI_FUNC(char *) PyOS_double_to_string(double val,

0 commit comments

Comments
 (0)