cpython: ac1995b01028 (original) (raw)
Mercurial > cpython
changeset 97625:ac1995b01028 3.5
Issue #24993: Handle import error in namereplace error handler Handle PyCapsule_Import() failure (exception) in PyCodec_NameReplaceErrors(): return immedialty NULL. [#24993]
Victor Stinner victor.stinner@gmail.com | |
---|---|
date | Thu, 03 Sep 2015 16:19:40 +0200 |
parents | abf4acc73b5a |
children | 716e2bc7d41c ef1f5aebe1a6 |
files | Python/codecs.c |
diffstat | 1 files changed, 5 insertions(+), 7 deletions(-)[+] [-] Python/codecs.c 12 |
line wrap: on
line diff
--- a/Python/codecs.c +++ b/Python/codecs.c @@ -966,7 +966,6 @@ PyObject *PyCodec_BackslashReplaceErrors } static _PyUnicode_Name_CAPI *ucnhash_CAPI = NULL; -static int ucnhash_initialized = 0; PyObject *PyCodec_NameReplaceErrors(PyObject *exc) { @@ -988,17 +987,17 @@ PyObject *PyCodec_NameReplaceErrors(PyOb return NULL; if (!(object = PyUnicodeEncodeError_GetObject(exc))) return NULL;
if (!ucnhash_initialized) {[](#l1.15)
if (!ucnhash_CAPI) {[](#l1.16) /* load the unicode data module */[](#l1.17) ucnhash_CAPI = (_PyUnicode_Name_CAPI *)PyCapsule_Import([](#l1.18) PyUnicodeData_CAPSULE_NAME, 1);[](#l1.19)
ucnhash_initialized = 1;[](#l1.20)
if (!ucnhash_CAPI)[](#l1.21)
return NULL;[](#l1.22) }[](#l1.23) for (i = start, ressize = 0; i < end; ++i) {[](#l1.24) /* object is guaranteed to be "ready" */[](#l1.25) c = PyUnicode_READ_CHAR(object, i);[](#l1.26)
if (ucnhash_CAPI &&[](#l1.27)
ucnhash_CAPI->getname(NULL, c, buffer, sizeof(buffer), 1)) {[](#l1.28)
if (ucnhash_CAPI->getname(NULL, c, buffer, sizeof(buffer), 1)) {[](#l1.29) replsize = 1+1+1+(int)strlen(buffer)+1;[](#l1.30) }[](#l1.31) else if (c >= 0x10000) {[](#l1.32)
@@ -1021,8 +1020,7 @@ PyObject *PyCodec_NameReplaceErrors(PyOb i < end; ++i) { c = PyUnicode_READ_CHAR(object, i); *outp++ = '\';
if (ucnhash_CAPI &&[](#l1.37)
ucnhash_CAPI->getname(NULL, c, buffer, sizeof(buffer), 1)) {[](#l1.38)
if (ucnhash_CAPI->getname(NULL, c, buffer, sizeof(buffer), 1)) {[](#l1.39) *outp++ = 'N';[](#l1.40) *outp++ = '{';[](#l1.41) strcpy((char *)outp, buffer);[](#l1.42)