summaryrefslogtreecommitdiffstats
path: root/Python/codecs.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-11-04 20:36:35 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-11-04 20:36:35 (GMT)
commitc06bb7affd231021fae09ddeba64b2a54d2c9e34 (patch)
tree42b5eca298f8a8abd7084d2331780691c06bbed7 /Python/codecs.c
parentb31f1bcd9901c41931bd7c9898f1181ecd2f6b36 (diff)
downloadcpython-c06bb7affd231021fae09ddeba64b2a54d2c9e34.zip
cpython-c06bb7affd231021fae09ddeba64b2a54d2c9e34.tar.gz
cpython-c06bb7affd231021fae09ddeba64b2a54d2c9e34.tar.bz2
Avoid the Py_UNICODE type in codecs.c
Diffstat (limited to 'Python/codecs.c')
-rw-r--r--Python/codecs.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/Python/codecs.c b/Python/codecs.c
index 07fe2ee..cdf2c44 100644
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -778,7 +778,7 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
}
else if (PyObject_IsInstance(exc, PyExc_UnicodeDecodeError)) {
unsigned char *p;
- Py_UNICODE ch = 0;
+ Py_UCS4 ch = 0;
if (PyUnicodeDecodeError_GetStart(exc, &start))
return NULL;
if (!(object = PyUnicodeDecodeError_GetObject(exc)))
@@ -804,7 +804,10 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
PyErr_SetObject(PyExceptionInstance_Class(exc), exc);
return NULL;
}
- return Py_BuildValue("(u#n)", &ch, 1, start+3);
+ res = PyUnicode_FromOrdinal(ch);
+ if (res == NULL)
+ return NULL;
+ return Py_BuildValue("(Nn)", res, start+3);
}
else {
wrong_exception_type(exc);
@@ -853,8 +856,9 @@ PyCodec_SurrogateEscapeErrors(PyObject *exc)
return restuple;
}
else if (PyObject_IsInstance(exc, PyExc_UnicodeDecodeError)) {
+ PyObject *str;
unsigned char *p;
- Py_UNICODE ch[4]; /* decode up to 4 bad bytes. */
+ Py_UCS2 ch[4]; /* decode up to 4 bad bytes. */
int consumed = 0;
if (PyUnicodeDecodeError_GetStart(exc, &start))
return NULL;
@@ -879,7 +883,10 @@ PyCodec_SurrogateEscapeErrors(PyObject *exc)
PyErr_SetObject(PyExceptionInstance_Class(exc), exc);
return NULL;
}
- return Py_BuildValue("(u#n)", ch, consumed, start+consumed);
+ str = PyUnicode_FromKindAndData(PyUnicode_2BYTE_KIND, ch, consumed);
+ if (str == NULL)
+ return NULL;
+ return Py_BuildValue("(Nn)", str, start+consumed);
}
else {
wrong_exception_type(exc);