comparison Python/errors.c @ 41878:089f449a20cd

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.
author Walter Dörwald <walter@livinglogic.de>
date Fri, 25 May 2007 15:46:59 +0000
parents b29d71d43c80
children 854cc4d5a33d
comparison
equal deleted inserted replaced
41877:1ec1afa2bdb5 41878:089f449a20cd
52 void 52 void
53 PyErr_SetObject(PyObject *exception, PyObject *value) 53 PyErr_SetObject(PyObject *exception, PyObject *value)
54 { 54 {
55 if (exception != NULL && 55 if (exception != NULL &&
56 !PyExceptionClass_Check(exception)) { 56 !PyExceptionClass_Check(exception)) {
57 PyObject *excstr = PyObject_ReprStr8(exception);
58 PyErr_Format(PyExc_SystemError, 57 PyErr_Format(PyExc_SystemError,
59 "exception %s not a BaseException subclass", 58 "exception %R not a BaseException subclass",
60 PyString_AS_STRING(excstr)); 59 exception);
61 Py_DECREF(excstr);
62 return; 60 return;
63 } 61 }
64 Py_XINCREF(exception); 62 Py_XINCREF(exception);
65 Py_XINCREF(value); 63 Py_XINCREF(value);
66 PyErr_Restore(exception, value, (PyObject *)NULL); 64 PyErr_Restore(exception, value, (PyObject *)NULL);
73 } 71 }
74 72
75 void 73 void
76 PyErr_SetString(PyObject *exception, const char *string) 74 PyErr_SetString(PyObject *exception, const char *string)
77 { 75 {
78 PyObject *value = PyString_FromString(string); 76 PyObject *value = PyUnicode_FromString(string);
79 PyErr_SetObject(exception, value); 77 PyErr_SetObject(exception, value);
80 Py_XDECREF(value); 78 Py_XDECREF(value);
81 } 79 }
82 80
83 81
526 va_start(vargs, format); 524 va_start(vargs, format);
527 #else 525 #else
528 va_start(vargs); 526 va_start(vargs);
529 #endif 527 #endif
530 528
531 string = PyString_FromFormatV(format, vargs); 529 string = PyUnicode_FromFormatV(format, vargs);
532 PyErr_SetObject(exception, string); 530 PyErr_SetObject(exception, string);
533 Py_XDECREF(string); 531 Py_XDECREF(string);
534 va_end(vargs); 532 va_end(vargs);
535 return NULL; 533 return NULL;
536 } 534 }