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.
This commit is contained in:
Walter Dörwald 2007-05-25 15:46:59 +00:00
parent e65c86cca0
commit 573c08c1b7
5 changed files with 33 additions and 45 deletions

View file

@ -54,11 +54,9 @@ PyErr_SetObject(PyObject *exception, PyObject *value)
{
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 @@ PyErr_SetNone(PyObject *exception)
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 @@ PyErr_Format(PyObject *exception, const char *format, ...)
va_start(vargs);
#endif
string = PyString_FromFormatV(format, vargs);
string = PyUnicode_FromFormatV(format, vargs);
PyErr_SetObject(exception, string);
Py_XDECREF(string);
va_end(vargs);