comparison Python/pythonrun.c @ 17212:215dc725db84 legacy-trunk

Finishing touch to Ping's changes. This is a patch that Ping sent me but apparently he had to go to school, so I am checking it in for him. This makes PyRun_HandleSystemExit() a static instead, called handle_system_exit(), and let it use the current exception rather than passing in an exception. This slightly simplifies the code.
author Guido van Rossum <guido@python.org>
date Fri, 23 Mar 2001 17:54:43 +0000
parents 16f145aac2ec
children 32fb6643adf1
comparison
equal deleted inserted replaced
17211:64876bb8aacd 17212:215dc725db84
796 offset--; 796 offset--;
797 } 797 }
798 PyFile_WriteString("^\n", f); 798 PyFile_WriteString("^\n", f);
799 } 799 }
800 800
801 void 801 static void
802 PyRun_HandleSystemExit(PyObject* value) 802 handle_system_exit(void)
803 { 803 {
804 PyObject *exception, *value, *tb;
805 PyErr_Fetch(&exception, &value, &tb);
804 if (Py_FlushLine()) 806 if (Py_FlushLine())
805 PyErr_Clear(); 807 PyErr_Clear();
806 fflush(stdout); 808 fflush(stdout);
807 if (value == NULL || value == Py_None) 809 if (value == NULL || value == Py_None)
808 Py_Exit(0); 810 Py_Exit(0);
829 831
830 void 832 void
831 PyErr_PrintEx(int set_sys_last_vars) 833 PyErr_PrintEx(int set_sys_last_vars)
832 { 834 {
833 PyObject *exception, *v, *tb, *hook; 835 PyObject *exception, *v, *tb, *hook;
836
837 if (PyErr_ExceptionMatches(PyExc_SystemExit)) {
838 handle_system_exit();
839 }
834 PyErr_Fetch(&exception, &v, &tb); 840 PyErr_Fetch(&exception, &v, &tb);
835 PyErr_NormalizeException(&exception, &v, &tb); 841 PyErr_NormalizeException(&exception, &v, &tb);
836
837 if (exception == NULL) 842 if (exception == NULL)
838 return; 843 return;
839
840 if (PyErr_GivenExceptionMatches(exception, PyExc_SystemExit)) {
841 PyRun_HandleSystemExit(v);
842 }
843 if (set_sys_last_vars) { 844 if (set_sys_last_vars) {
844 PySys_SetObject("last_type", exception); 845 PySys_SetObject("last_type", exception);
845 PySys_SetObject("last_value", v); 846 PySys_SetObject("last_value", v);
846 PySys_SetObject("last_traceback", tb); 847 PySys_SetObject("last_traceback", tb);
847 } 848 }
850 PyObject *args = Py_BuildValue("(OOO)", 851 PyObject *args = Py_BuildValue("(OOO)",
851 exception, v ? v : Py_None, tb ? tb : Py_None); 852 exception, v ? v : Py_None, tb ? tb : Py_None);
852 PyObject *result = PyEval_CallObject(hook, args); 853 PyObject *result = PyEval_CallObject(hook, args);
853 if (result == NULL) { 854 if (result == NULL) {
854 PyObject *exception2, *v2, *tb2; 855 PyObject *exception2, *v2, *tb2;
856 if (PyErr_ExceptionMatches(PyExc_SystemExit)) {
857 handle_system_exit();
858 }
855 PyErr_Fetch(&exception2, &v2, &tb2); 859 PyErr_Fetch(&exception2, &v2, &tb2);
856 PyErr_NormalizeException(&exception2, &v2, &tb2); 860 PyErr_NormalizeException(&exception2, &v2, &tb2);
857 if (PyErr_GivenExceptionMatches(
858 exception2, PyExc_SystemExit)) {
859 PyRun_HandleSystemExit(v2);
860 }
861 if (Py_FlushLine()) 861 if (Py_FlushLine())
862 PyErr_Clear(); 862 PyErr_Clear();
863 fflush(stdout); 863 fflush(stdout);
864 PySys_WriteStderr("Error in sys.excepthook:\n"); 864 PySys_WriteStderr("Error in sys.excepthook:\n");
865 PyErr_Display(exception2, v2, tb2); 865 PyErr_Display(exception2, v2, tb2);