File tree Expand file tree Collapse file tree 3 files changed +36
-3
lines changed
Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -755,6 +755,22 @@ def test_raise_exception(self):
755755 3 ,
756756 name )
757757
758+ @unittest .skipUnless (MS_WINDOWS , 'specific to Windows' )
759+ def test_ignore_exception (self ):
760+ for exc_code in (
761+ 0xE06D7363 , # MSC exception ("Emsc")
762+ 0xE0434352 , # COM Callable Runtime exception ("ECCR")
763+ ):
764+ code = f"""
765+ import faulthandler
766+ faulthandler.enable()
767+ faulthandler._raise_exception({ exc_code } )
768+ """
769+ code = dedent (code )
770+ output , exitcode = self .get_output (code )
771+ self .assertEqual (output , [])
772+ self .assertEqual (exitcode , exc_code )
773+
758774 @unittest .skipUnless (MS_WINDOWS , 'specific to Windows' )
759775 def test_raise_nonfatal_exception (self ):
760776 # These exceptions are not strictly errors. Letting
Original file line number Diff line number Diff line change 1+ On Windows, faulthandler.enable() now ignores MSC and COM exceptions.
Original file line number Diff line number Diff line change @@ -366,16 +366,32 @@ faulthandler_fatal_error(int signum)
366366}
367367
368368#ifdef MS_WINDOWS
369+ static int
370+ faulthandler_ignore_exception (DWORD code )
371+ {
372+ /* bpo-30557: ignore exceptions which are not errors */
373+ if (!(code & 0x80000000 )) {
374+ return 1 ;
375+ }
376+ /* bpo-31701: ignore MSC and COM exceptions
377+ E0000000 + code */
378+ if (code == 0xE06D7363 /* MSC exception ("Emsc") */
379+ || code == 0xE0434352 /* COM Callable Runtime exception ("ECCR") */ ) {
380+ return 1 ;
381+ }
382+ /* Interesting exception: log it with the Python traceback */
383+ return 0 ;
384+ }
385+
369386static LONG WINAPI
370387faulthandler_exc_handler (struct _EXCEPTION_POINTERS * exc_info )
371388{
372389 const int fd = fatal_error .fd ;
373390 DWORD code = exc_info -> ExceptionRecord -> ExceptionCode ;
374391 DWORD flags = exc_info -> ExceptionRecord -> ExceptionFlags ;
375392
376- /* bpo-30557: only log fatal exceptions */
377- if (!(code & 0x80000000 )) {
378- /* call the next exception handler */
393+ if (faulthandler_ignore_exception (code )) {
394+ /* ignore the exception: call the next exception handler */
379395 return EXCEPTION_CONTINUE_SEARCH ;
380396 }
381397
You can’t perform that action at this time.
0 commit comments