@@ -698,30 +698,31 @@ _Py_HandleSystemExit(int *exitcode_p)
698
698
return 0 ;
699
699
}
700
700
701
- PyObject * exception , * value , * tb ;
702
- PyErr_Fetch (& exception , & value , & tb );
703
-
704
701
fflush (stdout );
705
702
706
703
int exitcode = 0 ;
707
- if (value == NULL || value == Py_None ) {
704
+
705
+ PyObject * exc = PyErr_GetRaisedException ();
706
+ assert (exc != Py_None );
707
+ if (exc == NULL ) {
708
708
goto done ;
709
709
}
710
710
711
- if (PyExceptionInstance_Check (value )) {
712
- /* The error code should be in the `code' attribute. */
713
- PyObject * code = PyObject_GetAttr (value , & _Py_ID (code ));
714
- if (code ) {
715
- Py_SETREF (value , code );
716
- if (value == Py_None )
717
- goto done ;
711
+ assert (PyExceptionInstance_Check (exc ));
712
+ /* The error code should be in the `code' attribute. */
713
+ PyObject * code = PyObject_GetAttr (exc , & _Py_ID (code ));
714
+ if (code ) {
715
+ Py_SETREF (exc , code );
716
+ if (exc == Py_None ) {
717
+ goto done ;
718
718
}
719
- /* If we failed to dig out the 'code' attribute,
720
- just let the else clause below print the error. */
721
719
}
720
+ /* If we failed to dig out the 'code' attribute,
721
+ * just let the else clause below print the error.
722
+ */
722
723
723
- if (PyLong_Check (value )) {
724
- exitcode = (int )PyLong_AsLong (value );
724
+ if (PyLong_Check (exc )) {
725
+ exitcode = (int )PyLong_AsLong (exc );
725
726
}
726
727
else {
727
728
PyThreadState * tstate = _PyThreadState_GET ();
@@ -732,20 +733,17 @@ _Py_HandleSystemExit(int *exitcode_p)
732
733
*/
733
734
PyErr_Clear ();
734
735
if (sys_stderr != NULL && sys_stderr != Py_None ) {
735
- PyFile_WriteObject (value , sys_stderr , Py_PRINT_RAW );
736
+ PyFile_WriteObject (exc , sys_stderr , Py_PRINT_RAW );
736
737
} else {
737
- PyObject_Print (value , stderr , Py_PRINT_RAW );
738
+ PyObject_Print (exc , stderr , Py_PRINT_RAW );
738
739
fflush (stderr );
739
740
}
740
741
PySys_WriteStderr ("\n" );
741
742
exitcode = 1 ;
742
743
}
743
744
744
- done :
745
- /* Cleanup the exception */
746
- Py_CLEAR (exception );
747
- Py_CLEAR (value );
748
- Py_CLEAR (tb );
745
+ done :
746
+ Py_CLEAR (exc );
749
747
* exitcode_p = exitcode ;
750
748
return 1 ;
751
749
}
0 commit comments