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

Skip to content

Commit 6ca130d

Browse files
committed
Oops. The PyObject_Print() function was totally broken; the original code
was relying on PyString.tp_print but that no longer works. Fortunately it's rarely called; only the gdb 'pyo' command seems affected.
1 parent 66aaf74 commit 6ca130d

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

Objects/object.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,28 @@ internal_print(PyObject *op, FILE *fp, int flags, int nesting)
284284
if (flags & Py_PRINT_RAW)
285285
s = PyObject_Str(op);
286286
else
287-
s = PyObject_ReprStr8(op);
287+
s = PyObject_Repr(op);
288288
if (s == NULL)
289289
ret = -1;
290+
else if (PyString_Check(s)) {
291+
fwrite(PyString_AS_STRING(s), 1,
292+
PyString_GET_SIZE(s), fp);
293+
}
294+
else if (PyUnicode_Check(s)) {
295+
PyObject *t;
296+
t = _PyUnicode_AsDefaultEncodedString(s, NULL);
297+
if (t == NULL)
298+
ret = 0;
299+
else {
300+
fwrite(PyString_AS_STRING(t), 1,
301+
PyString_GET_SIZE(t), fp);
302+
}
303+
}
290304
else {
291-
ret = internal_print(s, fp, Py_PRINT_RAW,
292-
nesting+1);
305+
PyErr_Format(PyExc_TypeError,
306+
"str() or repr() returned '%.100s'",
307+
s->ob_type->tp_name);
308+
ret = -1;
293309
}
294310
Py_XDECREF(s);
295311
}

0 commit comments

Comments
 (0)