]> granicus.if.org Git - python/commitdiff
Issue #5988: Delete deprecated functions PyOS_ascii_formatd, PyOS_ascii_strtod, and...
authorEric Smith <eric@trueblade.com>
Mon, 22 Feb 2010 14:58:30 +0000 (14:58 +0000)
committerEric Smith <eric@trueblade.com>
Mon, 22 Feb 2010 14:58:30 +0000 (14:58 +0000)
Doc/c-api/conversion.rst
Include/pystrtod.h
Lib/test/test_ascii_formatd.py [deleted file]
Misc/NEWS
PC/os2emx/python27.def
Python/pystrtod.c

index ad3f2fa16b45ea96db593665fdfc9fd606f97886..e5f83ff84f1cafaf2ac86c4bf7ccfe30e65402a6 100644 (file)
@@ -51,21 +51,6 @@ The return value (*rv*) for these functions should be interpreted as follows:
 The following functions provide locale-independent string to number conversions.
 
 
-.. cfunction:: double PyOS_ascii_strtod(const char *nptr, char **endptr)
-
-   Convert a string to a :ctype:`double`. This function behaves like the Standard C
-   function :cfunc:`strtod` does in the C locale. It does this without changing the
-   current locale, since that would not be thread-safe.
-
-   :cfunc:`PyOS_ascii_strtod` should typically be used for reading configuration
-   files or other non-user input that should be locale independent.
-
-   See the Unix man page :manpage:`strtod(2)` for details.
-
-   .. deprecated:: 3.1
-      Use :cfunc:`PyOS_string_to_double` instead.
-
-
 .. cfunction:: double PyOS_string_to_double(const char *s, char **endptr, PyObject *overflow_exception)
 
    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.
    .. versionadded:: 3.1
 
 
-.. cfunction:: char* PyOS_ascii_formatd(char *buffer, size_t buf_len, const char *format, double d)
-
-   Convert a :ctype:`double` to a string using the ``'.'`` as the decimal
-   separator. *format* is a :cfunc:`printf`\ -style format string specifying the
-   number format. Allowed conversion characters are ``'e'``, ``'E'``, ``'f'``,
-   ``'F'``, ``'g'`` and ``'G'``.
-
-   The return value is a pointer to *buffer* with the converted string or NULL if
-   the conversion failed.
-
-   .. deprecated:: 3.1
-     Use :cfunc:`PyOS_double_to_string` instead.
-
-
 .. cfunction:: char* PyOS_double_to_string(double val, char format_code, int precision, int flags, int *ptype)
 
    Convert a :ctype:`double` *val* to a string using supplied
@@ -148,16 +119,6 @@ The following functions provide locale-independent string to number conversions.
    .. versionadded:: 3.1
 
 
-.. cfunction:: double PyOS_ascii_atof(const char *nptr)
-
-   Convert a string to a :ctype:`double` in a locale-independent way.
-
-   See the Unix man page :manpage:`atof(2)` for details.
-
-   .. deprecated:: 3.1
-      Use :cfunc:`PyOS_string_to_double` instead.
-
-
 .. cfunction:: char* PyOS_stricmp(char *s1, char *s2)
 
    Case insensitive comparison of strings. The function works almost
index b1d8786e509d6959940b06d8f2e83f95fa53c758..d7bae122343f813b1a0100f40a075eec2e9736df 100644 (file)
@@ -6,9 +6,6 @@ extern "C" {
 #endif
 
 
-PyAPI_FUNC(double) PyOS_ascii_strtod(const char *str, char **ptr);
-PyAPI_FUNC(double) PyOS_ascii_atof(const char *str);
-PyAPI_FUNC(char *) PyOS_ascii_formatd(char *buffer, size_t buf_len,  const char *format, double d);
 PyAPI_FUNC(double) PyOS_string_to_double(const char *str,
                                          char **endptr,
                                          PyObject *overflow_exception);
diff --git a/Lib/test/test_ascii_formatd.py b/Lib/test/test_ascii_formatd.py
deleted file mode 100644 (file)
index f61bc85..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-# PyOS_ascii_formatd is deprecated and not called from anywhere in
-#  Python itself. So this module is the only place it gets tested.
-# Test that it works, and test that it's deprecated.
-
-import unittest
-from test.support import check_warnings, run_unittest, cpython_only
-
-class FormatDeprecationTests(unittest.TestCase):
-
-    @cpython_only
-    def testFormatDeprecation(self):
-        # delay importing ctypes until we know we're in CPython
-        from ctypes import (pythonapi, create_string_buffer, sizeof, byref,
-                            c_double)
-        PyOS_ascii_formatd = pythonapi.PyOS_ascii_formatd
-        buf = create_string_buffer(100)
-
-        with check_warnings() as w:
-            PyOS_ascii_formatd(byref(buf), sizeof(buf), b'%+.10f',
-                               c_double(10.0))
-            self.assertEqual(buf.value, b'+10.0000000000')
-
-        self.assertEqual(w.category, DeprecationWarning)
-
-class FormatTests(unittest.TestCase):
-    # ensure that, for the restricted set of format codes,
-    # %-formatting returns the same values os PyOS_ascii_formatd
-    @cpython_only
-    def testFormat(self):
-        # delay importing ctypes until we know we're in CPython
-        from ctypes import (pythonapi, create_string_buffer, sizeof, byref,
-                            c_double)
-        PyOS_ascii_formatd = pythonapi.PyOS_ascii_formatd
-        buf = create_string_buffer(100)
-
-        tests = [
-            ('%f', 100.0),
-            ('%g', 100.0),
-            ('%#g', 100.0),
-            ('%#.2g', 100.0),
-            ('%#.2g', 123.4567),
-            ('%#.2g', 1.234567e200),
-            ('%e', 1.234567e200),
-            ('%e', 1.234),
-            ('%+e', 1.234),
-            ('%-e', 1.234),
-            ]
-
-        with check_warnings():
-            for format, val in tests:
-                PyOS_ascii_formatd(byref(buf), sizeof(buf),
-                                   bytes(format, 'ascii'),
-                                   c_double(val))
-                self.assertEqual(buf.value, bytes(format % val, 'ascii'))
-
-
-def test_main():
-    run_unittest(FormatDeprecationTests, FormatTests)
-
-if __name__ == '__main__':
-    test_main()
index 67a93008d91a0c4d0ca9f7ae5f24fdffea08bb85..021b31a05fb766b4255691d232d980fa86d53c6f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,11 @@ What's New in Python 3.2 Alpha 1?
 Core and Builtins
 -----------------
 
+- Issue #5988: Remove deprecated functions PyOS_ascii_formatd,
+  PyOS_ascii_strtod, and PyOS_ascii_atof. Use PyOS_double_to_string
+  and PyOS_string_to_double instead. See issue #5835 for the original
+  deprecations.
+
 - Issue #7385: Fix a crash in `MemoryView_FromObject` when
   `PyObject_GetBuffer` fails.  Patch by Florent Xicluna.
 
index 0776ced1c87bf9dfad5d725f3883de4a3bc14070..7d05ec3835a62c660df97e0bf0e866ead583c778 100644 (file)
@@ -1048,11 +1048,6 @@ EXPORTS
   "_PyThreadState_Current"
   "_PyThreadState_GetFrame"
 
-; From python26_s.lib(pystrtod)
-  "PyOS_ascii_strtod"
-  "PyOS_ascii_formatd"
-  "PyOS_ascii_atof"
-
 ; From python26_s.lib(pythonrun)
   "Py_IgnoreEnvironmentFlag"
   "Py_DebugFlag"
index 5543c58b5a97edefd948d9df937d22fc13aa4eca..a1d7ff09fcbd45d72535a6516f0353ee288615e6 100644 (file)
@@ -58,7 +58,7 @@ _Py_parse_inf_or_nan(const char *p, char **endptr)
 }
 
 /**
- * PyOS_ascii_strtod:
+ * _PyOS_ascii_strtod:
  * @nptr:    the string to convert to a numeric value.
  * @endptr:  if non-%NULL, it returns the character after
  *           the last character used in the conversion.
@@ -88,7 +88,7 @@ _Py_parse_inf_or_nan(const char *p, char **endptr)
 
 #ifndef PY_NO_SHORT_FLOAT_REPR
 
-double
+static double
 _PyOS_ascii_strtod(const char *nptr, char **endptr)
 {
        double result;
@@ -121,7 +121,7 @@ _PyOS_ascii_strtod(const char *nptr, char **endptr)
    correctly rounded results.
 */
 
-double
+static double
 _PyOS_ascii_strtod(const char *nptr, char **endptr)
 {
        char *fail_pos;
@@ -270,48 +270,10 @@ _PyOS_ascii_strtod(const char *nptr, char **endptr)
 
 #endif
 
-/* PyOS_ascii_strtod is DEPRECATED in Python 3.1 */
-
-double
-PyOS_ascii_strtod(const char *nptr, char **endptr)
-{
-       char *fail_pos;
-       const char *p;
-       double x;
-
-       if (PyErr_WarnEx(PyExc_DeprecationWarning,
-                        "PyOS_ascii_strtod and PyOS_ascii_atof are "
-                        "deprecated.  Use PyOS_string_to_double "
-                        "instead.", 1) < 0)
-               return -1.0;
-
-       /* _PyOS_ascii_strtod already does everything that we want,
-          except that it doesn't parse leading whitespace */
-       p = nptr;
-       while (Py_ISSPACE(*p))
-               p++;
-       x = _PyOS_ascii_strtod(p, &fail_pos);
-       if (fail_pos == p)
-               fail_pos = (char *)nptr;
-       if (endptr)
-               *endptr = (char *)fail_pos;
-       return x;
-}
-
-/* PyOS_ascii_strtod is DEPRECATED in Python 3.1 */
-
-double
-PyOS_ascii_atof(const char *nptr)
-{
-       return PyOS_ascii_strtod(nptr, NULL);
-}
-
-/* PyOS_string_to_double is the recommended replacement for the deprecated
-   PyOS_ascii_strtod and PyOS_ascii_atof functions.  It converts a
-   null-terminated byte string s (interpreted as a string of ASCII characters)
-   to a float.  The string should not have leading or trailing whitespace (in
-   contrast, PyOS_ascii_strtod allows leading whitespace but not trailing
-   whitespace).  The conversion is independent of the current locale.
+/* PyOS_string_to_double converts a null-terminated byte string s (interpreted
+   as a string of ASCII characters) to a float.  The string should not have
+   leading or trailing whitespace.  The conversion is independent of the
+   current locale.
 
    If endptr is NULL, try to convert the whole string.  Raise ValueError and
    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,
        return result;
 }
 
+#ifdef PY_NO_SHORT_FLOAT_REPR
+
 /* Given a string that may have a decimal point in the current
    locale, change it back to a dot.  Since the string cannot get
    longer, no need for a maximum buffer size parameter. */
@@ -618,12 +582,13 @@ ensure_decimal_point(char* buffer, size_t buf_size, int precision)
 #define FLOAT_FORMATBUFLEN 120
 
 /**
- * PyOS_ascii_formatd:
+ * _PyOS_ascii_formatd:
  * @buffer: A buffer to place the resulting string in
  * @buf_size: The length of the buffer.
  * @format: The printf()-style format to use for the
  *          code to use for converting. 
  * @d: The #gdouble to convert
+ * @precision: The precision to use when formatting.
  *
  * Converts a #gdouble to a string, using the '.' as
  * decimal point. To format the number you pass in
@@ -636,7 +601,7 @@ ensure_decimal_point(char* buffer, size_t buf_size, int precision)
  * Return value: The pointer to the buffer with the converted string.
  * On failure returns NULL but does not set any Python exception.
  **/
-char *
+static char *
 _PyOS_ascii_formatd(char       *buffer, 
                   size_t      buf_size, 
                   const char *format, 
@@ -716,22 +681,6 @@ _PyOS_ascii_formatd(char       *buffer,
        return buffer;
 }
 
-char *
-PyOS_ascii_formatd(char       *buffer, 
-                  size_t      buf_size, 
-                  const char *format, 
-                  double      d)
-{
-       if (PyErr_WarnEx(PyExc_DeprecationWarning,
-                        "PyOS_ascii_formatd is deprecated, "
-                        "use PyOS_double_to_string instead", 1) < 0)
-               return NULL;
-
-       return _PyOS_ascii_formatd(buffer, buf_size, format, d, -1);
-}
-
-#ifdef PY_NO_SHORT_FLOAT_REPR
-
 /* The fallback code to use if _Py_dg_dtoa is not available. */
 
 PyAPI_FUNC(char *) PyOS_double_to_string(double val,