Skip to content

Commit 97308df

Browse files
authored
bpo-45434: Move _Py_BEGIN_SUPPRESS_IPH to pycore_fileutils.h (pythonGH-28922)
1 parent 7cdc2a0 commit 97308df

File tree

10 files changed

+44
-42
lines changed

10 files changed

+44
-42
lines changed

Include/internal/pycore_fileutils.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@ extern int _Py_add_relfile(wchar_t *dirname,
8080
const wchar_t *relfile,
8181
size_t bufsize);
8282

83+
// Macros to protect CRT calls against instant termination when passed an
84+
// invalid parameter (bpo-23524). IPH stands for Invalid Parameter Handler.
85+
// Usage:
86+
//
87+
// _Py_BEGIN_SUPPRESS_IPH
88+
// ...
89+
// _Py_END_SUPPRESS_IPH
90+
#if defined _MSC_VER && _MSC_VER >= 1900
91+
extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
92+
# define _Py_BEGIN_SUPPRESS_IPH \
93+
{ _invalid_parameter_handler _Py_old_handler = \
94+
_set_thread_local_invalid_parameter_handler(_Py_silent_invalid_parameter_handler);
95+
# define _Py_END_SUPPRESS_IPH \
96+
_set_thread_local_invalid_parameter_handler(_Py_old_handler); }
97+
#else
98+
# define _Py_BEGIN_SUPPRESS_IPH
99+
# define _Py_END_SUPPRESS_IPH
100+
#endif /* _MSC_VER >= 1900 */
101+
83102
#ifdef __cplusplus
84103
}
85104
#endif

Include/pyport.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -712,26 +712,6 @@ extern char * _getpty(int *, int, mode_t, int);
712712
# define PY_LITTLE_ENDIAN 1
713713
#endif
714714

715-
#ifdef Py_BUILD_CORE
716-
/*
717-
* Macros to protect CRT calls against instant termination when passed an
718-
* invalid parameter (issue23524).
719-
*/
720-
#if defined _MSC_VER && _MSC_VER >= 1900
721-
722-
extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
723-
#define _Py_BEGIN_SUPPRESS_IPH { _invalid_parameter_handler _Py_old_handler = \
724-
_set_thread_local_invalid_parameter_handler(_Py_silent_invalid_parameter_handler);
725-
#define _Py_END_SUPPRESS_IPH _set_thread_local_invalid_parameter_handler(_Py_old_handler); }
726-
727-
#else
728-
729-
#define _Py_BEGIN_SUPPRESS_IPH
730-
#define _Py_END_SUPPRESS_IPH
731-
732-
#endif /* _MSC_VER >= 1900 */
733-
#endif /* Py_BUILD_CORE */
734-
735715
#ifdef __ANDROID__
736716
/* The Android langinfo.h header is not used. */
737717
# undef HAVE_LANGINFO_H

Modules/_io/fileio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
#define PY_SSIZE_T_CLEAN
44
#include "Python.h"
5-
#include "pycore_object.h"
5+
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
6+
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
67
#include "structmember.h" // PyMemberDef
78
#include <stdbool.h>
89
#ifdef HAVE_SYS_TYPES_H

Modules/_io/winconsoleio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
#define PY_SSIZE_T_CLEAN
1010
#include "Python.h"
11-
#include "pycore_object.h"
11+
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
12+
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
1213

1314
#ifdef MS_WINDOWS
1415

Modules/signalmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "pycore_atomic.h" // _Py_atomic_int
88
#include "pycore_call.h" // _PyObject_Call()
99
#include "pycore_ceval.h" // _PyEval_SignalReceived()
10+
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
1011
#include "pycore_frame.h" // InterpreterFrame
1112
#include "pycore_moduleobject.h" // _PyModule_GetState()
1213
#include "pycore_pyerrors.h" // _PyErr_SetString()

Modules/timemodule.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
11
/* Time module */
22

33
#include "Python.h"
4+
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
45

56
#include <ctype.h>
67

78
#ifdef HAVE_SYS_TIMES_H
8-
#include <sys/times.h>
9+
# include <sys/times.h>
910
#endif
10-
1111
#ifdef HAVE_SYS_TYPES_H
12-
#include <sys/types.h>
12+
# include <sys/types.h>
1313
#endif
14-
1514
#if defined(HAVE_SYS_RESOURCE_H)
16-
#include <sys/resource.h>
15+
# include <sys/resource.h>
1716
#endif
18-
1917
#ifdef QUICKWIN
20-
#include <io.h>
18+
# include <io.h>
2119
#endif
22-
2320
#if defined(HAVE_PTHREAD_H)
2421
# include <pthread.h>
2522
#endif
26-
2723
#if defined(_AIX)
2824
# include <sys/thread.h>
2925
#endif
30-
3126
#if defined(__WATCOMC__) && !defined(__QNX__)
3227
# include <i86.h>
3328
#else
@@ -38,17 +33,17 @@
3833
#endif /* !__WATCOMC__ || __QNX__ */
3934

4035
#ifdef _Py_MEMORY_SANITIZER
41-
# include <sanitizer/msan_interface.h>
36+
# include <sanitizer/msan_interface.h>
4237
#endif
4338

4439
#ifdef _MSC_VER
45-
#define _Py_timezone _timezone
46-
#define _Py_daylight _daylight
47-
#define _Py_tzname _tzname
40+
# define _Py_timezone _timezone
41+
# define _Py_daylight _daylight
42+
# define _Py_tzname _tzname
4843
#else
49-
#define _Py_timezone timezone
50-
#define _Py_daylight daylight
51-
#define _Py_tzname tzname
44+
# define _Py_timezone timezone
45+
# define _Py_daylight daylight
46+
# define _Py_tzname tzname
5247
#endif
5348

5449
#if defined(__APPLE__ ) && defined(__has_builtin)
@@ -60,8 +55,10 @@
6055
# define HAVE_CLOCK_GETTIME_RUNTIME 1
6156
#endif
6257

58+
6359
#define SEC_TO_NS (1000 * 1000 * 1000)
6460

61+
6562
/* Forward declarations */
6663
static int pysleep(_PyTime_t timeout);
6764

PC/getpathp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@
8080

8181

8282
#include "Python.h"
83+
#include "pycore_fileutils.h" // _Py_add_relfile()
8384
#include "pycore_initconfig.h" // PyStatus
8485
#include "pycore_pathconfig.h" // _PyPathConfig
85-
#include "pycore_fileutils.h" // _Py_add_relfile()
8686
#include "osdefs.h" // SEP, ALTSEP
8787
#include <wchar.h>
8888

PC/msvcrtmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
***********************************************************/
1818

1919
#include "Python.h"
20+
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
2021
#include "malloc.h"
2122
#include <io.h>
2223
#include <conio.h>

Parser/myreadline.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
#include "Python.h"
13+
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
1314
#include "pycore_pystate.h" // _PyThreadState_GET()
1415
#ifdef MS_WINDOWS
1516
# define WIN32_LEAN_AND_MEAN

Python/traceback.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
#include "Python.h"
55

66
#include "code.h" // PyCode_Addr2Line etc
7-
#include "pycore_interp.h" // PyInterpreterState.gc
87
#include "frameobject.h" // PyFrame_GetBack()
98
#include "pycore_ast.h" // asdl_seq_*
109
#include "pycore_compile.h" // _PyAST_Optimize
10+
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
1111
#include "pycore_frame.h" // _PyFrame_GetCode()
12+
#include "pycore_interp.h" // PyInterpreterState.gc
1213
#include "pycore_parser.h" // _PyParser_ASTFromString
1314
#include "pycore_pyarena.h" // _PyArena_Free()
1415
#include "pycore_pyerrors.h" // _PyErr_Fetch()
@@ -17,7 +18,7 @@
1718
#include "structmember.h" // PyMemberDef
1819
#include "osdefs.h" // SEP
1920
#ifdef HAVE_FCNTL_H
20-
#include <fcntl.h>
21+
# include <fcntl.h>
2122
#endif
2223

2324
#define OFF(x) offsetof(PyTracebackObject, x)

0 commit comments

Comments
 (0)