From b057f99445221ef9ca4828e21426e46d346d3dee Mon Sep 17 00:00:00 2001 From: shivnaren Date: Fri, 15 Oct 2021 03:50:20 +0530 Subject: [PATCH 01/18] bpo-45442: Add deactivate step to venv tutorial. --- Doc/tutorial/venv.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/tutorial/venv.rst b/Doc/tutorial/venv.rst index 221c11ca74b4ef..68921790c42aa6 100644 --- a/Doc/tutorial/venv.rst +++ b/Doc/tutorial/venv.rst @@ -88,6 +88,9 @@ For example: '~/envs/tutorial-env/lib/python3.5/site-packages'] >>> +To deactivate a virtual environment, type:: + deactivate +into the terminal. This is a shell function defined by the script when the virtual environment is activated. Managing Packages with pip ========================== From 11150a4a94e653c1fc27cc49d91a3d41820affcb Mon Sep 17 00:00:00 2001 From: srinivasan Date: Fri, 15 Oct 2021 15:18:23 +0530 Subject: [PATCH 02/18] bpo-45442: Fix indentation/syntax error Co-authored-by: Pradyun Gedam --- Doc/tutorial/venv.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/tutorial/venv.rst b/Doc/tutorial/venv.rst index 68921790c42aa6..ab4813f411d4e1 100644 --- a/Doc/tutorial/venv.rst +++ b/Doc/tutorial/venv.rst @@ -89,7 +89,8 @@ For example: >>> To deactivate a virtual environment, type:: - deactivate + + deactivate into the terminal. This is a shell function defined by the script when the virtual environment is activated. Managing Packages with pip From 8813d6af96467117919d442b6908c24823492bbe Mon Sep 17 00:00:00 2001 From: shivnaren Date: Fri, 15 Oct 2021 19:30:00 +0530 Subject: [PATCH 03/18] bpo-45442: Remove explanation of implementation detail. --- Doc/tutorial/venv.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/venv.rst b/Doc/tutorial/venv.rst index ab4813f411d4e1..221961c4f41377 100644 --- a/Doc/tutorial/venv.rst +++ b/Doc/tutorial/venv.rst @@ -91,7 +91,7 @@ For example: To deactivate a virtual environment, type:: deactivate -into the terminal. This is a shell function defined by the script when the virtual environment is activated. +into the terminal. Managing Packages with pip ========================== From dcff25ad48dd00de2661b15d14c37b7a0b660a03 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Oct 2021 00:20:33 +0200 Subject: [PATCH 04/18] bpo-45474: Fix the limited C API of marshal.h (GH-28956) Remove two functions from the limited C API: * PyMarshal_WriteLongToFile() * PyMarshal_WriteObjectToFile() The PEP 384 excludes functions expecting "FILE*" from the stable ABI. Remove also the Py_MARSHAL_VERSION macro from the limited C API. --- Doc/whatsnew/3.11.rst | 10 ++++++++++ Include/marshal.h | 13 +++++++------ .../C API/2021-10-14-22-16-56.bpo-45474.1OkJQh.rst | 10 ++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 Misc/NEWS.d/next/C API/2021-10-14-22-16-56.bpo-45474.1OkJQh.rst diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 48d454d9aac99f..e8d64a80a69a36 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -613,3 +613,13 @@ Removed * Remove the ``Py_FORCE_DOUBLE()`` macro. It was used by the ``Py_IS_INFINITY()`` macro. (Contributed by Victor Stinner in :issue:`45440`.) + +* Remove two functions from the limited C API: + + * :c:func:`PyMarshal_WriteLongToFile` + * :c:func:`PyMarshal_WriteObjectToFile` + + The :pep:`384` excludes functions expecting ``FILE*`` from the stable ABI. + + Remove also the ``Py_MARSHAL_VERSION`` macro from the limited C API. + (Contributed by Victor Stinner in :issue:`45474`.) diff --git a/Include/marshal.h b/Include/marshal.h index 09d9337e57b0aa..36ef6a779ec2c6 100644 --- a/Include/marshal.h +++ b/Include/marshal.h @@ -7,20 +7,21 @@ extern "C" { #endif -#define Py_MARSHAL_VERSION 4 - -PyAPI_FUNC(void) PyMarshal_WriteLongToFile(long, FILE *, int); -PyAPI_FUNC(void) PyMarshal_WriteObjectToFile(PyObject *, FILE *, int); +PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(const char *, + Py_ssize_t); PyAPI_FUNC(PyObject *) PyMarshal_WriteObjectToString(PyObject *, int); #ifndef Py_LIMITED_API +#define Py_MARSHAL_VERSION 4 + PyAPI_FUNC(long) PyMarshal_ReadLongFromFile(FILE *); PyAPI_FUNC(int) PyMarshal_ReadShortFromFile(FILE *); PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromFile(FILE *); PyAPI_FUNC(PyObject *) PyMarshal_ReadLastObjectFromFile(FILE *); + +PyAPI_FUNC(void) PyMarshal_WriteLongToFile(long, FILE *, int); +PyAPI_FUNC(void) PyMarshal_WriteObjectToFile(PyObject *, FILE *, int); #endif -PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(const char *, - Py_ssize_t); #ifdef __cplusplus } diff --git a/Misc/NEWS.d/next/C API/2021-10-14-22-16-56.bpo-45474.1OkJQh.rst b/Misc/NEWS.d/next/C API/2021-10-14-22-16-56.bpo-45474.1OkJQh.rst new file mode 100644 index 00000000000000..90bf498579c11a --- /dev/null +++ b/Misc/NEWS.d/next/C API/2021-10-14-22-16-56.bpo-45474.1OkJQh.rst @@ -0,0 +1,10 @@ +Remove two functions from the limited C API: + +* :c:func:`PyMarshal_WriteLongToFile` +* :c:func:`PyMarshal_WriteObjectToFile` + +The :pep:`384` excludes functions expecting ``FILE*`` from the stable ABI. + +Remove also the ``Py_MARSHAL_VERSION`` macro from the limited C API. + +Patch by Victor Stinner. From e64410ba7f25093d3900e554783ebcfb33f0694f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Oct 2021 01:09:06 +0200 Subject: [PATCH 05/18] bpo-45434: Limited Python.h no longer includes stdio.h (GH-28960) The header file no longer includes if the Py_LIMITED_API macro is defined. --- Doc/whatsnew/3.11.rst | 7 +++++++ Include/Python.h | 11 ++++------- .../C API/2021-10-15-00-30-45.bpo-45434.XLtsbK.rst | 5 +++++ 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 Misc/NEWS.d/next/C API/2021-10-15-00-30-45.bpo-45434.XLtsbK.rst diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index e8d64a80a69a36..a6e30c77c55a0d 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -565,6 +565,13 @@ Porting to Python 3.11 ``exit()`` and ``abort()``. (Contributed by Victor Stinner in :issue:`45434`.) +* The ```` header file no longer includes ```` if the + ``Py_LIMITED_API`` macro is defined. Functions expecting ``FILE*`` are + excluded from the limited C API (:pep:`384`). C extensions using + ```` must now include it explicitly. The system ```` + header provides functions like ``printf()`` and ``fopen()``. + (Contributed by Victor Stinner in :issue:`45434`.) + Deprecated ---------- diff --git a/Include/Python.h b/Include/Python.h index 4f62103e30276c..dc5c9b8e6384e8 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -16,12 +16,10 @@ # define _SGI_MP_SOURCE #endif -#include // NULL, FILE* -#ifndef NULL -# error "Python.h requires that stdio.h define NULL." -#endif - #include // memcpy() +#ifndef Py_LIMITED_API +# include // FILE* +#endif #ifdef HAVE_ERRNO_H # include // errno #endif @@ -29,8 +27,7 @@ # include #endif #ifdef HAVE_STDDEF_H - // For size_t -# include +# include // size_t #endif #include // assert() diff --git a/Misc/NEWS.d/next/C API/2021-10-15-00-30-45.bpo-45434.XLtsbK.rst b/Misc/NEWS.d/next/C API/2021-10-15-00-30-45.bpo-45434.XLtsbK.rst new file mode 100644 index 00000000000000..4a06635d179d9b --- /dev/null +++ b/Misc/NEWS.d/next/C API/2021-10-15-00-30-45.bpo-45434.XLtsbK.rst @@ -0,0 +1,5 @@ +The ```` header file no longer includes ```` if the +``Py_LIMITED_API`` macro is defined. Functions expecting ``FILE*`` are excluded +from the limited C API (:pep:`384`). C extensions using ```` must now +include it explicitly. +Patch by Victor Stinner. From 46c18f2cca71390871538c4764578aae3741b8d9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Oct 2021 01:49:32 +0200 Subject: [PATCH 06/18] bpo-41710: Fix What's New Entry credit (GH-28962) Fix bad copy/paste. --- Doc/whatsnew/3.11.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index a6e30c77c55a0d..0647774f400d69 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -252,7 +252,7 @@ threading the monotonic clock (:data:`time.CLOCK_MONOTONIC`) for the timeout, rather than using the system clock (:data:`time.CLOCK_REALTIME`), to not be affected by system clock changes. - (Contributed by Livius and Victor Stinner in :issue:`41710`.) + (Contributed by Victor Stinner in :issue:`41710`.) time ---- From 5c8be2b64c5d4e46b1ab25fbee997706a5e268bd Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Oct 2021 01:50:04 +0200 Subject: [PATCH 07/18] bpo-45434: Remove useless space in includes (GH-28963) Micro-optimize spaces! --- Include/abstract.h | 2 +- Include/bytearrayobject.h | 2 +- Include/bytesobject.h | 2 +- Include/ceval.h | 2 +- Include/code.h | 2 +- Include/dictobject.h | 2 +- Include/fileobject.h | 2 +- Include/fileutils.h | 2 +- Include/frameobject.h | 2 +- Include/import.h | 2 +- Include/interpreteridobject.h | 2 +- Include/listobject.h | 2 +- Include/methodobject.h | 8 +++----- Include/object.h | 2 +- Include/objimpl.h | 2 +- Include/pyerrors.h | 2 +- Include/pylifecycle.h | 2 +- Include/pymem.h | 2 +- Include/pystate.h | 2 +- Include/pythonrun.h | 2 +- Include/sysmodule.h | 2 +- Include/traceback.h | 2 +- Include/tupleobject.h | 2 +- Include/unicodeobject.h | 2 +- 24 files changed, 26 insertions(+), 28 deletions(-) diff --git a/Include/abstract.h b/Include/abstract.h index 9eaab6b2e054c4..9e06fbbb749138 100644 --- a/Include/abstract.h +++ b/Include/abstract.h @@ -863,7 +863,7 @@ PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass); #ifndef Py_LIMITED_API # define Py_CPYTHON_ABSTRACTOBJECT_H -# include "cpython/abstract.h" +# include "cpython/abstract.h" # undef Py_CPYTHON_ABSTRACTOBJECT_H #endif diff --git a/Include/bytearrayobject.h b/Include/bytearrayobject.h index 1a834474dde7c3..ae2bde1c303565 100644 --- a/Include/bytearrayobject.h +++ b/Include/bytearrayobject.h @@ -34,7 +34,7 @@ PyAPI_FUNC(int) PyByteArray_Resize(PyObject *, Py_ssize_t); #ifndef Py_LIMITED_API # define Py_CPYTHON_BYTEARRAYOBJECT_H -# include "cpython/bytearrayobject.h" +# include "cpython/bytearrayobject.h" # undef Py_CPYTHON_BYTEARRAYOBJECT_H #endif diff --git a/Include/bytesobject.h b/Include/bytesobject.h index bcb1a5942c68f8..4c4dc40d705d71 100644 --- a/Include/bytesobject.h +++ b/Include/bytesobject.h @@ -59,7 +59,7 @@ PyAPI_FUNC(int) PyBytes_AsStringAndSize( #ifndef Py_LIMITED_API # define Py_CPYTHON_BYTESOBJECT_H -# include "cpython/bytesobject.h" +# include "cpython/bytesobject.h" # undef Py_CPYTHON_BYTESOBJECT_H #endif diff --git a/Include/ceval.h b/Include/ceval.h index 0f687666e2bccf..cf8c5b17be589a 100644 --- a/Include/ceval.h +++ b/Include/ceval.h @@ -148,7 +148,7 @@ PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate); #ifndef Py_LIMITED_API # define Py_CPYTHON_CEVAL_H -# include "cpython/ceval.h" +# include "cpython/ceval.h" # undef Py_CPYTHON_CEVAL_H #endif diff --git a/Include/code.h b/Include/code.h index b9e23eb816529b..2dea3c26105318 100644 --- a/Include/code.h +++ b/Include/code.h @@ -10,7 +10,7 @@ typedef struct PyCodeObject PyCodeObject; #ifndef Py_LIMITED_API # define Py_CPYTHON_CODE_H -# include "cpython/code.h" +# include "cpython/code.h" # undef Py_CPYTHON_CODE_H #endif diff --git a/Include/dictobject.h b/Include/dictobject.h index da5a36ba07f32e..a6233d8ae2512a 100644 --- a/Include/dictobject.h +++ b/Include/dictobject.h @@ -87,7 +87,7 @@ PyAPI_DATA(PyTypeObject) PyDictRevIterValue_Type; #ifndef Py_LIMITED_API # define Py_CPYTHON_DICTOBJECT_H -# include "cpython/dictobject.h" +# include "cpython/dictobject.h" # undef Py_CPYTHON_DICTOBJECT_H #endif diff --git a/Include/fileobject.h b/Include/fileobject.h index 6ec2994aa859b6..4c983e7b5daa8a 100644 --- a/Include/fileobject.h +++ b/Include/fileobject.h @@ -39,7 +39,7 @@ PyAPI_DATA(int) Py_UTF8Mode; #ifndef Py_LIMITED_API # define Py_CPYTHON_FILEOBJECT_H -# include "cpython/fileobject.h" +# include "cpython/fileobject.h" # undef Py_CPYTHON_FILEOBJECT_H #endif diff --git a/Include/fileutils.h b/Include/fileutils.h index 16f3b635deed89..ba5acc84fcb185 100644 --- a/Include/fileutils.h +++ b/Include/fileutils.h @@ -16,7 +16,7 @@ PyAPI_FUNC(char*) Py_EncodeLocale( #ifndef Py_LIMITED_API # define Py_CPYTHON_FILEUTILS_H -# include "cpython/fileutils.h" +# include "cpython/fileutils.h" # undef Py_CPYTHON_FILEUTILS_H #endif diff --git a/Include/frameobject.h b/Include/frameobject.h index c118af1201a4c8..adb628f6314fcf 100644 --- a/Include/frameobject.h +++ b/Include/frameobject.h @@ -10,7 +10,7 @@ extern "C" { #ifndef Py_LIMITED_API # define Py_CPYTHON_FRAMEOBJECT_H -# include "cpython/frameobject.h" +# include "cpython/frameobject.h" # undef Py_CPYTHON_FRAMEOBJECT_H #endif diff --git a/Include/import.h b/Include/import.h index aeef3efd0bcee8..a87677bb10c7f4 100644 --- a/Include/import.h +++ b/Include/import.h @@ -88,7 +88,7 @@ PyAPI_FUNC(int) PyImport_AppendInittab( #ifndef Py_LIMITED_API # define Py_CPYTHON_IMPORT_H -# include "cpython/import.h" +# include "cpython/import.h" # undef Py_CPYTHON_IMPORT_H #endif diff --git a/Include/interpreteridobject.h b/Include/interpreteridobject.h index e744fcdc9ff189..8432632f339e92 100644 --- a/Include/interpreteridobject.h +++ b/Include/interpreteridobject.h @@ -7,7 +7,7 @@ extern "C" { #ifndef Py_LIMITED_API # define Py_CPYTHON_INTERPRETERIDOBJECT_H -# include "cpython/interpreteridobject.h" +# include "cpython/interpreteridobject.h" # undef Py_CPYTHON_INTERPRETERIDOBJECT_H #endif diff --git a/Include/listobject.h b/Include/listobject.h index 2a8a25525d1d7b..eff42c188f1ff1 100644 --- a/Include/listobject.h +++ b/Include/listobject.h @@ -42,7 +42,7 @@ PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *); #ifndef Py_LIMITED_API # define Py_CPYTHON_LISTOBJECT_H -# include "cpython/listobject.h" +# include "cpython/listobject.h" # undef Py_CPYTHON_LISTOBJECT_H #endif diff --git a/Include/methodobject.h b/Include/methodobject.h index 9ffe8e1a3ddfcb..1be5873a30569f 100644 --- a/Include/methodobject.h +++ b/Include/methodobject.h @@ -103,11 +103,9 @@ PyAPI_FUNC(PyObject *) PyCMethod_New(PyMethodDef *, PyObject *, #ifndef Py_LIMITED_API - -#define Py_CPYTHON_METHODOBJECT_H -#include "cpython/methodobject.h" -#undef Py_CPYTHON_METHODOBJECT_H - +# define Py_CPYTHON_METHODOBJECT_H +# include "cpython/methodobject.h" +# undef Py_CPYTHON_METHODOBJECT_H #endif #ifdef __cplusplus diff --git a/Include/object.h b/Include/object.h index 7f050b80aaff1c..33df303a44eb7e 100644 --- a/Include/object.h +++ b/Include/object.h @@ -724,7 +724,7 @@ times. #ifndef Py_LIMITED_API # define Py_CPYTHON_OBJECT_H -# include "cpython/object.h" +# include "cpython/object.h" # undef Py_CPYTHON_OBJECT_H #endif diff --git a/Include/objimpl.h b/Include/objimpl.h index 450befad679e70..9b98c112ac2cc5 100644 --- a/Include/objimpl.h +++ b/Include/objimpl.h @@ -205,7 +205,7 @@ PyAPI_FUNC(int) PyObject_GC_IsFinalized(PyObject *); #ifndef Py_LIMITED_API # define Py_CPYTHON_OBJIMPL_H -# include "cpython/objimpl.h" +# include "cpython/objimpl.h" # undef Py_CPYTHON_OBJIMPL_H #endif diff --git a/Include/pyerrors.h b/Include/pyerrors.h index f5d1c711577186..c6c443a2d7d0f0 100644 --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -314,7 +314,7 @@ PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_l #ifndef Py_LIMITED_API # define Py_CPYTHON_ERRORS_H -# include "cpython/pyerrors.h" +# include "cpython/pyerrors.h" # undef Py_CPYTHON_ERRORS_H #endif diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h index 9b2dd0868eb25b..4aecda235abf76 100644 --- a/Include/pylifecycle.h +++ b/Include/pylifecycle.h @@ -64,7 +64,7 @@ PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t); #ifndef Py_LIMITED_API # define Py_CPYTHON_PYLIFECYCLE_H -# include "cpython/pylifecycle.h" +# include "cpython/pylifecycle.h" # undef Py_CPYTHON_PYLIFECYCLE_H #endif diff --git a/Include/pymem.h b/Include/pymem.h index 66cdb0d2973cd0..c15ad10dfcf831 100644 --- a/Include/pymem.h +++ b/Include/pymem.h @@ -93,7 +93,7 @@ PyAPI_FUNC(void) PyMem_Free(void *ptr); #ifndef Py_LIMITED_API # define Py_CPYTHON_PYMEM_H -# include "cpython/pymem.h" +# include "cpython/pymem.h" # undef Py_CPYTHON_PYMEM_H #endif diff --git a/Include/pystate.h b/Include/pystate.h index d81f42a3efe321..b6ee0ede81dea0 100644 --- a/Include/pystate.h +++ b/Include/pystate.h @@ -132,7 +132,7 @@ PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void); #ifndef Py_LIMITED_API # define Py_CPYTHON_PYSTATE_H -# include "cpython/pystate.h" +# include "cpython/pystate.h" # undef Py_CPYTHON_PYSTATE_H #endif diff --git a/Include/pythonrun.h b/Include/pythonrun.h index b0a2fc3002d37d..02715775581c63 100644 --- a/Include/pythonrun.h +++ b/Include/pythonrun.h @@ -34,7 +34,7 @@ PyAPI_FUNC(int) PyOS_CheckStack(void); #ifndef Py_LIMITED_API # define Py_CPYTHON_PYTHONRUN_H -# include "cpython/pythonrun.h" +# include "cpython/pythonrun.h" # undef Py_CPYTHON_PYTHONRUN_H #endif diff --git a/Include/sysmodule.h b/Include/sysmodule.h index 8c8f7c425942a5..3463c622309009 100644 --- a/Include/sysmodule.h +++ b/Include/sysmodule.h @@ -31,7 +31,7 @@ PyAPI_FUNC(PyObject *) PySys_GetXOptions(void); #ifndef Py_LIMITED_API # define Py_CPYTHON_SYSMODULE_H -# include "cpython/sysmodule.h" +# include "cpython/sysmodule.h" # undef Py_CPYTHON_SYSMODULE_H #endif diff --git a/Include/traceback.h b/Include/traceback.h index 781e5a6eec4edd..2dfa2ada4f2c37 100644 --- a/Include/traceback.h +++ b/Include/traceback.h @@ -16,7 +16,7 @@ PyAPI_DATA(PyTypeObject) PyTraceBack_Type; #ifndef Py_LIMITED_API # define Py_CPYTHON_TRACEBACK_H -# include "cpython/traceback.h" +# include "cpython/traceback.h" # undef Py_CPYTHON_TRACEBACK_H #endif diff --git a/Include/tupleobject.h b/Include/tupleobject.h index e796a320192c20..dc68e3fc5c6d88 100644 --- a/Include/tupleobject.h +++ b/Include/tupleobject.h @@ -36,7 +36,7 @@ PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...); #ifndef Py_LIMITED_API # define Py_CPYTHON_TUPLEOBJECT_H -# include "cpython/tupleobject.h" +# include "cpython/tupleobject.h" # undef Py_CPYTHON_TUPLEOBJECT_H #endif diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index c65b9228298d76..abce967caff78e 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -1043,7 +1043,7 @@ PyAPI_FUNC(int) PyUnicode_IsIdentifier(PyObject *s); #ifndef Py_LIMITED_API # define Py_CPYTHON_UNICODEOBJECT_H -# include "cpython/unicodeobject.h" +# include "cpython/unicodeobject.h" # undef Py_CPYTHON_UNICODEOBJECT_H #endif From 37e1a68c6595619929335c48005ee72814030fe9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Oct 2021 01:50:28 +0200 Subject: [PATCH 08/18] po-35134: Move Include/funcobject.h to Include/cpython/ (GH-28958) Remove redundant "#ifndef Py_LIMITED_API" in funcobject.h. --- Doc/whatsnew/3.11.rst | 6 ++++++ Include/Python.h | 2 +- Include/{ => cpython}/funcobject.h | 4 +--- Makefile.pre.in | 2 +- .../next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst | 3 +++ PCbuild/pythoncore.vcxproj | 2 +- PCbuild/pythoncore.vcxproj.filters | 6 +++--- Tools/scripts/stable_abi.py | 1 - 8 files changed, 16 insertions(+), 10 deletions(-) rename Include/{ => cpython}/funcobject.h (99%) create mode 100644 Misc/NEWS.d/next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 0647774f400d69..a45568392fbf9f 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -572,6 +572,12 @@ Porting to Python 3.11 header provides functions like ``printf()`` and ``fopen()``. (Contributed by Victor Stinner in :issue:`45434`.) +* The non-limited API file ``funcobject.h`` has been moved to the + ``Include/cpython`` directory. This file must not be included directly, as it + is already included in ``Python.h``: :ref:`Include Files `. If + it has been included directly, consider including ``Python.h`` instead. + (Contributed by Victor Stinner in :issue:`35134`.) + Deprecated ---------- diff --git a/Include/Python.h b/Include/Python.h index dc5c9b8e6384e8..e8e061bdf62e87 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -60,7 +60,7 @@ #include "setobject.h" #include "methodobject.h" #include "moduleobject.h" -#include "funcobject.h" +#include "cpython/funcobject.h" #include "classobject.h" #include "fileobject.h" #include "pycapsule.h" diff --git a/Include/funcobject.h b/Include/cpython/funcobject.h similarity index 99% rename from Include/funcobject.h rename to Include/cpython/funcobject.h index 6bc03f57d4cb39..60b702218a1f40 100644 --- a/Include/funcobject.h +++ b/Include/cpython/funcobject.h @@ -1,5 +1,5 @@ - /* Function object interface */ + #ifndef Py_LIMITED_API #ifndef Py_FUNCOBJECT_H #define Py_FUNCOBJECT_H @@ -76,7 +76,6 @@ PyAPI_FUNC(int) PyFunction_SetClosure(PyObject *, PyObject *); PyAPI_FUNC(PyObject *) PyFunction_GetAnnotations(PyObject *); PyAPI_FUNC(int) PyFunction_SetAnnotations(PyObject *, PyObject *); -#ifndef Py_LIMITED_API PyAPI_FUNC(PyObject *) _PyFunction_Vectorcall( PyObject *func, PyObject *const *stack, @@ -84,7 +83,6 @@ PyAPI_FUNC(PyObject *) _PyFunction_Vectorcall( PyObject *kwnames); uint32_t _PyFunction_GetVersionForCurrentState(PyFunctionObject *func); -#endif /* Macros for direct access to these values. Type checks are *not* done, so use with care. */ diff --git a/Makefile.pre.in b/Makefile.pre.in index 30b025e7efb839..a5585c8de8ad01 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1145,7 +1145,6 @@ PYTHON_HEADERS= \ $(srcdir)/Include/fileutils.h \ $(srcdir)/Include/floatobject.h \ $(srcdir)/Include/frameobject.h \ - $(srcdir)/Include/funcobject.h \ $(srcdir)/Include/genobject.h \ $(srcdir)/Include/import.h \ $(srcdir)/Include/interpreteridobject.h \ @@ -1210,6 +1209,7 @@ PYTHON_HEADERS= \ $(srcdir)/Include/cpython/fileutils.h \ $(srcdir)/Include/cpython/floatobject.h \ $(srcdir)/Include/cpython/frameobject.h \ + $(srcdir)/Include/cpython/funcobject.h \ $(srcdir)/Include/cpython/import.h \ $(srcdir)/Include/cpython/initconfig.h \ $(srcdir)/Include/cpython/interpreteridobject.h \ diff --git a/Misc/NEWS.d/next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst b/Misc/NEWS.d/next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst new file mode 100644 index 00000000000000..fc12e02b0c580e --- /dev/null +++ b/Misc/NEWS.d/next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst @@ -0,0 +1,3 @@ +Move Include/funcobject.h header file to Include/cpython/funcobject.h. +C extensions should only include the main ```` header. +Patch by Victor Stinner. diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index f688e8a3232451..dc216e34855df2 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -134,6 +134,7 @@ + @@ -169,7 +170,6 @@ - diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index eb72c38a7b2038..8eeb38871f327e 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -108,9 +108,6 @@ Include - - Include - Include @@ -456,6 +453,9 @@ Include\cpython + + Include\cpython + Include\cpython diff --git a/Tools/scripts/stable_abi.py b/Tools/scripts/stable_abi.py index 6d7034090f8819..6cb310e5a31d5a 100755 --- a/Tools/scripts/stable_abi.py +++ b/Tools/scripts/stable_abi.py @@ -34,7 +34,6 @@ "datetime.h", "dtoa.h", "frameobject.h", - "funcobject.h", "genobject.h", "longintrepr.h", "parsetok.h", From 96805ce55a17a91289e23c56b1e1a1e24e904248 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Oct 2021 02:39:58 +0200 Subject: [PATCH 09/18] bpo-35134: Move Include/cellobject.h to Include/cpython/ (GH-28964) --- Doc/whatsnew/3.11.rst | 9 +++++---- Include/Python.h | 2 +- Include/{ => cpython}/cellobject.h | 4 +++- Makefile.pre.in | 2 +- .../next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst | 6 +++--- PCbuild/pythoncore.vcxproj | 2 +- PCbuild/pythoncore.vcxproj.filters | 6 +++--- 7 files changed, 17 insertions(+), 14 deletions(-) rename Include/{ => cpython}/cellobject.h (89%) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index a45568392fbf9f..734cf1572fcba4 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -572,10 +572,11 @@ Porting to Python 3.11 header provides functions like ``printf()`` and ``fopen()``. (Contributed by Victor Stinner in :issue:`45434`.) -* The non-limited API file ``funcobject.h`` has been moved to the - ``Include/cpython`` directory. This file must not be included directly, as it - is already included in ``Python.h``: :ref:`Include Files `. If - it has been included directly, consider including ``Python.h`` instead. +* The non-limited API files ``cellobject.h`` and ``funcobject.h`` have been + moved to the ``Include/cpython`` directory. These files must not be included + directly, as they are already included in ``Python.h``: :ref:`Include Files + `. If they have been included directly, consider including + ``Python.h`` instead. (Contributed by Victor Stinner in :issue:`35134`.) Deprecated diff --git a/Include/Python.h b/Include/Python.h index e8e061bdf62e87..89f60fe5c9f945 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -68,7 +68,7 @@ #include "pyframe.h" #include "traceback.h" #include "sliceobject.h" -#include "cellobject.h" +#include "cpython/cellobject.h" #include "iterobject.h" #include "genobject.h" #include "descrobject.h" diff --git a/Include/cellobject.h b/Include/cpython/cellobject.h similarity index 89% rename from Include/cellobject.h rename to Include/cpython/cellobject.h index 81bc784d36f3e0..8dc7b8f4cf6f88 100644 --- a/Include/cellobject.h +++ b/Include/cpython/cellobject.h @@ -1,4 +1,5 @@ /* Cell object interface */ + #ifndef Py_LIMITED_API #ifndef Py_CELLOBJECT_H #define Py_CELLOBJECT_H @@ -8,7 +9,8 @@ extern "C" { typedef struct { PyObject_HEAD - PyObject *ob_ref; /* Content of the cell or NULL when empty */ + /* Content of the cell or NULL when empty */ + PyObject *ob_ref; } PyCellObject; PyAPI_DATA(PyTypeObject) PyCell_Type; diff --git a/Makefile.pre.in b/Makefile.pre.in index a5585c8de8ad01..32bbab068f7027 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1127,7 +1127,6 @@ PYTHON_HEADERS= \ $(srcdir)/Include/boolobject.h \ $(srcdir)/Include/bytearrayobject.h \ $(srcdir)/Include/bytesobject.h \ - $(srcdir)/Include/cellobject.h \ $(srcdir)/Include/ceval.h \ $(srcdir)/Include/classobject.h \ $(srcdir)/Include/code.h \ @@ -1201,6 +1200,7 @@ PYTHON_HEADERS= \ $(srcdir)/Include/cpython/abstract.h \ $(srcdir)/Include/cpython/bytearrayobject.h \ $(srcdir)/Include/cpython/bytesobject.h \ + $(srcdir)/Include/cpython/cellobject.h \ $(srcdir)/Include/cpython/ceval.h \ $(srcdir)/Include/cpython/code.h \ $(srcdir)/Include/cpython/compile.h \ diff --git a/Misc/NEWS.d/next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst b/Misc/NEWS.d/next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst index fc12e02b0c580e..800f6e7f927410 100644 --- a/Misc/NEWS.d/next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst +++ b/Misc/NEWS.d/next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst @@ -1,3 +1,3 @@ -Move Include/funcobject.h header file to Include/cpython/funcobject.h. -C extensions should only include the main ```` header. -Patch by Victor Stinner. +Move ``cellobject.h`` and ``funcobject.h`` header files from ``Include/`` to +``Include/cpython/``. C extensions should only include the main ```` +header. Patch by Victor Stinner. diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index dc216e34855df2..877064e877debe 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -115,7 +115,6 @@ - @@ -126,6 +125,7 @@ + diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index 8eeb38871f327e..b8841c90cc1b96 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -51,9 +51,6 @@ Include - - Include - Include @@ -372,6 +369,9 @@ Include\cpython + + Include\cpython + Include\cpython From 6adbd0fb965b54bf4ec4fcaef1fb87c9f1d846da Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 14 Oct 2021 21:28:52 -0700 Subject: [PATCH 10/18] closes bpo-45479: Degunkify Py_UniversalNewlineFgets. (GH-28965) Remove dead variables and control flow. --- Objects/fileobject.c | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/Objects/fileobject.c b/Objects/fileobject.c index dc600c6d09a487..8eb62490c452b9 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -239,13 +239,7 @@ _PyLong_FileDescriptor_Converter(PyObject *o, void *ptr) ** Py_UniversalNewlineFgets is an fgets variation that understands ** all of \r, \n and \r\n conventions. ** The stream should be opened in binary mode. -** If fobj is NULL the routine always does newline conversion, and -** it may peek one char ahead to gobble the second char in \r\n. -** If fobj is non-NULL it must be a PyFileObject. In this case there -** is no readahead but in stead a flag is used to skip a following -** \n on the next read. Also, if the file is open in binary mode -** the whole conversion is skipped. Finally, the routine keeps track of -** the different types of newlines seen. +** The fobj parameter exists solely for legacy reasons and must be NULL. ** Note that we need no error handling: fgets() treats error and eof ** identically. */ @@ -254,7 +248,6 @@ Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj) { char *p = buf; int c; - int newlinetypes = 0; int skipnextlf = 0; if (fobj) { @@ -262,24 +255,15 @@ Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj) return NULL; } FLOCKFILE(stream); - c = 'x'; /* Shut up gcc warning */ while (--n > 0 && (c = GETC(stream)) != EOF ) { - if (skipnextlf ) { + if (skipnextlf) { skipnextlf = 0; if (c == '\n') { /* Seeing a \n here with skipnextlf true ** means we saw a \r before. */ - newlinetypes |= NEWLINE_CRLF; c = GETC(stream); if (c == EOF) break; - } else { - /* - ** Note that c == EOF also brings us here, - ** so we're okay if the last char in the file - ** is a CR. - */ - newlinetypes |= NEWLINE_CR; } } if (c == '\r') { @@ -289,26 +273,15 @@ Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj) */ skipnextlf = 1; c = '\n'; - } else if ( c == '\n') { - newlinetypes |= NEWLINE_LF; } *p++ = c; if (c == '\n') break; } - /* if ( c == EOF && skipnextlf ) - newlinetypes |= NEWLINE_CR; */ FUNLOCKFILE(stream); *p = '\0'; - if ( skipnextlf ) { - /* If we have no file object we cannot save the - ** skipnextlf flag. We have to readahead, which - ** will cause a pause if we're reading from an - ** interactive stream, but that is very unlikely - ** unless we're doing something silly like - ** exec(open("/dev/tty").read()). - */ - c = GETC(stream); - if ( c != '\n' ) + if (skipnextlf) { + int c = GETC(stream); + if (c != '\n') ungetc(c, stream); } if (p == buf) From a119c0c9082687503fb1ba6be29e23a93e54ff2f Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 14 Oct 2021 23:10:52 -0700 Subject: [PATCH 11/18] bpo-45479: Futher simplify Py_UniversalNewlineFgets. (GH-28967) Thank you to Eryk Sun for the suggestions in https://github.com/python/cpython/pull/28965#discussion_r729527143. --- Objects/fileobject.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 8eb62490c452b9..8ca56a802b9769 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -248,7 +248,6 @@ Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj) { char *p = buf; int c; - int skipnextlf = 0; if (fobj) { errno = ENXIO; /* What can you do... */ @@ -256,34 +255,21 @@ Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj) } FLOCKFILE(stream); while (--n > 0 && (c = GETC(stream)) != EOF ) { - if (skipnextlf) { - skipnextlf = 0; - if (c == '\n') { - /* Seeing a \n here with skipnextlf true - ** means we saw a \r before. - */ - c = GETC(stream); - if (c == EOF) break; - } - } if (c == '\r') { - /* A \r is translated into a \n, and we skip - ** an adjacent \n, if any. We don't set the - ** newlinetypes flag until we've seen the next char. - */ - skipnextlf = 1; - c = '\n'; + // A \r is translated into a \n, and we skip an adjacent \n, if any. + c = GETC(stream); + if (c != '\n') { + ungetc(c, stream); + c = '\n'; + } } *p++ = c; - if (c == '\n') break; + if (c == '\n') { + break; + } } FUNLOCKFILE(stream); *p = '\0'; - if (skipnextlf) { - int c = GETC(stream); - if (c != '\n') - ungetc(c, stream); - } if (p == buf) return NULL; return buf; From c82f6bed9748a3c653e0f8cceea6af89a0d6fab3 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Oct 2021 09:46:29 +0200 Subject: [PATCH 12/18] bpo-35134: Move classobject.h to Include/cpython/ (GH-28968) Move classobject.h, context.h, genobject.h and longintrepr.h header files from Include/ to Include/cpython/. Remove redundant "#ifndef Py_LIMITED_API" in context.h. Remove explicit #include "longintrepr.h" in C files. It's not needed, Python.h already includes it. --- Doc/whatsnew/3.11.rst | 3 ++- Include/Python.h | 10 ++++---- Include/{ => cpython}/classobject.h | 4 ++-- Include/{ => cpython}/context.h | 7 ++---- Include/{ => cpython}/genobject.h | 12 +++++----- Include/{ => cpython}/longintrepr.h | 0 Makefile.pre.in | 8 +++---- .../2021-10-15-00-11-51.bpo-35134.eX4zqy.rst | 3 ++- Modules/_decimal/_decimal.c | 1 - Objects/abstract.c | 1 - Objects/boolobject.c | 1 - Objects/longobject.c | 1 - PCbuild/pythoncore.vcxproj | 8 +++---- PCbuild/pythoncore.vcxproj.filters | 24 +++++++++---------- Python/marshal.c | 1 - 15 files changed, 39 insertions(+), 45 deletions(-) rename Include/{ => cpython}/classobject.h (96%) rename Include/{ => cpython}/context.h (99%) rename Include/{ => cpython}/genobject.h (93%) rename Include/{ => cpython}/longintrepr.h (100%) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 734cf1572fcba4..2e952281865799 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -572,7 +572,8 @@ Porting to Python 3.11 header provides functions like ``printf()`` and ``fopen()``. (Contributed by Victor Stinner in :issue:`45434`.) -* The non-limited API files ``cellobject.h`` and ``funcobject.h`` have been +* The non-limited API files ``cellobject.h``, ``classobject.h``, ``context.h``, + ``funcobject.h``, ``genobject.h`` and ``longintrepr.h`` have been moved to the ``Include/cpython`` directory. These files must not be included directly, as they are already included in ``Python.h``: :ref:`Include Files `. If they have been included directly, consider including diff --git a/Include/Python.h b/Include/Python.h index 89f60fe5c9f945..bc8d4f9b548894 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -46,7 +46,7 @@ #include "bytesobject.h" #include "unicodeobject.h" #include "longobject.h" -#include "longintrepr.h" +#include "cpython/longintrepr.h" #include "boolobject.h" #include "floatobject.h" #include "complexobject.h" @@ -61,7 +61,7 @@ #include "methodobject.h" #include "moduleobject.h" #include "cpython/funcobject.h" -#include "classobject.h" +#include "cpython/classobject.h" #include "fileobject.h" #include "pycapsule.h" #include "code.h" @@ -70,7 +70,8 @@ #include "sliceobject.h" #include "cpython/cellobject.h" #include "iterobject.h" -#include "genobject.h" +#include "pystate.h" +#include "cpython/genobject.h" #include "descrobject.h" #include "genericaliasobject.h" #include "warnings.h" @@ -83,8 +84,7 @@ #include "pyerrors.h" #include "cpython/initconfig.h" #include "pythread.h" -#include "pystate.h" -#include "context.h" +#include "cpython/context.h" #include "modsupport.h" #include "compile.h" #include "pythonrun.h" diff --git a/Include/classobject.h b/Include/cpython/classobject.h similarity index 96% rename from Include/classobject.h rename to Include/cpython/classobject.h index 1952f673b7d865..80df8842eb4f78 100644 --- a/Include/classobject.h +++ b/Include/cpython/classobject.h @@ -53,5 +53,5 @@ PyAPI_FUNC(PyObject *) PyInstanceMethod_Function(PyObject *); #ifdef __cplusplus } #endif -#endif /* !Py_CLASSOBJECT_H */ -#endif /* Py_LIMITED_API */ +#endif // !Py_CLASSOBJECT_H +#endif // !Py_LIMITED_API diff --git a/Include/context.h b/Include/cpython/context.h similarity index 99% rename from Include/context.h rename to Include/cpython/context.h index 4e5007089dd94b..4db079f7633f48 100644 --- a/Include/context.h +++ b/Include/cpython/context.h @@ -1,12 +1,10 @@ +#ifndef Py_LIMITED_API #ifndef Py_CONTEXT_H #define Py_CONTEXT_H #ifdef __cplusplus extern "C" { #endif -#ifndef Py_LIMITED_API - - PyAPI_DATA(PyTypeObject) PyContext_Type; typedef struct _pycontextobject PyContext; @@ -73,9 +71,8 @@ PyAPI_FUNC(int) PyContextVar_Reset(PyObject *var, PyObject *token); PyAPI_FUNC(PyObject *) _PyContext_NewHamtForTests(void); -#endif /* !Py_LIMITED_API */ - #ifdef __cplusplus } #endif #endif /* !Py_CONTEXT_H */ +#endif /* !Py_LIMITED_API */ diff --git a/Include/genobject.h b/Include/cpython/genobject.h similarity index 93% rename from Include/genobject.h rename to Include/cpython/genobject.h index 55a8b34afd60ed..8f87cf5fff7579 100644 --- a/Include/genobject.h +++ b/Include/cpython/genobject.h @@ -1,4 +1,3 @@ - /* Generator object interface */ #ifndef Py_LIMITED_API @@ -8,8 +7,7 @@ extern "C" { #endif -#include "pystate.h" /* _PyErr_StackItem */ -#include "abstract.h" /* PySendResult */ +/* --- Generators --------------------------------------------------------- */ /* _PyGenObject_HEAD defines the initial segment of generator and coroutine objects. */ @@ -45,7 +43,9 @@ PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **); PyObject *_PyGen_yf(PyGenObject *); PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self); -#ifndef Py_LIMITED_API + +/* --- PyCoroObject ------------------------------------------------------- */ + typedef struct { _PyGenObject_HEAD(cr) PyObject *cr_origin; @@ -59,7 +59,8 @@ PyObject *_PyCoro_GetAwaitableIter(PyObject *o); PyAPI_FUNC(PyObject *) PyCoro_New(PyFrameObject *, PyObject *name, PyObject *qualname); -/* Asynchronous Generators */ + +/* --- Asynchronous Generators -------------------------------------------- */ typedef struct { _PyGenObject_HEAD(ag) @@ -89,7 +90,6 @@ PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *, PyObject *_PyAsyncGenValueWrapperNew(PyObject *); -#endif #undef _PyGenObject_HEAD diff --git a/Include/longintrepr.h b/Include/cpython/longintrepr.h similarity index 100% rename from Include/longintrepr.h rename to Include/cpython/longintrepr.h diff --git a/Makefile.pre.in b/Makefile.pre.in index 32bbab068f7027..a81161e147d30b 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1128,12 +1128,10 @@ PYTHON_HEADERS= \ $(srcdir)/Include/bytearrayobject.h \ $(srcdir)/Include/bytesobject.h \ $(srcdir)/Include/ceval.h \ - $(srcdir)/Include/classobject.h \ $(srcdir)/Include/code.h \ $(srcdir)/Include/codecs.h \ $(srcdir)/Include/compile.h \ $(srcdir)/Include/complexobject.h \ - $(srcdir)/Include/context.h \ $(srcdir)/Include/descrobject.h \ $(srcdir)/Include/dictobject.h \ $(srcdir)/Include/dynamic_annotations.h \ @@ -1144,13 +1142,11 @@ PYTHON_HEADERS= \ $(srcdir)/Include/fileutils.h \ $(srcdir)/Include/floatobject.h \ $(srcdir)/Include/frameobject.h \ - $(srcdir)/Include/genobject.h \ $(srcdir)/Include/import.h \ $(srcdir)/Include/interpreteridobject.h \ $(srcdir)/Include/intrcheck.h \ $(srcdir)/Include/iterobject.h \ $(srcdir)/Include/listobject.h \ - $(srcdir)/Include/longintrepr.h \ $(srcdir)/Include/longobject.h \ $(srcdir)/Include/marshal.h \ $(srcdir)/Include/memoryobject.h \ @@ -1202,18 +1198,22 @@ PYTHON_HEADERS= \ $(srcdir)/Include/cpython/bytesobject.h \ $(srcdir)/Include/cpython/cellobject.h \ $(srcdir)/Include/cpython/ceval.h \ + $(srcdir)/Include/cpython/classobject.h \ $(srcdir)/Include/cpython/code.h \ $(srcdir)/Include/cpython/compile.h \ + $(srcdir)/Include/cpython/context.h \ $(srcdir)/Include/cpython/dictobject.h \ $(srcdir)/Include/cpython/fileobject.h \ $(srcdir)/Include/cpython/fileutils.h \ $(srcdir)/Include/cpython/floatobject.h \ $(srcdir)/Include/cpython/frameobject.h \ $(srcdir)/Include/cpython/funcobject.h \ + $(srcdir)/Include/cpython/genobject.h \ $(srcdir)/Include/cpython/import.h \ $(srcdir)/Include/cpython/initconfig.h \ $(srcdir)/Include/cpython/interpreteridobject.h \ $(srcdir)/Include/cpython/listobject.h \ + $(srcdir)/Include/cpython/longintrepr.h \ $(srcdir)/Include/cpython/methodobject.h \ $(srcdir)/Include/cpython/object.h \ $(srcdir)/Include/cpython/objimpl.h \ diff --git a/Misc/NEWS.d/next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst b/Misc/NEWS.d/next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst index 800f6e7f927410..4ab10884a54922 100644 --- a/Misc/NEWS.d/next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst +++ b/Misc/NEWS.d/next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst @@ -1,3 +1,4 @@ -Move ``cellobject.h`` and ``funcobject.h`` header files from ``Include/`` to +Move ``cellobject.h``, ``classobject.h``, ``context.h``, ``funcobject.h``, +``genobject.h`` and ``longintrepr.h`` header files from ``Include/`` to ``Include/cpython/``. C extensions should only include the main ```` header. Patch by Victor Stinner. diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index dd876f200365d5..237edd5191fd94 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -28,7 +28,6 @@ #include #include "pycore_pystate.h" // _PyThreadState_GET() -#include "longintrepr.h" #include "complexobject.h" #include "mpdecimal.h" diff --git a/Objects/abstract.c b/Objects/abstract.c index 0d6cefd3eb8612..6f7b94600e278a 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -10,7 +10,6 @@ #include "pycore_unionobject.h" // _PyUnion_Check() #include #include // offsetof() -#include "longintrepr.h" diff --git a/Objects/boolobject.c b/Objects/boolobject.c index c72243a160b880..53f81926057974 100644 --- a/Objects/boolobject.c +++ b/Objects/boolobject.c @@ -2,7 +2,6 @@ #include "Python.h" #include "pycore_pyerrors.h" // _Py_FatalRefcountError() -#include "longintrepr.h" /* We define bool_repr to return "False" or "True" */ diff --git a/Objects/longobject.c b/Objects/longobject.c index 66e164974a92c2..5325d1852bc029 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -8,7 +8,6 @@ #include "pycore_long.h" // __PyLong_GetSmallInt_internal() #include "pycore_object.h" // _PyObject_InitVar() #include "pycore_pystate.h" // _Py_IsMainInterpreter() -#include "longintrepr.h" #include #include diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 877064e877debe..0b0ff45621dcb8 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -116,29 +116,31 @@ - - + + + + @@ -170,7 +172,6 @@ - @@ -224,7 +225,6 @@ - diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index b8841c90cc1b96..17794fce88bc81 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -54,9 +54,6 @@ Include - - Include - Include @@ -69,9 +66,6 @@ Include - - Include - Include @@ -105,9 +99,6 @@ Include - - Include - Include @@ -120,9 +111,6 @@ Include - - Include - Include @@ -375,12 +363,18 @@ Include\cpython + + Include\cpython + Include\cpython Include + + Include\cpython + Include\cpython @@ -399,6 +393,9 @@ Include\cpython + + Include + Include @@ -456,6 +453,9 @@ Include\cpython + + Include + Include\cpython diff --git a/Python/marshal.c b/Python/marshal.c index e9ad566b71b107..51c77555d9ea97 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -13,7 +13,6 @@ #include "pycore_code.h" // _PyCode_New() #include "pycore_floatobject.h" // _PyFloat_Pack8() #include "pycore_hashtable.h" // _Py_hashtable_t -#include "longintrepr.h" #include "code.h" #include "marshal.h" // Py_MARSHAL_VERSION From c50770d58ef681272c41ae68ae201afbf20ff1e9 Mon Sep 17 00:00:00 2001 From: Graham Inggs Date: Fri, 15 Oct 2021 11:38:55 +0200 Subject: [PATCH 13/18] bpo-45428: Fix reading filenames from stdin in py_compile (GH-28848) Strip trailing '\n'. --- Lib/py_compile.py | 2 +- .../next/Library/2021-10-14-18-04-17.bpo-45428.mM2War.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2021-10-14-18-04-17.bpo-45428.mM2War.rst diff --git a/Lib/py_compile.py b/Lib/py_compile.py index 0f9b59025cee38..388614e51b1847 100644 --- a/Lib/py_compile.py +++ b/Lib/py_compile.py @@ -190,7 +190,7 @@ def main(): ) args = parser.parse_args() if args.filenames == ['-']: - filenames = sys.stdin.readlines() + filenames = [filename.rstrip('\n') for filename in sys.stdin.readlines()] else: filenames = args.filenames for filename in filenames: diff --git a/Misc/NEWS.d/next/Library/2021-10-14-18-04-17.bpo-45428.mM2War.rst b/Misc/NEWS.d/next/Library/2021-10-14-18-04-17.bpo-45428.mM2War.rst new file mode 100644 index 00000000000000..556eca43ed3c77 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-10-14-18-04-17.bpo-45428.mM2War.rst @@ -0,0 +1 @@ +Fix a regression in py_compile when reading filenames from standard input. \ No newline at end of file From d0d02d115b2b649bfb306e08193857b69e72a47b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Oct 2021 11:56:34 +0200 Subject: [PATCH 14/18] bpo-35081: Move interpreteridobject.h to Include/internal/ (GH-28969) Move the interpreteridobject.h header file from Include/ to Include/internal/. It only provides private functions. --- .../pycore_interpreteridobject.h} | 17 ++++++++++++++--- Include/internal/pycore_pymem.h | 2 +- Include/interpreteridobject.h | 17 ----------------- Makefile.pre.in | 3 +-- .../2021-10-15-09-29-59.bpo-35081.2teFD3.rst | 3 +++ Modules/_xxsubinterpretersmodule.c | 2 +- Objects/interpreteridobject.c | 2 +- Objects/object.c | 2 +- PCbuild/pythoncore.vcxproj | 3 +-- PCbuild/pythoncore.vcxproj.filters | 9 +++------ Tools/c-analyzer/cpython/_parser.py | 1 - 11 files changed, 26 insertions(+), 35 deletions(-) rename Include/{cpython/interpreteridobject.h => internal/pycore_interpreteridobject.h} (51%) delete mode 100644 Include/interpreteridobject.h create mode 100644 Misc/NEWS.d/next/C API/2021-10-15-09-29-59.bpo-35081.2teFD3.rst diff --git a/Include/cpython/interpreteridobject.h b/Include/internal/pycore_interpreteridobject.h similarity index 51% rename from Include/cpython/interpreteridobject.h rename to Include/internal/pycore_interpreteridobject.h index 5076584209b90b..804831e76deaea 100644 --- a/Include/cpython/interpreteridobject.h +++ b/Include/internal/pycore_interpreteridobject.h @@ -1,11 +1,22 @@ -#ifndef Py_CPYTHON_INTERPRETERIDOBJECT_H -# error "this header file must not be included directly" +/* Interpreter ID Object */ + +#ifndef Py_INTERNAL_INTERPRETERIDOBJECT_H +#define Py_INTERNAL_INTERPRETERIDOBJECT_H +#ifdef __cplusplus +extern "C" { #endif -/* Interpreter ID Object */ +#ifndef Py_BUILD_CORE +# error "this header requires Py_BUILD_CORE define" +#endif PyAPI_DATA(PyTypeObject) _PyInterpreterID_Type; PyAPI_FUNC(PyObject *) _PyInterpreterID_New(int64_t); PyAPI_FUNC(PyObject *) _PyInterpreterState_GetIDObject(PyInterpreterState *); PyAPI_FUNC(PyInterpreterState *) _PyInterpreterID_LookUp(PyObject *); + +#ifdef __cplusplus +} +#endif +#endif // !Py_INTERNAL_INTERPRETERIDOBJECT_H diff --git a/Include/internal/pycore_pymem.h b/Include/internal/pycore_pymem.h index 30db3f2b6701ec..d70deee710e30d 100644 --- a/Include/internal/pycore_pymem.h +++ b/Include/internal/pycore_pymem.h @@ -103,4 +103,4 @@ void _PyObject_VirtualFree(void *, size_t size); #ifdef __cplusplus } #endif -#endif /* !Py_INTERNAL_PYMEM_H */ +#endif // !Py_INTERNAL_PYMEM_H diff --git a/Include/interpreteridobject.h b/Include/interpreteridobject.h deleted file mode 100644 index 8432632f339e92..00000000000000 --- a/Include/interpreteridobject.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef Py_INTERPRETERIDOBJECT_H -#define Py_INTERPRETERIDOBJECT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef Py_LIMITED_API -# define Py_CPYTHON_INTERPRETERIDOBJECT_H -# include "cpython/interpreteridobject.h" -# undef Py_CPYTHON_INTERPRETERIDOBJECT_H -#endif - -#ifdef __cplusplus -} -#endif -#endif /* !Py_INTERPRETERIDOBJECT_H */ diff --git a/Makefile.pre.in b/Makefile.pre.in index a81161e147d30b..ccce52b36c42e2 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1143,7 +1143,6 @@ PYTHON_HEADERS= \ $(srcdir)/Include/floatobject.h \ $(srcdir)/Include/frameobject.h \ $(srcdir)/Include/import.h \ - $(srcdir)/Include/interpreteridobject.h \ $(srcdir)/Include/intrcheck.h \ $(srcdir)/Include/iterobject.h \ $(srcdir)/Include/listobject.h \ @@ -1211,7 +1210,6 @@ PYTHON_HEADERS= \ $(srcdir)/Include/cpython/genobject.h \ $(srcdir)/Include/cpython/import.h \ $(srcdir)/Include/cpython/initconfig.h \ - $(srcdir)/Include/cpython/interpreteridobject.h \ $(srcdir)/Include/cpython/listobject.h \ $(srcdir)/Include/cpython/longintrepr.h \ $(srcdir)/Include/cpython/methodobject.h \ @@ -1260,6 +1258,7 @@ PYTHON_HEADERS= \ $(srcdir)/Include/internal/pycore_import.h \ $(srcdir)/Include/internal/pycore_initconfig.h \ $(srcdir)/Include/internal/pycore_interp.h \ + $(srcdir)/Include/internal/pycore_interpreteridobject.h \ $(srcdir)/Include/internal/pycore_list.h \ $(srcdir)/Include/internal/pycore_long.h \ $(srcdir)/Include/internal/pycore_moduleobject.h \ diff --git a/Misc/NEWS.d/next/C API/2021-10-15-09-29-59.bpo-35081.2teFD3.rst b/Misc/NEWS.d/next/C API/2021-10-15-09-29-59.bpo-35081.2teFD3.rst new file mode 100644 index 00000000000000..79d4a9b9180d95 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2021-10-15-09-29-59.bpo-35081.2teFD3.rst @@ -0,0 +1,3 @@ +Move the ``interpreteridobject.h`` header file from ``Include/`` to +``Include/internal/``. It only provides private functions. Patch by Victor +Stinner. diff --git a/Modules/_xxsubinterpretersmodule.c b/Modules/_xxsubinterpretersmodule.c index 939114e60cae97..b5c0a632191146 100644 --- a/Modules/_xxsubinterpretersmodule.c +++ b/Modules/_xxsubinterpretersmodule.c @@ -6,7 +6,7 @@ #include "frameobject.h" #include "pycore_frame.h" #include "pycore_pystate.h" // _PyThreadState_GET() -#include "interpreteridobject.h" +#include "pycore_interpreteridobject.h" static char * diff --git a/Objects/interpreteridobject.c b/Objects/interpreteridobject.c index 46239100dcb7b7..7b3e31beded594 100644 --- a/Objects/interpreteridobject.c +++ b/Objects/interpreteridobject.c @@ -3,7 +3,7 @@ #include "Python.h" #include "pycore_abstract.h" // _PyIndex_Check() #include "pycore_interp.h" // _PyInterpreterState_LookUpID() -#include "interpreteridobject.h" +#include "pycore_interpreteridobject.h" typedef struct interpid { diff --git a/Objects/object.c b/Objects/object.c index 589dd6647318da..5e719d45b60a69 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -16,7 +16,7 @@ #include "pycore_symtable.h" // PySTEntry_Type #include "pycore_unionobject.h" // _PyUnion_Type #include "frameobject.h" // PyFrame_Type -#include "interpreteridobject.h" // _PyInterpreterID_Type +#include "pycore_interpreteridobject.h" // _PyInterpreterID_Type #ifdef Py_LIMITED_API // Prevent recursive call _Py_IncRef() <=> Py_INCREF() diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 0b0ff45621dcb8..32511d2a665113 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -138,7 +138,6 @@ - @@ -200,6 +199,7 @@ + @@ -221,7 +221,6 @@ - diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index 17794fce88bc81..4cc1092b33a496 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -333,9 +333,6 @@ Include - - Include - Modules @@ -456,9 +453,6 @@ Include - - Include\cpython - Include\cpython @@ -555,6 +549,9 @@ Include\internal + + Include\cpython + Include\internal diff --git a/Tools/c-analyzer/cpython/_parser.py b/Tools/c-analyzer/cpython/_parser.py index ef06a9fcb69033..8526b2af15a235 100644 --- a/Tools/c-analyzer/cpython/_parser.py +++ b/Tools/c-analyzer/cpython/_parser.py @@ -172,7 +172,6 @@ def clean_lines(text): Include/cpython/fileutils.h Py_CPYTHON_FILEUTILS_H 1 Include/cpython/frameobject.h Py_CPYTHON_FRAMEOBJECT_H 1 Include/cpython/import.h Py_CPYTHON_IMPORT_H 1 -Include/cpython/interpreteridobject.h Py_CPYTHON_INTERPRETERIDOBJECT_H 1 Include/cpython/listobject.h Py_CPYTHON_LISTOBJECT_H 1 Include/cpython/methodobject.h Py_CPYTHON_METHODOBJECT_H 1 Include/cpython/object.h Py_CPYTHON_OBJECT_H 1 From 50818d22baa9eb7ef85e3b9494234fe21685f2e3 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Oct 2021 13:06:05 +0200 Subject: [PATCH 15/18] bpo-45434: Remove Include/eval.h header file (GH-28973) Move Include/eval.h content into Include/ceval.h and Include/cpython/ceval.h, and remove Include/eval.h. --- Doc/faq/extending.rst | 3 --- Doc/faq/windows.rst | 2 +- Doc/whatsnew/3.11.rst | 10 +++---- Include/Python.h | 1 - Include/ceval.h | 12 ++++++++- Include/cpython/ceval.h | 2 ++ Include/eval.h | 27 ------------------- Makefile.pre.in | 1 - .../2021-10-15-00-11-51.bpo-35134.eX4zqy.rst | 11 +++++--- PCbuild/pythoncore.vcxproj | 1 - PCbuild/pythoncore.vcxproj.filters | 3 --- 11 files changed, 26 insertions(+), 47 deletions(-) delete mode 100644 Include/eval.h diff --git a/Doc/faq/extending.rst b/Doc/faq/extending.rst index 3379e41d9de072..fd32b097335e53 100644 --- a/Doc/faq/extending.rst +++ b/Doc/faq/extending.rst @@ -290,9 +290,6 @@ complete example using the GNU readline library (you may want to ignore #define PY_SSIZE_T_CLEAN #include - #include - #include - #include int main (int argc, char* argv[]) { diff --git a/Doc/faq/windows.rst b/Doc/faq/windows.rst index 0153a4f316ee82..6b95819c8ee855 100644 --- a/Doc/faq/windows.rst +++ b/Doc/faq/windows.rst @@ -212,7 +212,7 @@ Embedding the Python interpreter in a Windows app can be summarized as follows: .. code-block:: c - #include "python.h" + #include ... Py_Initialize(); // Initialize Python. initmyAppc(); // Initialize (import) the helper class. diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 2e952281865799..994fb843fd3777 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -573,11 +573,11 @@ Porting to Python 3.11 (Contributed by Victor Stinner in :issue:`45434`.) * The non-limited API files ``cellobject.h``, ``classobject.h``, ``context.h``, - ``funcobject.h``, ``genobject.h`` and ``longintrepr.h`` have been - moved to the ``Include/cpython`` directory. These files must not be included - directly, as they are already included in ``Python.h``: :ref:`Include Files - `. If they have been included directly, consider including - ``Python.h`` instead. + ``funcobject.h``, ``genobject.h`` and ``longintrepr.h`` have been moved to + the ``Include/cpython`` directory. Moreover, the ``eval.h`` header file was + removed. These files must not be included directly, as they are already + included in ``Python.h``: :ref:`Include Files `. If they have + been included directly, consider including ``Python.h`` instead. (Contributed by Victor Stinner in :issue:`35134`.) Deprecated diff --git a/Include/Python.h b/Include/Python.h index bc8d4f9b548894..a2de514702f2fb 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -96,7 +96,6 @@ #include "import.h" #include "abstract.h" #include "bltinmodule.h" -#include "eval.h" #include "cpython/pyctype.h" #include "pystrtod.h" #include "pystrcmp.h" diff --git a/Include/ceval.h b/Include/ceval.h index cf8c5b17be589a..1b57f6ea20f6f0 100644 --- a/Include/ceval.h +++ b/Include/ceval.h @@ -1,3 +1,5 @@ +/* Interface to random parts in ceval.c */ + #ifndef Py_CEVAL_H #define Py_CEVAL_H #ifdef __cplusplus @@ -5,7 +7,15 @@ extern "C" { #endif -/* Interface to random parts in ceval.c */ +PyAPI_FUNC(PyObject *) PyEval_EvalCode(PyObject *, PyObject *, PyObject *); + +PyAPI_FUNC(PyObject *) PyEval_EvalCodeEx(PyObject *co, + PyObject *globals, + PyObject *locals, + PyObject *const *args, int argc, + PyObject *const *kwds, int kwdc, + PyObject *const *defs, int defc, + PyObject *kwdefs, PyObject *closure); /* PyEval_CallObjectWithKeywords(), PyEval_CallObject(), PyEval_CallFunction * and PyEval_CallMethod are deprecated. Since they are officially part of the diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h index 44b78f6d223120..caf64401307c07 100644 --- a/Include/cpython/ceval.h +++ b/Include/cpython/ceval.h @@ -2,6 +2,8 @@ # error "this header file must not be included directly" #endif +PyAPI_FUNC(PyObject *) _PyEval_CallTracing(PyObject *func, PyObject *args); + PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *); PyAPI_DATA(int) _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg); PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *); diff --git a/Include/eval.h b/Include/eval.h deleted file mode 100644 index eda28df8f65281..00000000000000 --- a/Include/eval.h +++ /dev/null @@ -1,27 +0,0 @@ - -/* Interface to execute compiled code */ - -#ifndef Py_EVAL_H -#define Py_EVAL_H -#ifdef __cplusplus -extern "C" { -#endif - -PyAPI_FUNC(PyObject *) PyEval_EvalCode(PyObject *, PyObject *, PyObject *); - -PyAPI_FUNC(PyObject *) PyEval_EvalCodeEx(PyObject *co, - PyObject *globals, - PyObject *locals, - PyObject *const *args, int argc, - PyObject *const *kwds, int kwdc, - PyObject *const *defs, int defc, - PyObject *kwdefs, PyObject *closure); - -#ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) _PyEval_CallTracing(PyObject *func, PyObject *args); -#endif - -#ifdef __cplusplus -} -#endif -#endif /* !Py_EVAL_H */ diff --git a/Makefile.pre.in b/Makefile.pre.in index ccce52b36c42e2..b79b71f59b1459 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1137,7 +1137,6 @@ PYTHON_HEADERS= \ $(srcdir)/Include/dynamic_annotations.h \ $(srcdir)/Include/enumobject.h \ $(srcdir)/Include/errcode.h \ - $(srcdir)/Include/eval.h \ $(srcdir)/Include/fileobject.h \ $(srcdir)/Include/fileutils.h \ $(srcdir)/Include/floatobject.h \ diff --git a/Misc/NEWS.d/next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst b/Misc/NEWS.d/next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst index 4ab10884a54922..d0d3ce6b34f6f1 100644 --- a/Misc/NEWS.d/next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst +++ b/Misc/NEWS.d/next/C API/2021-10-15-00-11-51.bpo-35134.eX4zqy.rst @@ -1,4 +1,7 @@ -Move ``cellobject.h``, ``classobject.h``, ``context.h``, ``funcobject.h``, -``genobject.h`` and ``longintrepr.h`` header files from ``Include/`` to -``Include/cpython/``. C extensions should only include the main ```` -header. Patch by Victor Stinner. +The non-limited API files ``cellobject.h``, ``classobject.h``, ``context.h``, +``funcobject.h``, ``genobject.h`` and ``longintrepr.h`` have been moved to +the ``Include/cpython`` directory. Moreover, the ``eval.h`` header file was +removed. These files must not be included directly, as they are already +included in ``Python.h``: :ref:`Include Files `. If they have +been included directly, consider including ``Python.h`` instead. +Patch by Victor Stinner. diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 32511d2a665113..357d0a7071031c 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -166,7 +166,6 @@ - diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index 4cc1092b33a496..1a3ad884d4ac3e 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -84,9 +84,6 @@ Include - - Include - Include From 1856e8c5aa08057efc6c3ea51b210237e9fc1204 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Salgado Date: Fri, 15 Oct 2021 12:18:22 +0100 Subject: [PATCH 16/18] bpo-45445: Remove incorrectly commited test file (GH-28972) --- test_foo.py | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 test_foo.py diff --git a/test_foo.py b/test_foo.py deleted file mode 100644 index a27be0fdb47a69..00000000000000 --- a/test_foo.py +++ /dev/null @@ -1,3 +0,0 @@ -def foo(a=3, *, c, d=2): - pass -foo() From 7dad45b0ede59df05742a97ce501b817084b2252 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Oct 2021 13:43:44 +0200 Subject: [PATCH 17/18] bpo-44113: Move the What's New entry to Deprecate section (GH-28974) --- Doc/whatsnew/3.11.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 994fb843fd3777..8a3deaa0f6305a 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -583,13 +583,6 @@ Porting to Python 3.11 Deprecated ---------- -Removed -------- - -* :c:func:`PyFrame_BlockSetup` and :c:func:`PyFrame_BlockPop` have been - removed. - (Contributed by Mark Shannon in :issue:`40222`.) - * Deprecate the following functions to configure the Python initialization: * :c:func:`PySys_AddWarnOptionUnicode` @@ -606,6 +599,13 @@ Removed ` instead (:pep:`587`). (Contributed by Victor Stinner in :issue:`44113`.) +Removed +------- + +* :c:func:`PyFrame_BlockSetup` and :c:func:`PyFrame_BlockPop` have been + removed. + (Contributed by Mark Shannon in :issue:`40222`.) + * Remove the following math macros using the ``errno`` variable: * ``Py_ADJUST_ERANGE1()`` From 675ff5dad48d814a1a6811b12fa0298cae504c39 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Oct 2021 15:21:21 +0200 Subject: [PATCH 18/18] bpo-45482: Rename namespaceobject.h to pycore_namespace.h (GH-28975) Rename Include/namespaceobject.h to Include/internal/pycore_namespace.h. The _testmultiphase extension is now built with the Py_BUILD_CORE_MODULE macro defined to access _PyNamespace_Type. object.c: remove unused "pycore_context.h" include. --- Include/Python.h | 1 - Include/internal/pycore_namespace.h | 20 ++++++++++++++++++++ Include/namespaceobject.h | 19 ------------------- Makefile.pre.in | 2 +- Modules/_testcapimodule.c | 4 ++-- Modules/_testmultiphase.c | 1 + Modules/timemodule.c | 1 + Objects/namespaceobject.c | 1 + Objects/object.c | 4 ++-- PCbuild/pythoncore.vcxproj | 2 +- PCbuild/pythoncore.vcxproj.filters | 6 +++--- Python/import.c | 20 ++++++++++---------- Python/sysmodule.c | 1 + setup.py | 3 ++- 14 files changed, 45 insertions(+), 40 deletions(-) create mode 100644 Include/internal/pycore_namespace.h delete mode 100644 Include/namespaceobject.h diff --git a/Include/Python.h b/Include/Python.h index a2de514702f2fb..c0a621ad44afd1 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -77,7 +77,6 @@ #include "warnings.h" #include "weakrefobject.h" #include "structseq.h" -#include "namespaceobject.h" #include "cpython/picklebufobject.h" #include "cpython/pytime.h" #include "codecs.h" diff --git a/Include/internal/pycore_namespace.h b/Include/internal/pycore_namespace.h new file mode 100644 index 00000000000000..cb76f040693d10 --- /dev/null +++ b/Include/internal/pycore_namespace.h @@ -0,0 +1,20 @@ +// Simple namespace object interface + +#ifndef Py_INTERNAL_NAMESPACE_H +#define Py_INTERNAL_NAMESPACE_H +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef Py_BUILD_CORE +# error "this header requires Py_BUILD_CORE define" +#endif + +PyAPI_DATA(PyTypeObject) _PyNamespace_Type; + +PyAPI_FUNC(PyObject *) _PyNamespace_New(PyObject *kwds); + +#ifdef __cplusplus +} +#endif +#endif // !Py_INTERNAL_NAMESPACE_H diff --git a/Include/namespaceobject.h b/Include/namespaceobject.h deleted file mode 100644 index 0c8d95c0f137c6..00000000000000 --- a/Include/namespaceobject.h +++ /dev/null @@ -1,19 +0,0 @@ - -/* simple namespace object interface */ - -#ifndef NAMESPACEOBJECT_H -#define NAMESPACEOBJECT_H -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef Py_LIMITED_API -PyAPI_DATA(PyTypeObject) _PyNamespace_Type; - -PyAPI_FUNC(PyObject *) _PyNamespace_New(PyObject *kwds); -#endif /* !Py_LIMITED_API */ - -#ifdef __cplusplus -} -#endif -#endif /* !NAMESPACEOBJECT_H */ diff --git a/Makefile.pre.in b/Makefile.pre.in index b79b71f59b1459..9de51711ac4c53 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1151,7 +1151,6 @@ PYTHON_HEADERS= \ $(srcdir)/Include/methodobject.h \ $(srcdir)/Include/modsupport.h \ $(srcdir)/Include/moduleobject.h \ - $(srcdir)/Include/namespaceobject.h \ $(srcdir)/Include/object.h \ $(srcdir)/Include/objimpl.h \ $(srcdir)/Include/opcode.h \ @@ -1261,6 +1260,7 @@ PYTHON_HEADERS= \ $(srcdir)/Include/internal/pycore_list.h \ $(srcdir)/Include/internal/pycore_long.h \ $(srcdir)/Include/internal/pycore_moduleobject.h \ + $(srcdir)/Include/internal/pycore_namespace.h \ $(srcdir)/Include/internal/pycore_object.h \ $(srcdir)/Include/internal/pycore_pathconfig.h \ $(srcdir)/Include/internal/pycore_pyarena.h \ diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 7cbd2dc3b6a51f..82cfc04c410961 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -1167,8 +1167,8 @@ test_get_type_qualname(PyObject *self, PyObject *Py_UNUSED(ignored)) assert(strcmp(PyUnicode_AsUTF8(tp_qualname), "int") == 0); Py_DECREF(tp_qualname); - tp_qualname = PyType_GetQualName(&_PyNamespace_Type); - assert(strcmp(PyUnicode_AsUTF8(tp_qualname), "SimpleNamespace") == 0); + tp_qualname = PyType_GetQualName(&PyODict_Type); + assert(strcmp(PyUnicode_AsUTF8(tp_qualname), "OrderedDict") == 0); Py_DECREF(tp_qualname); PyObject *HeapTypeNameType = PyType_FromSpec(&HeapTypeNameType_Spec); diff --git a/Modules/_testmultiphase.c b/Modules/_testmultiphase.c index e0ed77d265cdcc..2d25e16bd4d390 100644 --- a/Modules/_testmultiphase.c +++ b/Modules/_testmultiphase.c @@ -3,6 +3,7 @@ */ #include "Python.h" +#include "pycore_namespace.h" // _PyNamespace_New() /* State for testing module state access from methods */ diff --git a/Modules/timemodule.c b/Modules/timemodule.c index ca8d62d5cc9380..0ef3b2ffaa8987 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -2,6 +2,7 @@ #include "Python.h" #include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH +#include "pycore_namespace.h" // _PyNamespace_New() #include diff --git a/Objects/namespaceobject.c b/Objects/namespaceobject.c index fa37ed250d30a4..7875e7cafecb65 100644 --- a/Objects/namespaceobject.c +++ b/Objects/namespaceobject.c @@ -1,6 +1,7 @@ // namespace object implementation #include "Python.h" +#include "pycore_namespace.h" // _PyNamespace_Type #include "structmember.h" // PyMemberDef diff --git a/Objects/object.c b/Objects/object.c index 5e719d45b60a69..25f5a2133d5745 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -4,10 +4,10 @@ #include "Python.h" #include "pycore_call.h" // _PyObject_CallNoArgs() #include "pycore_ceval.h" // _Py_EnterRecursiveCall() -#include "pycore_context.h" -#include "pycore_dict.h" +#include "pycore_dict.h" // _PyObject_MakeDictFromInstanceAttributes() #include "pycore_floatobject.h" // _PyFloat_DebugMallocStats() #include "pycore_initconfig.h" // _PyStatus_EXCEPTION() +#include "pycore_namespace.h" // _PyNamespace_Type #include "pycore_object.h" // _PyType_CheckConsistency() #include "pycore_pyerrors.h" // _PyErr_Occurred() #include "pycore_pylifecycle.h" // _PyTypes_InitSlotDefs() diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 357d0a7071031c..015d783c89a83b 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -202,6 +202,7 @@ + @@ -229,7 +230,6 @@ - diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index 1a3ad884d4ac3e..94528b9261fa60 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -327,9 +327,6 @@ Include - - Include - Modules @@ -558,6 +555,9 @@ Include\internal + + Include + Include\internal diff --git a/Python/import.c b/Python/import.c index f2160928c4fa7c..fe4686cd56b3ba 100644 --- a/Python/import.c +++ b/Python/import.c @@ -3,19 +3,19 @@ #include "Python.h" #include "pycore_import.h" // _PyImport_BootstrapImp() -#include "pycore_initconfig.h" -#include "pycore_pyerrors.h" -#include "pycore_pyhash.h" +#include "pycore_initconfig.h" // _PyStatus_OK() +#include "pycore_interp.h" // _PyInterpreterState_ClearModules() +#include "pycore_namespace.h" // _PyNamespace_Type +#include "pycore_pyerrors.h" // _PyErr_SetString() +#include "pycore_pyhash.h" // _Py_KeyedHash() #include "pycore_pylifecycle.h" #include "pycore_pymem.h" // _PyMem_SetDefaultAllocator() -#include "pycore_interp.h" // _PyInterpreterState_ClearModules() #include "pycore_pystate.h" // _PyInterpreterState_GET() -#include "pycore_sysmodule.h" -#include "marshal.h" -#include "code.h" -#include "importdl.h" -#include "pydtrace.h" -#include +#include "pycore_sysmodule.h" // _PySys_Audit() +#include "marshal.h" // PyMarshal_ReadObjectFromString() +#include "importdl.h" // _PyImport_DynLoadFiletab +#include "pydtrace.h" // PyDTrace_IMPORT_FIND_LOAD_START_ENABLED() +#include // bool #ifdef HAVE_FCNTL_H #include diff --git a/Python/sysmodule.c b/Python/sysmodule.c index ae3cbf1954e09e..ad9be714c021ab 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -20,6 +20,7 @@ Data members: #include "pycore_code.h" // _Py_QuickenedCount #include "pycore_frame.h" // InterpreterFrame #include "pycore_initconfig.h" // _PyStatus_EXCEPTION() +#include "pycore_namespace.h" // _PyNamespace_New() #include "pycore_object.h" // _PyObject_IS_GC() #include "pycore_pathconfig.h" // _PyPathConfig_ComputeSysPath0() #include "pycore_pyerrors.h" // _PyErr_Fetch() diff --git a/setup.py b/setup.py index 56c06cbddaf21d..24365ef3d927ba 100644 --- a/setup.py +++ b/setup.py @@ -1043,7 +1043,8 @@ def detect_test_extensions(self): self.add(Extension('_testimportmultiple', ['_testimportmultiple.c'])) # Test multi-phase extension module init (PEP 489) - self.add(Extension('_testmultiphase', ['_testmultiphase.c'])) + self.add(Extension('_testmultiphase', ['_testmultiphase.c'], + extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) # Fuzz tests. self.add(Extension('_xxtestfuzz',