[Python-checkins] bpo-35134: Add Include/cpython/complexobject.h header (GH-32383)

vstinner webhook-mailer at python.org
Wed Apr 6 19:05:36 EDT 2022


https://github.com/python/cpython/commit/ca219f6dfc57f8f4984f96df0f733b7de92fe91c
commit: ca219f6dfc57f8f4984f96df0f733b7de92fe91c
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2022-04-07T01:05:27+02:00
summary:

bpo-35134: Add Include/cpython/complexobject.h header (GH-32383)

Move the private _PyComplex_FormatAdvancedWriter() function to the
internal C API. This function is no longer exported.

files:
A Include/cpython/complexobject.h
M Include/complexobject.h
M Makefile.pre.in
M PCbuild/pythoncore.vcxproj
M PCbuild/pythoncore.vcxproj.filters

diff --git a/Include/complexobject.h b/Include/complexobject.h
index 9221f9c51d65b..c7764e43803d6 100644
--- a/Include/complexobject.h
+++ b/Include/complexobject.h
@@ -6,61 +6,22 @@
 extern "C" {
 #endif
 
-#ifndef Py_LIMITED_API
-typedef struct {
-    double real;
-    double imag;
-} Py_complex;
-
-/* Operations on complex numbers from complexmodule.c */
-
-PyAPI_FUNC(Py_complex) _Py_c_sum(Py_complex, Py_complex);
-PyAPI_FUNC(Py_complex) _Py_c_diff(Py_complex, Py_complex);
-PyAPI_FUNC(Py_complex) _Py_c_neg(Py_complex);
-PyAPI_FUNC(Py_complex) _Py_c_prod(Py_complex, Py_complex);
-PyAPI_FUNC(Py_complex) _Py_c_quot(Py_complex, Py_complex);
-PyAPI_FUNC(Py_complex) _Py_c_pow(Py_complex, Py_complex);
-PyAPI_FUNC(double) _Py_c_abs(Py_complex);
-#endif
-
 /* Complex object interface */
 
-/*
-PyComplexObject represents a complex number with double-precision
-real and imaginary parts.
-*/
-#ifndef Py_LIMITED_API
-typedef struct {
-    PyObject_HEAD
-    Py_complex cval;
-} PyComplexObject;
-#endif
-
 PyAPI_DATA(PyTypeObject) PyComplex_Type;
 
 #define PyComplex_Check(op) PyObject_TypeCheck(op, &PyComplex_Type)
 #define PyComplex_CheckExact(op) Py_IS_TYPE(op, &PyComplex_Type)
 
-#ifndef Py_LIMITED_API
-PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex);
-#endif
 PyAPI_FUNC(PyObject *) PyComplex_FromDoubles(double real, double imag);
 
 PyAPI_FUNC(double) PyComplex_RealAsDouble(PyObject *op);
 PyAPI_FUNC(double) PyComplex_ImagAsDouble(PyObject *op);
-#ifndef Py_LIMITED_API
-PyAPI_FUNC(Py_complex) PyComplex_AsCComplex(PyObject *op);
-#endif
 
-/* Format the object based on the format_spec, as defined in PEP 3101
-   (Advanced String Formatting). */
 #ifndef Py_LIMITED_API
-PyAPI_FUNC(int) _PyComplex_FormatAdvancedWriter(
-    _PyUnicodeWriter *writer,
-    PyObject *obj,
-    PyObject *format_spec,
-    Py_ssize_t start,
-    Py_ssize_t end);
+#  define Py_CPYTHON_COMPLEXOBJECT_H
+#  include "cpython/complexobject.h"
+#  undef Py_CPYTHON_COMPLEXOBJECT_H
 #endif
 
 #ifdef __cplusplus
diff --git a/Include/cpython/complexobject.h b/Include/cpython/complexobject.h
new file mode 100644
index 0000000000000..b7d7283ae8896
--- /dev/null
+++ b/Include/cpython/complexobject.h
@@ -0,0 +1,44 @@
+#ifndef Py_CPYTHON_COMPLEXOBJECT_H
+#  error "this header file must not be included directly"
+#endif
+
+typedef struct {
+    double real;
+    double imag;
+} Py_complex;
+
+/* Operations on complex numbers from complexmodule.c */
+
+PyAPI_FUNC(Py_complex) _Py_c_sum(Py_complex, Py_complex);
+PyAPI_FUNC(Py_complex) _Py_c_diff(Py_complex, Py_complex);
+PyAPI_FUNC(Py_complex) _Py_c_neg(Py_complex);
+PyAPI_FUNC(Py_complex) _Py_c_prod(Py_complex, Py_complex);
+PyAPI_FUNC(Py_complex) _Py_c_quot(Py_complex, Py_complex);
+PyAPI_FUNC(Py_complex) _Py_c_pow(Py_complex, Py_complex);
+PyAPI_FUNC(double) _Py_c_abs(Py_complex);
+
+/* Complex object interface */
+
+/*
+PyComplexObject represents a complex number with double-precision
+real and imaginary parts.
+*/
+typedef struct {
+    PyObject_HEAD
+    Py_complex cval;
+} PyComplexObject;
+
+PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex);
+
+PyAPI_FUNC(Py_complex) PyComplex_AsCComplex(PyObject *op);
+
+#ifdef Py_BUILD_CORE
+/* Format the object based on the format_spec, as defined in PEP 3101
+   (Advanced String Formatting). */
+extern int _PyComplex_FormatAdvancedWriter(
+    _PyUnicodeWriter *writer,
+    PyObject *obj,
+    PyObject *format_spec,
+    Py_ssize_t start,
+    Py_ssize_t end);
+#endif  // Py_BUILD_CORE
diff --git a/Makefile.pre.in b/Makefile.pre.in
index d9b96f52ec9f7..69e97234ae737 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1522,6 +1522,7 @@ PYTHON_HEADERS= \
 		$(srcdir)/Include/cpython/classobject.h \
 		$(srcdir)/Include/cpython/code.h \
 		$(srcdir)/Include/cpython/compile.h \
+		$(srcdir)/Include/cpython/complexobject.h \
 		$(srcdir)/Include/cpython/context.h \
 		$(srcdir)/Include/cpython/descrobject.h \
 		$(srcdir)/Include/cpython/dictobject.h \
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index 4fc6aa80f6fae..1d7c08b2c8a71 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -141,6 +141,7 @@
     <ClInclude Include="..\Include\cpython\classobject.h" />
     <ClInclude Include="..\Include\cpython\code.h" />
     <ClInclude Include="..\Include\cpython\compile.h" />
+    <ClInclude Include="..\Include\cpython\complexobject.h" />
     <ClInclude Include="..\Include\cpython\context.h" />
     <ClInclude Include="..\Include\cpython\descrobject.h" />
     <ClInclude Include="..\Include\cpython\dictobject.h" />
diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters
index 55fca4982e0f3..571a7f13bc1a0 100644
--- a/PCbuild/pythoncore.vcxproj.filters
+++ b/PCbuild/pythoncore.vcxproj.filters
@@ -357,6 +357,9 @@
     <ClInclude Include="..\Include\cpython\compile.h">
       <Filter>Include</Filter>
     </ClInclude>
+    <ClInclude Include="..\Include\cpython\complexobject.h">
+      <Filter>Include</Filter>
+    </ClInclude>
     <ClInclude Include="..\Include\cpython\context.h">
       <Filter>Include\cpython</Filter>
     </ClInclude>



More information about the Python-checkins mailing list