Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 43525:b9d19d51de36
get rid of some more PyString uses.
Only the filename is still a PyString now.
(We'll need to deal with the default filesystem encoding to do it right.)
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 10 Oct 2007 21:38:59 +0000 |
| parents | 38f3f9ef193d |
| children | 19319e70fc3e |
comparison
equal
deleted
inserted
replaced
| 43524:2f30bfb7c738 | 43525:b9d19d51de36 |
|---|---|
| 760 return -1; | 760 return -1; |
| 761 enc = PyUnicode_AsString(oenc); | 761 enc = PyUnicode_AsString(oenc); |
| 762 } | 762 } |
| 763 v = PySys_GetObject("ps1"); | 763 v = PySys_GetObject("ps1"); |
| 764 if (v != NULL) { | 764 if (v != NULL) { |
| 765 v = PyObject_Str(v); | 765 v = PyObject_Unicode(v); |
| 766 if (v == NULL) | 766 if (v == NULL) |
| 767 PyErr_Clear(); | 767 PyErr_Clear(); |
| 768 else if (PyString_Check(v)) | 768 else if (PyUnicode_Check(v)) |
| 769 ps1 = PyString_AsString(v); | 769 ps1 = PyUnicode_AsString(v); |
| 770 } | 770 } |
| 771 w = PySys_GetObject("ps2"); | 771 w = PySys_GetObject("ps2"); |
| 772 if (w != NULL) { | 772 if (w != NULL) { |
| 773 w = PyObject_Str(w); | 773 w = PyObject_Unicode(w); |
| 774 if (w == NULL) | 774 if (w == NULL) |
| 775 PyErr_Clear(); | 775 PyErr_Clear(); |
| 776 else if (PyString_Check(w)) | 776 else if (PyUnicode_Check(w)) |
| 777 ps2 = PyString_AsString(w); | 777 ps2 = PyUnicode_AsString(w); |
| 778 } | 778 } |
| 779 arena = PyArena_New(); | 779 arena = PyArena_New(); |
| 780 if (arena == NULL) { | 780 if (arena == NULL) { |
| 781 Py_XDECREF(v); | 781 Py_XDECREF(v); |
| 782 Py_XDECREF(w); | 782 Py_XDECREF(w); |
| 977 | 977 |
| 978 if (!(v = PyObject_GetAttrString(err, "text"))) | 978 if (!(v = PyObject_GetAttrString(err, "text"))) |
| 979 goto finally; | 979 goto finally; |
| 980 if (v == Py_None) | 980 if (v == Py_None) |
| 981 *text = NULL; | 981 *text = NULL; |
| 982 else if (! (*text = PyString_AsString(v))) | 982 else if (!PyUnicode_Check(v) || |
| 983 !(*text = PyUnicode_AsString(v))) | |
| 983 goto finally; | 984 goto finally; |
| 984 Py_DECREF(v); | 985 Py_DECREF(v); |
| 985 return 1; | 986 return 1; |
| 986 | 987 |
| 987 finally: | 988 finally: |
| 1091 return; | 1092 return; |
| 1092 /* Now we know v != NULL too */ | 1093 /* Now we know v != NULL too */ |
| 1093 if (set_sys_last_vars) { | 1094 if (set_sys_last_vars) { |
| 1094 PySys_SetObject("last_type", exception); | 1095 PySys_SetObject("last_type", exception); |
| 1095 PySys_SetObject("last_value", v); | 1096 PySys_SetObject("last_value", v); |
| 1096 PySys_SetObject("last_traceback", tb); | 1097 PySys_SetObject("last_traceback", tb ? tb : Py_None); |
| 1097 } | 1098 } |
| 1098 hook = PySys_GetObject("excepthook"); | 1099 hook = PySys_GetObject("excepthook"); |
| 1099 if (hook) { | 1100 if (hook) { |
| 1100 PyObject *args = PyTuple_Pack(3, | 1101 PyObject *args = PyTuple_Pack(3, |
| 1101 exception, v, tb ? tb : Py_None); | 1102 exception, v, tb ? tb : Py_None); |
| 1193 if (dot != NULL) | 1194 if (dot != NULL) |
| 1194 className = dot+1; | 1195 className = dot+1; |
| 1195 } | 1196 } |
| 1196 | 1197 |
| 1197 moduleName = PyObject_GetAttrString(exception, "__module__"); | 1198 moduleName = PyObject_GetAttrString(exception, "__module__"); |
| 1198 if (moduleName == NULL) | 1199 if (moduleName == NULL || !PyUnicode_Check(moduleName)) |
| 1200 { | |
| 1201 Py_DECREF(moduleName); | |
| 1199 err = PyFile_WriteString("<unknown>", f); | 1202 err = PyFile_WriteString("<unknown>", f); |
| 1203 } | |
| 1200 else { | 1204 else { |
| 1201 char* modstr = PyString_AsString(moduleName); | 1205 char* modstr = PyUnicode_AsString(moduleName); |
| 1202 if (modstr && strcmp(modstr, "__builtin__")) | 1206 if (modstr && strcmp(modstr, "__builtin__")) |
| 1203 { | 1207 { |
| 1204 err = PyFile_WriteString(modstr, f); | 1208 err = PyFile_WriteString(modstr, f); |
| 1205 err += PyFile_WriteString(".", f); | 1209 err += PyFile_WriteString(".", f); |
| 1206 } | 1210 } |
| 1214 } | 1218 } |
| 1215 } | 1219 } |
| 1216 else | 1220 else |
| 1217 err = PyFile_WriteObject(exception, f, Py_PRINT_RAW); | 1221 err = PyFile_WriteObject(exception, f, Py_PRINT_RAW); |
| 1218 if (err == 0 && (value != Py_None)) { | 1222 if (err == 0 && (value != Py_None)) { |
| 1219 PyObject *s = PyObject_Str(value); | 1223 PyObject *s = PyObject_Unicode(value); |
| 1220 /* only print colon if the str() of the | 1224 /* only print colon if the str() of the |
| 1221 object is not the empty string | 1225 object is not the empty string |
| 1222 */ | 1226 */ |
| 1223 if (s == NULL) | 1227 if (s == NULL) |
| 1224 err = -1; | 1228 err = -1; |
| 1225 else if (!PyString_Check(s) || | 1229 else if (!PyUnicode_Check(s) || |
| 1226 PyString_GET_SIZE(s) != 0) | 1230 PyUnicode_GetSize(s) != 0) |
| 1227 err = PyFile_WriteString(": ", f); | 1231 err = PyFile_WriteString(": ", f); |
| 1228 if (err == 0) | 1232 if (err == 0) |
| 1229 err = PyFile_WriteObject(s, f, Py_PRINT_RAW); | 1233 err = PyFile_WriteObject(s, f, Py_PRINT_RAW); |
| 1230 Py_XDECREF(s); | 1234 Py_XDECREF(s); |
| 1231 } | 1235 } |
| 1528 break; | 1532 break; |
| 1529 case E_DECODE: { | 1533 case E_DECODE: { |
| 1530 PyObject *type, *value, *tb; | 1534 PyObject *type, *value, *tb; |
| 1531 PyErr_Fetch(&type, &value, &tb); | 1535 PyErr_Fetch(&type, &value, &tb); |
| 1532 if (value != NULL) { | 1536 if (value != NULL) { |
| 1533 u = PyObject_Str(value); | 1537 u = PyObject_Unicode(value); |
| 1534 if (u != NULL) { | 1538 if (u != NULL) { |
| 1535 msg = PyString_AsString(u); | 1539 msg = PyUnicode_AsString(u); |
| 1536 } | 1540 } |
| 1537 } | 1541 } |
| 1538 if (msg == NULL) | 1542 if (msg == NULL) |
| 1539 msg = "unknown decode error"; | 1543 msg = "unknown decode error"; |
| 1540 Py_XDECREF(type); | 1544 Py_XDECREF(type); |
