Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c5724de

Browse files
committed
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.)
1 parent ebe8f8a commit c5724de

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

Python/pythonrun.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -762,19 +762,19 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags
762762
}
763763
v = PySys_GetObject("ps1");
764764
if (v != NULL) {
765-
v = PyObject_Str(v);
765+
v = PyObject_Unicode(v);
766766
if (v == NULL)
767767
PyErr_Clear();
768-
else if (PyString_Check(v))
769-
ps1 = PyString_AsString(v);
768+
else if (PyUnicode_Check(v))
769+
ps1 = PyUnicode_AsString(v);
770770
}
771771
w = PySys_GetObject("ps2");
772772
if (w != NULL) {
773-
w = PyObject_Str(w);
773+
w = PyObject_Unicode(w);
774774
if (w == NULL)
775775
PyErr_Clear();
776-
else if (PyString_Check(w))
777-
ps2 = PyString_AsString(w);
776+
else if (PyUnicode_Check(w))
777+
ps2 = PyUnicode_AsString(w);
778778
}
779779
arena = PyArena_New();
780780
if (arena == NULL) {
@@ -979,7 +979,8 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename,
979979
goto finally;
980980
if (v == Py_None)
981981
*text = NULL;
982-
else if (! (*text = PyString_AsString(v)))
982+
else if (!PyUnicode_Check(v) ||
983+
!(*text = PyUnicode_AsString(v)))
983984
goto finally;
984985
Py_DECREF(v);
985986
return 1;
@@ -1093,7 +1094,7 @@ PyErr_PrintEx(int set_sys_last_vars)
10931094
if (set_sys_last_vars) {
10941095
PySys_SetObject("last_type", exception);
10951096
PySys_SetObject("last_value", v);
1096-
PySys_SetObject("last_traceback", tb);
1097+
PySys_SetObject("last_traceback", tb ? tb : Py_None);
10971098
}
10981099
hook = PySys_GetObject("excepthook");
10991100
if (hook) {
@@ -1195,10 +1196,13 @@ PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
11951196
}
11961197

11971198
moduleName = PyObject_GetAttrString(exception, "__module__");
1198-
if (moduleName == NULL)
1199+
if (moduleName == NULL || !PyUnicode_Check(moduleName))
1200+
{
1201+
Py_DECREF(moduleName);
11991202
err = PyFile_WriteString("<unknown>", f);
1203+
}
12001204
else {
1201-
char* modstr = PyString_AsString(moduleName);
1205+
char* modstr = PyUnicode_AsString(moduleName);
12021206
if (modstr && strcmp(modstr, "__builtin__"))
12031207
{
12041208
err = PyFile_WriteString(modstr, f);
@@ -1216,14 +1220,14 @@ PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
12161220
else
12171221
err = PyFile_WriteObject(exception, f, Py_PRINT_RAW);
12181222
if (err == 0 && (value != Py_None)) {
1219-
PyObject *s = PyObject_Str(value);
1223+
PyObject *s = PyObject_Unicode(value);
12201224
/* only print colon if the str() of the
12211225
object is not the empty string
12221226
*/
12231227
if (s == NULL)
12241228
err = -1;
1225-
else if (!PyString_Check(s) ||
1226-
PyString_GET_SIZE(s) != 0)
1229+
else if (!PyUnicode_Check(s) ||
1230+
PyUnicode_GetSize(s) != 0)
12271231
err = PyFile_WriteString(": ", f);
12281232
if (err == 0)
12291233
err = PyFile_WriteObject(s, f, Py_PRINT_RAW);
@@ -1530,9 +1534,9 @@ err_input(perrdetail *err)
15301534
PyObject *type, *value, *tb;
15311535
PyErr_Fetch(&type, &value, &tb);
15321536
if (value != NULL) {
1533-
u = PyObject_Str(value);
1537+
u = PyObject_Unicode(value);
15341538
if (u != NULL) {
1535-
msg = PyString_AsString(u);
1539+
msg = PyUnicode_AsString(u);
15361540
}
15371541
}
15381542
if (msg == NULL)

0 commit comments

Comments
 (0)