Skip to content

bpo-45434: Move _Py_BEGIN_SUPPRESS_IPH to pycore_fileutils.h #28922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Include/internal/pycore_fileutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions Include/pyport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Modules/_io/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Modules/_io/winconsoleio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
31 changes: 14 additions & 17 deletions Modules/timemodule.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion PC/getpathp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
1 change: 1 addition & 0 deletions PC/msvcrtmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
***********************************************************/

#include "Python.h"
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
#include "malloc.h"
#include <io.h>
#include <conio.h>
Expand Down
1 change: 1 addition & 0 deletions Parser/myreadline.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions Python/traceback.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down