From 3f1af5c42e915775e9cc32224e090b05430a23de Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 12 Mar 2010 17:00:41 +0000 Subject: Issue #6697: use %U format instead of _PyUnicode_AsString(), because _PyUnicode_AsString() was not checked for error (NULL). The unicode string is no more truncated to 200 or 400 *bytes*. --- Modules/_hashopenssl.c | 5 +---- Modules/zipimport.c | 9 +++------ Objects/funcobject.c | 4 ++-- Objects/typeobject.c | 13 +++++++++---- Python/ceval.c | 4 ++-- Python/import.c | 4 ++-- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c index 26ed148..887de55 100644 --- a/Modules/_hashopenssl.c +++ b/Modules/_hashopenssl.c @@ -294,10 +294,7 @@ static PyGetSetDef EVP_getseters[] = { static PyObject * EVP_repr(EVPobject *self) { - char buf[100]; - PyOS_snprintf(buf, sizeof(buf), "<%s HASH object @ %p>", - _PyUnicode_AsString(self->name), self); - return PyUnicode_FromString(buf); + return PyUnicode_FromFormat("<%U HASH object @ %p>", self->name, self); } #if HASH_OBJ_CONSTRUCTOR diff --git a/Modules/zipimport.c b/Modules/zipimport.c index 770f18f..fed3e99 100644 --- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -321,15 +321,12 @@ zipimporter_load_module(PyObject *obj, PyObject *args) /* add __path__ to the module *before* the code gets executed */ PyObject *pkgpath, *fullpath; - char *prefix = _PyUnicode_AsString(self->prefix); char *subname = get_subname(fullname); int err; - fullpath = PyUnicode_FromFormat("%s%c%s%s", - _PyUnicode_AsString(self->archive), - SEP, - prefix ? prefix : "", - subname); + fullpath = PyUnicode_FromFormat("%U%c%U%s", + self->archive, SEP, + self->prefix, subname); if (fullpath == NULL) goto error; diff --git a/Objects/funcobject.c b/Objects/funcobject.c index 16851a9..35fc32d 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -295,9 +295,9 @@ func_set_code(PyFunctionObject *op, PyObject *value) PyTuple_GET_SIZE(op->func_closure)); if (nclosure != nfree) { PyErr_Format(PyExc_ValueError, - "%s() requires a code object with %zd free vars," + "%U() requires a code object with %zd free vars," " not %zd", - _PyUnicode_AsString(op->func_name), + op->func_name, nclosure, nfree); return -1; } diff --git a/Objects/typeobject.c b/Objects/typeobject.c index be4b6f8..7fd4cc8 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1295,10 +1295,15 @@ check_duplicates(PyObject *list) for (j = i + 1; j < n; j++) { if (PyList_GET_ITEM(list, j) == o) { o = class_name(o); - PyErr_Format(PyExc_TypeError, - "duplicate base class %.400s", - o ? _PyUnicode_AsString(o) : "?"); - Py_XDECREF(o); + if (o != NULL) { + PyErr_Format(PyExc_TypeError, + "duplicate base class %U", + o); + Py_DECREF(o); + } else { + PyErr_SetString(PyExc_TypeError, + "duplicate base class"); + } return -1; } } diff --git a/Python/ceval.c b/Python/ceval.c index 47c53cf..4e9f77b 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -3989,10 +3989,10 @@ update_keyword_args(PyObject *orig_kwdict, int nk, PyObject ***pp_stack, if (PyDict_GetItem(kwdict, key) != NULL) { PyErr_Format(PyExc_TypeError, "%.200s%s got multiple values " - "for keyword argument '%.200s'", + "for keyword argument '%U'", PyEval_GetFuncName(func), PyEval_GetFuncDesc(func), - _PyUnicode_AsString(key)); + key); Py_DECREF(key); Py_DECREF(value); Py_DECREF(kwdict); diff --git a/Python/import.c b/Python/import.c index 8a948b9..036d17e 100644 --- a/Python/import.c +++ b/Python/import.c @@ -2691,8 +2691,8 @@ PyImport_ReloadModule(PyObject *m) parent = PyDict_GetItem(modules, parentname); if (parent == NULL) { PyErr_Format(PyExc_ImportError, - "reload(): parent %.200s not in sys.modules", - _PyUnicode_AsString(parentname)); + "reload(): parent %U not in sys.modules", + parentname); Py_DECREF(parentname); imp_modules_reloading_clear(); return NULL; -- cgit v0.12