Skip to content

Commit e9e7d28

Browse files
authored
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.
1 parent 45876a9 commit e9e7d28

File tree

13 files changed

+27
-12
lines changed

13 files changed

+27
-12
lines changed

Include/Python.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@
152152
#include "pyctype.h"
153153
#include "pystrtod.h"
154154
#include "pystrcmp.h"
155-
#include "dtoa.h"
156155
#include "fileutils.h"
157156
#include "pyfpe.h"
158157
#include "tracemalloc.h"
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
#ifndef Py_LIMITED_API
21
#ifndef PY_NO_SHORT_FLOAT_REPR
32
#ifdef __cplusplus
43
extern "C" {
54
#endif
65

6+
#ifndef Py_BUILD_CORE
7+
# error "this header requires Py_BUILD_CORE define"
8+
#endif
9+
10+
/* These functions are used by modules compiled as C extension like math:
11+
they must be exported. */
12+
713
PyAPI_FUNC(double) _Py_dg_strtod(const char *str, char **ptr);
814
PyAPI_FUNC(char *) _Py_dg_dtoa(double d, int mode, int ndigits,
915
int *decpt, int *sign, char **rve);
1016
PyAPI_FUNC(void) _Py_dg_freedtoa(char *s);
1117
PyAPI_FUNC(double) _Py_dg_stdnan(int sign);
1218
PyAPI_FUNC(double) _Py_dg_infinity(int sign);
1319

14-
1520
#ifdef __cplusplus
1621
}
1722
#endif
18-
#endif
19-
#endif
23+
#endif /* !PY_NO_SHORT_FLOAT_REPR */

Makefile.pre.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,6 @@ PYTHON_HEADERS= \
981981
$(srcdir)/Include/context.h \
982982
$(srcdir)/Include/descrobject.h \
983983
$(srcdir)/Include/dictobject.h \
984-
$(srcdir)/Include/dtoa.h \
985984
$(srcdir)/Include/dynamic_annotations.h \
986985
$(srcdir)/Include/enumobject.h \
987986
$(srcdir)/Include/errcode.h \
@@ -1082,6 +1081,7 @@ PYTHON_HEADERS= \
10821081
$(srcdir)/Include/internal/pycore_code.h \
10831082
$(srcdir)/Include/internal/pycore_condvar.h \
10841083
$(srcdir)/Include/internal/pycore_context.h \
1084+
$(srcdir)/Include/internal/pycore_dtoa.h \
10851085
$(srcdir)/Include/internal/pycore_fileutils.h \
10861086
$(srcdir)/Include/internal/pycore_getopt.h \
10871087
$(srcdir)/Include/internal/pycore_gil.h \
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Move the ``dtoa.h`` header file to the internal C API as ``pycore_dtoa.h``:
2+
it only contains private functions (prefixed by ``_Py``). The :mod:`math` and
3+
:mod:`cmath` modules must now be compiled with the ``Py_BUILD_CORE`` macro
4+
defined.
5+

Modules/Setup

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ _symtable symtablemodule.c
167167
# Modules that should always be present (non UNIX dependent):
168168

169169
#array arraymodule.c # array objects
170-
#cmath cmathmodule.c _math.c # -lm # complex math library functions
171-
#math mathmodule.c _math.c # -lm # math library functions, e.g. sin()
170+
#cmath cmathmodule.c _math.c -DPy_BUILD_CORE_MODULE # -lm # complex math library functions
171+
#math mathmodule.c _math.c -DPy_BUILD_CORE_MODULE # -lm # math library functions, e.g. sin()
172172
#_contextvars _contextvarsmodule.c # Context Variables
173173
#_struct _struct.c # binary structure packing/unpacking
174174
#_weakref _weakref.c # basic weak reference support

Modules/cmathmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/* much code borrowed from mathmodule.c */
44

55
#include "Python.h"
6+
#include "pycore_dtoa.h"
67
#include "_math.h"
78
/* we need DBL_MAX, DBL_MIN, DBL_EPSILON, DBL_MANT_DIG and FLT_RADIX from
89
float.h. We assume that FLT_RADIX is either 2 or 16. */

Modules/mathmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ raised for division by zero and mod by zero.
5353
*/
5454

5555
#include "Python.h"
56+
#include "pycore_dtoa.h"
5657
#include "_math.h"
5758

5859
#include "clinic/mathmodule.c.h"

Objects/floatobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
for any kind of float exception without losing portability. */
55

66
#include "Python.h"
7+
#include "pycore_dtoa.h"
78

89
#include <ctype.h>
910
#include <float.h>

PCbuild/pythoncore.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
<ClInclude Include="..\Include\internal\pycore_code.h" />
167167
<ClInclude Include="..\Include\internal\pycore_condvar.h" />
168168
<ClInclude Include="..\Include\internal\pycore_context.h" />
169+
<ClInclude Include="..\Include\internal\pycore_dtoa.h" />
169170
<ClInclude Include="..\Include\internal\pycore_fileutils.h" />
170171
<ClInclude Include="..\Include\internal\pycore_getopt.h" />
171172
<ClInclude Include="..\Include\internal\pycore_gil.h" />
@@ -223,7 +224,6 @@
223224
<ClInclude Include="..\Include\pystrcmp.h" />
224225
<ClInclude Include="..\Include\pystrtod.h" />
225226
<ClInclude Include="..\Include\pystrhex.h" />
226-
<ClInclude Include="..\Include\dtoa.h" />
227227
<ClInclude Include="..\Include\Python-ast.h" />
228228
<ClInclude Include="..\Include\Python.h" />
229229
<ClInclude Include="..\Include\pythonrun.h" />

PCbuild/pythoncore.vcxproj.filters

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@
201201
<ClInclude Include="..\Include\internal\pycore_context.h">
202202
<Filter>Include</Filter>
203203
</ClInclude>
204+
<ClInclude Include="..\Include\internal\pycore_dtoa.h">
205+
<Filter>Include</Filter>
206+
</ClInclude>
204207
<ClInclude Include="..\Include\internal\pycore_fileutils.h">
205208
<Filter>Include</Filter>
206209
</ClInclude>
@@ -360,9 +363,6 @@
360363
<ClInclude Include="..\Include\pystrhex.h">
361364
<Filter>Include</Filter>
362365
</ClInclude>
363-
<ClInclude Include="..\Include\dtoa.h">
364-
<Filter>Include</Filter>
365-
</ClInclude>
366366
<ClInclude Include="..\Include\Python-ast.h">
367367
<Filter>Include</Filter>
368368
</ClInclude>

0 commit comments

Comments
 (0)