summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-10-13 13:03:35 (GMT)
committerGitHub <noreply@github.com>2021-10-13 13:03:35 (GMT)
commit97308dfcdc0696e0b116c37386e2ff4d72e6c3f4 (patch)
treea827f813979840eb28c66d5b74ab6f653fe51207
parent7cdc2a0f4b785327ad9d55312409a06e554df3d5 (diff)
downloadcpython-97308dfcdc0696e0b116c37386e2ff4d72e6c3f4.zip
cpython-97308dfcdc0696e0b116c37386e2ff4d72e6c3f4.tar.gz
cpython-97308dfcdc0696e0b116c37386e2ff4d72e6c3f4.tar.bz2
bpo-45434: Move _Py_BEGIN_SUPPRESS_IPH to pycore_fileutils.h (GH-28922)
-rw-r--r--Include/internal/pycore_fileutils.h19
-rw-r--r--Include/pyport.h20
-rw-r--r--Modules/_io/fileio.c3
-rw-r--r--Modules/_io/winconsoleio.c3
-rw-r--r--Modules/signalmodule.c1
-rw-r--r--Modules/timemodule.c31
-rw-r--r--PC/getpathp.c2
-rw-r--r--PC/msvcrtmodule.c1
-rw-r--r--Parser/myreadline.c1
-rw-r--r--Python/traceback.c5
10 files changed, 44 insertions, 42 deletions
diff --git a/Include/internal/pycore_fileutils.h b/Include/internal/pycore_fileutils.h
index 8491ed9..2316a97 100644
--- a/Include/internal/pycore_fileutils.h
+++ b/Include/internal/pycore_fileutils.h
@@ -80,6 +80,25 @@ extern int _Py_add_relfile(wchar_t *dirname,
const wchar_t *relfile,
size_t bufsize);
+// Macros to protect CRT calls against instant termination when passed an
+// invalid parameter (bpo-23524). IPH stands for Invalid Parameter Handler.
+// Usage:
+//
+// _Py_BEGIN_SUPPRESS_IPH
+// ...
+// _Py_END_SUPPRESS_IPH
+#if defined _MSC_VER && _MSC_VER >= 1900
+ extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
+# define _Py_BEGIN_SUPPRESS_IPH \
+ { _invalid_parameter_handler _Py_old_handler = \
+ _set_thread_local_invalid_parameter_handler(_Py_silent_invalid_parameter_handler);
+# define _Py_END_SUPPRESS_IPH \
+ _set_thread_local_invalid_parameter_handler(_Py_old_handler); }
+#else
+# define _Py_BEGIN_SUPPRESS_IPH
+# define _Py_END_SUPPRESS_IPH
+#endif /* _MSC_VER >= 1900 */
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/pyport.h b/Include/pyport.h
index a8a2d6d..6e4e980 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -712,26 +712,6 @@ extern char * _getpty(int *, int, mode_t, int);
# define PY_LITTLE_ENDIAN 1
#endif
-#ifdef Py_BUILD_CORE
-/*
- * Macros to protect CRT calls against instant termination when passed an
- * invalid parameter (issue23524).
- */
-#if defined _MSC_VER && _MSC_VER >= 1900
-
-extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
-#define _Py_BEGIN_SUPPRESS_IPH { _invalid_parameter_handler _Py_old_handler = \
- _set_thread_local_invalid_parameter_handler(_Py_silent_invalid_parameter_handler);
-#define _Py_END_SUPPRESS_IPH _set_thread_local_invalid_parameter_handler(_Py_old_handler); }
-
-#else
-
-#define _Py_BEGIN_SUPPRESS_IPH
-#define _Py_END_SUPPRESS_IPH
-
-#endif /* _MSC_VER >= 1900 */
-#endif /* Py_BUILD_CORE */
-
#ifdef __ANDROID__
/* The Android langinfo.h header is not used. */
# undef HAVE_LANGINFO_H
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index b9856b3..dd215e8 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -2,7 +2,8 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"
-#include "pycore_object.h"
+#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
+#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#include "structmember.h" // PyMemberDef
#include <stdbool.h>
#ifdef HAVE_SYS_TYPES_H
diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c
index 460f2d3..4002d28 100644
--- a/Modules/_io/winconsoleio.c
+++ b/Modules/_io/winconsoleio.c
@@ -8,7 +8,8 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"
-#include "pycore_object.h"
+#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
+#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#ifdef MS_WINDOWS
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index 6568a4d..09f4aed 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -7,6 +7,7 @@
#include "pycore_atomic.h" // _Py_atomic_int
#include "pycore_call.h" // _PyObject_Call()
#include "pycore_ceval.h" // _PyEval_SignalReceived()
+#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
#include "pycore_frame.h" // InterpreterFrame
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_pyerrors.h" // _PyErr_SetString()
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 4639afa..ca8d62d 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -1,33 +1,28 @@
/* Time module */
#include "Python.h"
+#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
#include <ctype.h>
#ifdef HAVE_SYS_TIMES_H
-#include <sys/times.h>
+# include <sys/times.h>
#endif
-
#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
+# include <sys/types.h>
#endif
-
#if defined(HAVE_SYS_RESOURCE_H)
-#include <sys/resource.h>
+# include <sys/resource.h>
#endif
-
#ifdef QUICKWIN
-#include <io.h>
+# include <io.h>
#endif
-
#if defined(HAVE_PTHREAD_H)
# include <pthread.h>
#endif
-
#if defined(_AIX)
# include <sys/thread.h>
#endif
-
#if defined(__WATCOMC__) && !defined(__QNX__)
# include <i86.h>
#else
@@ -38,17 +33,17 @@
#endif /* !__WATCOMC__ || __QNX__ */
#ifdef _Py_MEMORY_SANITIZER
-# include <sanitizer/msan_interface.h>
+# include <sanitizer/msan_interface.h>
#endif
#ifdef _MSC_VER
-#define _Py_timezone _timezone
-#define _Py_daylight _daylight
-#define _Py_tzname _tzname
+# define _Py_timezone _timezone
+# define _Py_daylight _daylight
+# define _Py_tzname _tzname
#else
-#define _Py_timezone timezone
-#define _Py_daylight daylight
-#define _Py_tzname tzname
+# define _Py_timezone timezone
+# define _Py_daylight daylight
+# define _Py_tzname tzname
#endif
#if defined(__APPLE__ ) && defined(__has_builtin)
@@ -60,8 +55,10 @@
# define HAVE_CLOCK_GETTIME_RUNTIME 1
#endif
+
#define SEC_TO_NS (1000 * 1000 * 1000)
+
/* Forward declarations */
static int pysleep(_PyTime_t timeout);
diff --git a/PC/getpathp.c b/PC/getpathp.c
index 79569bb..549353d 100644
--- a/PC/getpathp.c
+++ b/PC/getpathp.c
@@ -80,9 +80,9 @@
#include "Python.h"
+#include "pycore_fileutils.h" // _Py_add_relfile()
#include "pycore_initconfig.h" // PyStatus
#include "pycore_pathconfig.h" // _PyPathConfig
-#include "pycore_fileutils.h" // _Py_add_relfile()
#include "osdefs.h" // SEP, ALTSEP
#include <wchar.h>
diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c
index 0591497..1f78d99 100644
--- a/PC/msvcrtmodule.c
+++ b/PC/msvcrtmodule.c
@@ -17,6 +17,7 @@
***********************************************************/
#include "Python.h"
+#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
#include "malloc.h"
#include <io.h>
#include <conio.h>
diff --git a/Parser/myreadline.c b/Parser/myreadline.c
index e5e2fb1..b10d306 100644
--- a/Parser/myreadline.c
+++ b/Parser/myreadline.c
@@ -10,6 +10,7 @@
*/
#include "Python.h"
+#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
#include "pycore_pystate.h" // _PyThreadState_GET()
#ifdef MS_WINDOWS
# define WIN32_LEAN_AND_MEAN
diff --git a/Python/traceback.c b/Python/traceback.c
index 3ea1db5..ffa7c34 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -4,11 +4,12 @@
#include "Python.h"
#include "code.h" // PyCode_Addr2Line etc
-#include "pycore_interp.h" // PyInterpreterState.gc
#include "frameobject.h" // PyFrame_GetBack()
#include "pycore_ast.h" // asdl_seq_*
#include "pycore_compile.h" // _PyAST_Optimize
+#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
#include "pycore_frame.h" // _PyFrame_GetCode()
+#include "pycore_interp.h" // PyInterpreterState.gc
#include "pycore_parser.h" // _PyParser_ASTFromString
#include "pycore_pyarena.h" // _PyArena_Free()
#include "pycore_pyerrors.h" // _PyErr_Fetch()
@@ -17,7 +18,7 @@
#include "structmember.h" // PyMemberDef
#include "osdefs.h" // SEP
#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
+# include <fcntl.h>
#endif
#define OFF(x) offsetof(PyTracebackObject, x)