]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-35081: Move dtoa.h header to the internal C API (GH-18489)
authorVictor Stinner <vstinner@python.org>
Wed, 12 Feb 2020 21:54:42 +0000 (22:54 +0100)
committerGitHub <noreply@github.com>
Wed, 12 Feb 2020 21:54:42 +0000 (22:54 +0100)
Move the dtoa.h header file to the internal C API as pycore_dtoa.h:
it only contains private functions (prefixed by "_Py").

The math and cmath modules must now be compiled with the
Py_BUILD_CORE macro defined.

13 files changed:
Include/Python.h
Include/internal/pycore_dtoa.h [moved from Include/dtoa.h with 66% similarity]
Makefile.pre.in
Misc/NEWS.d/next/C API/2020-02-12-21-24-02.bpo-35081.at7BjN.rst [new file with mode: 0644]
Modules/Setup
Modules/cmathmodule.c
Modules/mathmodule.c
Objects/floatobject.c
PCbuild/pythoncore.vcxproj
PCbuild/pythoncore.vcxproj.filters
Python/dtoa.c
Python/pystrtod.c
setup.py

index d6e5b139ac67964e8457bfd57304157b0eabafb3..969d8e6bea7416646ee4bdba65aee1af24878119 100644 (file)
 #include "pyctype.h"
 #include "pystrtod.h"
 #include "pystrcmp.h"
-#include "dtoa.h"
 #include "fileutils.h"
 #include "pyfpe.h"
 #include "tracemalloc.h"
similarity index 66%
rename from Include/dtoa.h
rename to Include/internal/pycore_dtoa.h
index 9bfb6251db831c59579b157625e8a3fc492d1e77..3faf8cf6b2eefc7d7fe688e3df95c94a6ca52e85 100644 (file)
@@ -1,9 +1,15 @@
-#ifndef Py_LIMITED_API
 #ifndef PY_NO_SHORT_FLOAT_REPR
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#ifndef Py_BUILD_CORE
+#  error "this header requires Py_BUILD_CORE define"
+#endif
+
+/* These functions are used by modules compiled as C extension like math:
+   they must be exported. */
+
 PyAPI_FUNC(double) _Py_dg_strtod(const char *str, char **ptr);
 PyAPI_FUNC(char *) _Py_dg_dtoa(double d, int mode, int ndigits,
                         int *decpt, int *sign, char **rve);
@@ -11,9 +17,7 @@ PyAPI_FUNC(void) _Py_dg_freedtoa(char *s);
 PyAPI_FUNC(double) _Py_dg_stdnan(int sign);
 PyAPI_FUNC(double) _Py_dg_infinity(int sign);
 
-
 #ifdef __cplusplus
 }
 #endif
-#endif
-#endif
+#endif   /* !PY_NO_SHORT_FLOAT_REPR */
index aae93ff82c145f8925f7946c4b53b04ebc79de5f..f5540a2f0a6b4bb8da06d3efd98f76e7393458ab 100644 (file)
@@ -981,7 +981,6 @@ PYTHON_HEADERS= \
                $(srcdir)/Include/context.h \
                $(srcdir)/Include/descrobject.h \
                $(srcdir)/Include/dictobject.h \
-               $(srcdir)/Include/dtoa.h \
                $(srcdir)/Include/dynamic_annotations.h \
                $(srcdir)/Include/enumobject.h \
                $(srcdir)/Include/errcode.h \
@@ -1082,6 +1081,7 @@ PYTHON_HEADERS= \
                $(srcdir)/Include/internal/pycore_code.h \
                $(srcdir)/Include/internal/pycore_condvar.h \
                $(srcdir)/Include/internal/pycore_context.h \
+               $(srcdir)/Include/internal/pycore_dtoa.h \
                $(srcdir)/Include/internal/pycore_fileutils.h \
                $(srcdir)/Include/internal/pycore_getopt.h \
                $(srcdir)/Include/internal/pycore_gil.h \
diff --git a/Misc/NEWS.d/next/C API/2020-02-12-21-24-02.bpo-35081.at7BjN.rst b/Misc/NEWS.d/next/C API/2020-02-12-21-24-02.bpo-35081.at7BjN.rst
new file mode 100644 (file)
index 0000000..94e6ae7
--- /dev/null
@@ -0,0 +1,5 @@
+Move the ``dtoa.h`` header file to the internal C API as ``pycore_dtoa.h``:
+it only contains private functions (prefixed by ``_Py``). The :mod:`math` and
+:mod:`cmath` modules must now be compiled with the ``Py_BUILD_CORE`` macro
+defined.
+
index 983fa014ecb242bf8716a7ff997f56aaee6e913c..40266a192bc5e841d467f89b053105c3a6accbc9 100644 (file)
@@ -167,8 +167,8 @@ _symtable symtablemodule.c
 # Modules that should always be present (non UNIX dependent):
 
 #array arraymodule.c   # array objects
-#cmath cmathmodule.c _math.c # -lm # complex math library functions
-#math mathmodule.c _math.c # -lm # math library functions, e.g. sin()
+#cmath cmathmodule.c _math.c -DPy_BUILD_CORE_MODULE # -lm # complex math library functions
+#math mathmodule.c _math.c -DPy_BUILD_CORE_MODULE # -lm # math library functions, e.g. sin()
 #_contextvars _contextvarsmodule.c  # Context Variables
 #_struct _struct.c     # binary structure packing/unpacking
 #_weakref _weakref.c   # basic weak reference support
index 8b21decfa53fcc6088c421a6f0d0181c7624e5d0..5eac4b4940bea4dbb004097df4eababba35b58a6 100644 (file)
@@ -3,6 +3,7 @@
 /* much code borrowed from mathmodule.c */
 
 #include "Python.h"
+#include "pycore_dtoa.h"
 #include "_math.h"
 /* we need DBL_MAX, DBL_MIN, DBL_EPSILON, DBL_MANT_DIG and FLT_RADIX from
    float.h.  We assume that FLT_RADIX is either 2 or 16. */
index f012b51d86698d6767a30f27919b202d6ccd06d8..309f229159540125166be069ecefc3fa5a088eec 100644 (file)
@@ -53,6 +53,7 @@ raised for division by zero and mod by zero.
  */
 
 #include "Python.h"
+#include "pycore_dtoa.h"
 #include "_math.h"
 
 #include "clinic/mathmodule.c.h"
index 648030b659c233a47311fd45a4efeaae2d87f589..04f968e56b142761cd02f6ddfc72f791576b8b41 100644 (file)
@@ -4,6 +4,7 @@
    for any kind of float exception without losing portability. */
 
 #include "Python.h"
+#include "pycore_dtoa.h"
 
 #include <ctype.h>
 #include <float.h>
index a3719d8558de7f41c7ddd0546383cd894898482c..7d597bcdac6669791069b6ecb2c34263bf047292 100644 (file)
     <ClInclude Include="..\Include\internal\pycore_code.h" />
     <ClInclude Include="..\Include\internal\pycore_condvar.h" />
     <ClInclude Include="..\Include\internal\pycore_context.h" />
+    <ClInclude Include="..\Include\internal\pycore_dtoa.h" />
     <ClInclude Include="..\Include\internal\pycore_fileutils.h" />
     <ClInclude Include="..\Include\internal\pycore_getopt.h" />
     <ClInclude Include="..\Include\internal\pycore_gil.h" />
     <ClInclude Include="..\Include\pystrcmp.h" />
     <ClInclude Include="..\Include\pystrtod.h" />
     <ClInclude Include="..\Include\pystrhex.h" />
-    <ClInclude Include="..\Include\dtoa.h" />
     <ClInclude Include="..\Include\Python-ast.h" />
     <ClInclude Include="..\Include\Python.h" />
     <ClInclude Include="..\Include\pythonrun.h" />
index 67e223dab4396e05ba3c0876d42d3a4168a9c486..9563bdc25ebdbdf22a0347625791c653b2a53ded 100644 (file)
     <ClInclude Include="..\Include\internal\pycore_context.h">
       <Filter>Include</Filter>
     </ClInclude>
+    <ClInclude Include="..\Include\internal\pycore_dtoa.h">
+      <Filter>Include</Filter>
+    </ClInclude>
     <ClInclude Include="..\Include\internal\pycore_fileutils.h">
       <Filter>Include</Filter>
     </ClInclude>
     <ClInclude Include="..\Include\pystrhex.h">
       <Filter>Include</Filter>
     </ClInclude>
-    <ClInclude Include="..\Include\dtoa.h">
-      <Filter>Include</Filter>
-    </ClInclude>
     <ClInclude Include="..\Include\Python-ast.h">
       <Filter>Include</Filter>
     </ClInclude>
index b7bb7acfb6c215a46840d3c5696968c261f0225a..822adc612962a90f6bf1919aa8458c0072a1caea 100644 (file)
 /* Linking of Python's #defines to Gay's #defines starts here. */
 
 #include "Python.h"
+#include "pycore_dtoa.h"
 
 /* if PY_NO_SHORT_FLOAT_REPR is defined, then don't even try to compile
    the following code */
index 94dc4818c2f473d2e7a4ac8151fc63deb8efb317..1c8202c776188489ac835c6d0eab57a7e8d06286 100644 (file)
@@ -1,6 +1,7 @@
 /* -*- Mode: C; c-file-style: "python" -*- */
 
 #include <Python.h>
+#include "pycore_dtoa.h"
 #include <locale.h>
 
 /* Case-insensitive string match used for nan and inf detection; t should be
index 02f523c42d355f27b70b709b0723898d5f2cb721..51e67fe4a558b8ef29b5bbf59ac5e000cf527814 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -734,12 +734,14 @@ class PyBuildExt(build_ext):
 
         # math library functions, e.g. sin()
         self.add(Extension('math',  ['mathmodule.c'],
+                           extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
                            extra_objects=[shared_math],
                            depends=['_math.h', shared_math],
                            libraries=['m']))
 
         # complex math library functions
         self.add(Extension('cmath', ['cmathmodule.c'],
+                           extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
                            extra_objects=[shared_math],
                            depends=['_math.h', shared_math],
                            libraries=['m']))