summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-09-03 14:20:01 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-09-03 14:20:01 (GMT)
commitfbb215cb2411385783b9b347870c84f1041c2a1a (patch)
treee770d3b1347c627db47225e4c7e7a9d4302736c7 /Python
parent304d528715865704171df94129ccae1488ab271f (diff)
parent38b8ae0f5b8a6165fbbfc5798e8a3067234af261 (diff)
downloadcpython-fbb215cb2411385783b9b347870c84f1041c2a1a.zip
cpython-fbb215cb2411385783b9b347870c84f1041c2a1a.tar.gz
cpython-fbb215cb2411385783b9b347870c84f1041c2a1a.tar.bz2
Merge 3.5 (namereplace)
Diffstat (limited to 'Python')
-rw-r--r--Python/codecs.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/Python/codecs.c b/Python/codecs.c
index 596bd80..d90bf73 100644
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -966,7 +966,6 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
}
static _PyUnicode_Name_CAPI *ucnhash_CAPI = NULL;
-static int ucnhash_initialized = 0;
PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
{
@@ -988,17 +987,17 @@ PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
return NULL;
if (!(object = PyUnicodeEncodeError_GetObject(exc)))
return NULL;
- if (!ucnhash_initialized) {
+ if (!ucnhash_CAPI) {
/* load the unicode data module */
ucnhash_CAPI = (_PyUnicode_Name_CAPI *)PyCapsule_Import(
PyUnicodeData_CAPSULE_NAME, 1);
- ucnhash_initialized = 1;
+ if (!ucnhash_CAPI)
+ return NULL;
}
for (i = start, ressize = 0; i < end; ++i) {
/* object is guaranteed to be "ready" */
c = PyUnicode_READ_CHAR(object, i);
- if (ucnhash_CAPI &&
- ucnhash_CAPI->getname(NULL, c, buffer, sizeof(buffer), 1)) {
+ if (ucnhash_CAPI->getname(NULL, c, buffer, sizeof(buffer), 1)) {
replsize = 1+1+1+(int)strlen(buffer)+1;
}
else if (c >= 0x10000) {
@@ -1021,8 +1020,7 @@ PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
i < end; ++i) {
c = PyUnicode_READ_CHAR(object, i);
*outp++ = '\\';
- if (ucnhash_CAPI &&
- ucnhash_CAPI->getname(NULL, c, buffer, sizeof(buffer), 1)) {
+ if (ucnhash_CAPI->getname(NULL, c, buffer, sizeof(buffer), 1)) {
*outp++ = 'N';
*outp++ = '{';
strcpy((char *)outp, buffer);