[Python-checkins] bpo-35081: Move dtoa.h header to the internal C API (GH-18489)

Victor Stinner webhook-mailer at python.org
Wed Feb 12 16:54:53 EST 2020


https://github.com/python/cpython/commit/e9e7d284c434768333fdfb53a3663eae74cb995a
commit: e9e7d284c434768333fdfb53a3663eae74cb995a
branch: master
author: Victor Stinner <vstinner at python.org>
committer: GitHub <noreply at github.com>
date: 2020年02月12日T22:54:42+01:00
summary:
bpo-35081: Move dtoa.h header to the internal C API (GH-18489)
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.
files:
A Include/internal/pycore_dtoa.h
A Misc/NEWS.d/next/C API/2020-02-12-21-24-02.bpo-35081.at7BjN.rst
D Include/dtoa.h
M Include/Python.h
M Makefile.pre.in
M Modules/Setup
M Modules/cmathmodule.c
M Modules/mathmodule.c
M Objects/floatobject.c
M PCbuild/pythoncore.vcxproj
M PCbuild/pythoncore.vcxproj.filters
M Python/dtoa.c
M Python/pystrtod.c
M setup.py
diff --git a/Include/Python.h b/Include/Python.h
index d6e5b139ac679..969d8e6bea741 100644
--- a/Include/Python.h
+++ b/Include/Python.h
@@ -152,7 +152,6 @@
 #include "pyctype.h"
 #include "pystrtod.h"
 #include "pystrcmp.h"
-#include "dtoa.h"
 #include "fileutils.h"
 #include "pyfpe.h"
 #include "tracemalloc.h"
diff --git a/Include/dtoa.h b/Include/internal/pycore_dtoa.h
similarity index 66%
rename from Include/dtoa.h
rename to Include/internal/pycore_dtoa.h
index 9bfb6251db831..3faf8cf6b2eef 100644
--- a/Include/dtoa.h
+++ b/Include/internal/pycore_dtoa.h
@@ -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 */
diff --git a/Makefile.pre.in b/Makefile.pre.in
index aae93ff82c145..f5540a2f0a6b4 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -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
index 0000000000000..94e6ae7e42cc8
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2020-02-12-21-24-02.bpo-35081.at7BjN.rst	
@@ -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.
+
diff --git a/Modules/Setup b/Modules/Setup
index 983fa014ecb24..40266a192bc5e 100644
--- a/Modules/Setup
+++ b/Modules/Setup
@@ -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
diff --git a/Modules/cmathmodule.c b/Modules/cmathmodule.c
index 8b21decfa53fc..5eac4b4940bea 100644
--- a/Modules/cmathmodule.c
+++ b/Modules/cmathmodule.c
@@ -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. */
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index f012b51d86698..309f229159540 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -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"
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 648030b659c23..04f968e56b142 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -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>
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index a3719d8558de7..7d597bcdac666 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -166,6 +166,7 @@
 <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" />
@@ -223,7 +224,6 @@
 <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" />
diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters
index 67e223dab4396..9563bdc25ebdb 100644
--- a/PCbuild/pythoncore.vcxproj.filters
+++ b/PCbuild/pythoncore.vcxproj.filters
@@ -201,6 +201,9 @@
 <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>
@@ -360,9 +363,6 @@
 <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>
diff --git a/Python/dtoa.c b/Python/dtoa.c
index b7bb7acfb6c21..822adc612962a 100644
--- a/Python/dtoa.c
+++ b/Python/dtoa.c
@@ -115,6 +115,7 @@
 /* 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 */
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index 94dc4818c2f47..1c8202c776188 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -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
diff --git a/setup.py b/setup.py
index 02f523c42d355..51e67fe4a558b 100644
--- a/setup.py
+++ b/setup.py
@@ -734,12 +734,14 @@ def detect_simple_extensions(self):
 
 # 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']))


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /