This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients JelleZijlstra, benjamin.peterson, corona10, db3l, eryksun, remi.lapeyre, serhiy.storchaka, stutzbach, vstinner
Date 2020-06-04.17:59:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1591293585.72.0.692593090332.issue40826@roundup.psfhosted.org>
In-reply-to
Content
> The purpose of _Py_BEGIN_SUPPRESS_IPH is to suppress such popup, no?

That macro suppresses the CRT's invalid parameter handler, which by default  terminates abnormally with a fastfail (status code 0xC0000409), even in a release build. 

In a debug build, we still have message boxes from failed asserts that call _CrtDbgReportW. For example, the following stack trace shows _CrtDbgReportW called from _get_osfhandle:

    Call Site
    win32u!NtUserWaitMessage
    user32!DialogBox2
    user32!InternalDialogBox
    user32!SoftModalMessageBox
    user32!MessageBoxWorker
    user32!MessageBoxTimeoutW
    user32!MessageBoxW
    ucrtbased!__acrt_MessageBoxW
    ucrtbased!__crt_char_traits<wchar_t>::message_box<HWND__ * __ptr64,
                        wchar_t const * __ptr64 const & __ptr64,
                        wchar_t const * __ptr64 const & __ptr64,
                        unsigned int const & __ptr64>
    ucrtbased!common_show_message_box<wchar_t>
    ucrtbased!__acrt_show_wide_message_box
    ucrtbased!common_message_window<wchar_t>
    ucrtbased!__acrt_MessageWindowW
    ucrtbased!_VCrtDbgReportW
    ucrtbased!_CrtDbgReportW
    ucrtbased!_get_osfhandle
    python310_d!PyOS_StdioReadline

_get_osfhandle validates that the fd is open via

    _VALIDATE_CLEAR_OSSERR_RETURN(_osfile(fh) & FOPEN, EBADF, -1);

which uses the following macro:

    #define _VALIDATE_CLEAR_OSSERR_RETURN(expr, errorcode, retexpr)                \
        {                                                                          \
            int _Expr_val=!!(expr);                                                \
            _ASSERT_EXPR((_Expr_val), _CRT_WIDE(#expr));                           \
            if (!(_Expr_val))                                                      \
            {                                                                      \
                _doserrno = 0L;                                                    \
                errno = errorcode;                                                 \
                _INVALID_PARAMETER(_CRT_WIDE(#expr));                              \
                return retexpr;                                                    \
            }                                                                      \
        }

In a debug build, _ASSERT_EXPR expands as:

    #define _ASSERT_EXPR(expr, msg) \
        (void)(                                                                                     \
            (!!(expr)) ||                                                                           \
            (1 != _CrtDbgReportW(_CRT_ASSERT, _CRT_WIDE(__FILE__), __LINE__, NULL, L"%ls", msg)) || \
            (_CrtDbgBreak(), 0)                                                                     \
        )

which is where _CrtDbgReportW gets called. By default it reports the assertion failure with a message box. The suppression of this in libregrtest either ignores this report or sends it to stderr:

    for m in [msvcrt.CRT_WARN, msvcrt.CRT_ERROR, msvcrt.CRT_ASSERT]:
        if verbose:
            msvcrt.CrtSetReportMode(m, msvcrt.CRTDBG_MODE_FILE)
            msvcrt.CrtSetReportFile(m, msvcrt.CRTDBG_FILE_STDERR)
        else:
            msvcrt.CrtSetReportMode(m, 0)

msvcrt.CrtSetReportMode and msvcrt.CrtSetReportFile only exist in a debug build.
History
Date User Action Args
2020-06-04 17:59:45eryksunsetrecipients: + eryksun, db3l, vstinner, benjamin.peterson, stutzbach, serhiy.storchaka, JelleZijlstra, corona10, remi.lapeyre
2020-06-04 17:59:45eryksunsetmessageid: <1591293585.72.0.692593090332.issue40826@roundup.psfhosted.org>
2020-06-04 17:59:45eryksunlinkissue40826 messages
2020-06-04 17:59:45eryksuncreate