bpo-45412: Add _PY_SHORT_FLOAT_REPR macro (GH-31171)

Remove the HAVE_PY_SET_53BIT_PRECISION macro (moved to the internal
C API).

* Move HAVE_PY_SET_53BIT_PRECISION macro to pycore_pymath.h.
* Replace PY_NO_SHORT_FLOAT_REPR macro with _PY_SHORT_FLOAT_REPR
  macro which is always defined. gcc -Wundef emits a warning when
  using _PY_SHORT_FLOAT_REPR but the macro is not defined, if
  pycore_pymath.h include was forgotten.
This commit is contained in:
Victor Stinner 2022-02-23 18:16:23 +01:00 committed by GitHub
parent 375a56bd40
commit 9bbdde2180
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 104 additions and 96 deletions

View file

@ -1,8 +1,8 @@
/* -*- Mode: C; c-file-style: "python" -*- */
#include <Python.h>
#include "pycore_dtoa.h"
#include "pycore_pymath.h" // _Py_SET_53BIT_PRECISION_START
#include "pycore_dtoa.h" // _Py_dg_strtod()
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
#include <locale.h>
/* Case-insensitive string match used for nan and inf detection; t should be
@ -24,7 +24,7 @@ case_insensitive_match(const char *s, const char *t)
the successfully parsed portion of the string. On failure, return -1.0 and
set *endptr to point to the start of the string. */
#ifndef PY_NO_SHORT_FLOAT_REPR
#if _PY_SHORT_FLOAT_REPR == 1
double
_Py_parse_inf_or_nan(const char *p, char **endptr)
@ -127,7 +127,7 @@ _Py_parse_inf_or_nan(const char *p, char **endptr)
* Return value: the #gdouble value.
**/
#ifndef PY_NO_SHORT_FLOAT_REPR
#if _PY_SHORT_FLOAT_REPR == 1
static double
_PyOS_ascii_strtod(const char *nptr, char **endptr)
@ -441,7 +441,7 @@ _Py_string_to_number_with_underscores(
return NULL;
}
#ifdef PY_NO_SHORT_FLOAT_REPR
#if _PY_SHORT_FLOAT_REPR == 0
/* Given a string that may have a decimal point in the current
locale, change it back to a dot. Since the string cannot get
@ -942,7 +942,7 @@ char * PyOS_double_to_string(double val,
return buf;
}
#else
#else // _PY_SHORT_FLOAT_REPR == 1
/* _Py_dg_dtoa is available. */
@ -1305,4 +1305,4 @@ char * PyOS_double_to_string(double val,
flags & Py_DTSF_ALT,
float_strings, type);
}
#endif /* ifdef PY_NO_SHORT_FLOAT_REPR */
#endif // _PY_SHORT_FLOAT_REPR == 1