Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(81033)

Delta Between Two Patch Sets: Python/errors.c

Issue 11619: On Windows, don't encode filenames in the import machinery
Left Patch Set: Created 5 years, 12 months ago
Right Patch Set: Created 5 years, 12 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Python/compile.c ('k') | Python/future.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 1
2 /* Error handling */ 2 /* Error handling */
3 3
4 #include "Python.h" 4 #include "Python.h"
5 5
6 #ifndef __STDC__ 6 #ifndef __STDC__
7 #ifndef MS_WINDOWS 7 #ifndef MS_WINDOWS
8 extern char *strerror(int); 8 extern char *strerror(int);
9 #endif 9 #endif
10 #endif 10 #endif
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 } 818 }
819 819
820 820
821 /* Call when an exception has occurred but there is no way for Python 821 /* Call when an exception has occurred but there is no way for Python
822 to handle it. Examples: exception in __del__ or during GC. */ 822 to handle it. Examples: exception in __del__ or during GC. */
823 void 823 void
824 PyErr_WriteUnraisable(PyObject *obj) 824 PyErr_WriteUnraisable(PyObject *obj)
825 { 825 {
826 _Py_IDENTIFIER(__module__); 826 _Py_IDENTIFIER(__module__);
827 PyObject *f, *t, *v, *tb; 827 PyObject *f, *t, *v, *tb;
828 PyObject *moduleName = NULL;
829 char* className;
830
828 PyErr_Fetch(&t, &v, &tb); 831 PyErr_Fetch(&t, &v, &tb);
832
829 f = PySys_GetObject("stderr"); 833 f = PySys_GetObject("stderr");
830 if (f != NULL && f != Py_None) { 834 if (f == NULL || f == Py_None)
831 if (obj) { 835 goto done;
832 PyFile_WriteString("Exception ignored in: ", f); 836
833 PyFile_WriteObject(obj, f, 0); 837 if (obj) {
834 PyFile_WriteString("\n", f); 838 if (PyFile_WriteString("Exception ignored in: ", f) < 0)
835 } 839 goto done;
836 PyTraceBack_Print(tb, f); 840 if (PyFile_WriteObject(obj, f, 0) < 0)
837 if (t) { 841 goto done;
838 PyObject* moduleName; 842 if (PyFile_WriteString("\n", f) < 0)
839 char* className; 843 goto done;
840 assert(PyExceptionClass_Check(t)); 844 }
841 className = PyExceptionClass_Name(t); 845
842 if (className != NULL) { 846 if (PyTraceBack_Print(tb, f) < 0)
843 char *dot = strrchr(className, '.'); 847 goto done;
844 if (dot != NULL) 848
845 className = dot+1; 849 if (!t)
846 } 850 goto done;
847 851
848 moduleName = _PyObject_GetAttrId(t, &PyId___module__); 852 assert(PyExceptionClass_Check(t));
849 if (moduleName == NULL) 853 className = PyExceptionClass_Name(t);
850 PyFile_WriteString("<unknown>", f); 854 if (className != NULL) {
851 else { 855 char *dot = strrchr(className, '.');
852 char* modstr = _PyUnicode_AsString(moduleName); 856 if (dot != NULL)
853 if (modstr && 857 className = dot+1;
854 strcmp(modstr, "builtins") != 0) 858 }
855 { 859
856 PyFile_WriteString(modstr, f); 860 moduleName = _PyObject_GetAttrId(t, &PyId___module__);
857 PyFile_WriteString(".", f); 861 if (moduleName == NULL) {
858 } 862 PyErr_Clear();
859 } 863 if (PyFile_WriteString("<unknown>", f) < 0)
860 if (className == NULL) 864 goto done;
861 PyFile_WriteString("<unknown>", f); 865 }
862 else 866 else {
863 PyFile_WriteString(className, f); 867 if (PyUnicode_CompareWithASCIIString(moduleName, "builtins") != 0) {
864 if (v && v != Py_None) { 868 if (PyFile_WriteObject(moduleName, f, Py_PRINT_RAW) < 0)
865 PyFile_WriteString(": ", f); 869 goto done;
866 PyFile_WriteObject(v, f, Py_PRINT_RAW); 870 if (PyFile_WriteString(".", f) < 0)
867 } 871 goto done;
868 PyFile_WriteString("\n", f); 872 }
869 Py_XDECREF(moduleName); 873 }
870 } 874 if (className == NULL) {
871 PyErr_Clear(); /* Just in case */ 875 if (PyFile_WriteString("<unknown>", f) < 0)
872 } 876 goto done;
877 }
878 else {
879 if (PyFile_WriteString(className, f) < 0)
880 goto done;
881 }
882
883 if (v && v != Py_None) {
884 if (PyFile_WriteString(": ", f) < 0)
885 goto done;
886 if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
887 goto done;
888 }
889 if (PyFile_WriteString("\n", f) < 0)
890 goto done;
891
892 done:
893 Py_XDECREF(moduleName);
873 Py_XDECREF(t); 894 Py_XDECREF(t);
874 Py_XDECREF(v); 895 Py_XDECREF(v);
875 Py_XDECREF(tb); 896 Py_XDECREF(tb);
897 PyErr_Clear(); /* Just in case */
876 } 898 }
877 899
878 extern PyObject *PyModule_GetWarningsModule(void); 900 extern PyObject *PyModule_GetWarningsModule(void);
879 901
880 902
881 void 903 void
882 PyErr_SyntaxLocation(const char *filename, int lineno) 904 PyErr_SyntaxLocation(const char *filename, int lineno)
883 { 905 {
884 PyErr_SyntaxLocationEx(filename, lineno, -1); 906 PyErr_SyntaxLocationEx(filename, lineno, -1);
885 } 907 }
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 FILE *fp; 1052 FILE *fp;
1031 if (filename == NULL || lineno <= 0) 1053 if (filename == NULL || lineno <= 0)
1032 return NULL; 1054 return NULL;
1033 fp = _Py_fopen(filename, "r" PY_STDIOTEXTMODE); 1055 fp = _Py_fopen(filename, "r" PY_STDIOTEXTMODE);
1034 return err_programtext(fp, lineno); 1056 return err_programtext(fp, lineno);
1035 } 1057 }
1036 1058
1037 #ifdef __cplusplus 1059 #ifdef __cplusplus
1038 } 1060 }
1039 #endif 1061 #endif
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+