Change PyErr_Format() to generate a unicode string (by using
PyUnicode_FromFormatV() instead of PyString_FromFormatV()).
Change calls to PyErr_Format() to benefit from the new format
specifiers: Using %S, object instead of %s, PyString_AS_STRING(object)
with will work with unicode objects too.
diff --git a/Python/errors.c b/Python/errors.c
index 4ef491f..2a84c8d 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -54,11 +54,9 @@
{
if (exception != NULL &&
!PyExceptionClass_Check(exception)) {
- PyObject *excstr = PyObject_ReprStr8(exception);
PyErr_Format(PyExc_SystemError,
- "exception %s not a BaseException subclass",
- PyString_AS_STRING(excstr));
- Py_DECREF(excstr);
+ "exception %R not a BaseException subclass",
+ exception);
return;
}
Py_XINCREF(exception);
@@ -75,7 +73,7 @@
void
PyErr_SetString(PyObject *exception, const char *string)
{
- PyObject *value = PyString_FromString(string);
+ PyObject *value = PyUnicode_FromString(string);
PyErr_SetObject(exception, value);
Py_XDECREF(value);
}
@@ -528,7 +526,7 @@
va_start(vargs);
#endif
- string = PyString_FromFormatV(format, vargs);
+ string = PyUnicode_FromFormatV(format, vargs);
PyErr_SetObject(exception, string);
Py_XDECREF(string);
va_end(vargs);