Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3f1af5c

Browse files
author
Victor Stinner
committed
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*.
1 parent 50981b8 commit 3f1af5c

6 files changed

Lines changed: 19 additions & 20 deletions

File tree

Modules/_hashopenssl.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,7 @@ static PyGetSetDef EVP_getseters[] = {
294294
static PyObject *
295295
EVP_repr(EVPobject *self)
296296
{
297-
char buf[100];
298-
PyOS_snprintf(buf, sizeof(buf), "<%s HASH object @ %p>",
299-
_PyUnicode_AsString(self->name), self);
300-
return PyUnicode_FromString(buf);
297+
return PyUnicode_FromFormat("<%U HASH object @ %p>", self->name, self);
301298
}
302299

303300
#if HASH_OBJ_CONSTRUCTOR

Modules/zipimport.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,12 @@ zipimporter_load_module(PyObject *obj, PyObject *args)
321321
/* add __path__ to the module *before* the code gets
322322
executed */
323323
PyObject *pkgpath, *fullpath;
324-
char *prefix = _PyUnicode_AsString(self->prefix);
325324
char *subname = get_subname(fullname);
326325
int err;
327326

328-
fullpath = PyUnicode_FromFormat("%s%c%s%s",
329-
_PyUnicode_AsString(self->archive),
330-
SEP,
331-
prefix ? prefix : "",
332-
subname);
327+
fullpath = PyUnicode_FromFormat("%U%c%U%s",
328+
self->archive, SEP,
329+
self->prefix, subname);
333330
if (fullpath == NULL)
334331
goto error;
335332

Objects/funcobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ func_set_code(PyFunctionObject *op, PyObject *value)
295295
PyTuple_GET_SIZE(op->func_closure));
296296
if (nclosure != nfree) {
297297
PyErr_Format(PyExc_ValueError,
298-
"%s() requires a code object with %zd free vars,"
298+
"%U() requires a code object with %zd free vars,"
299299
" not %zd",
300-
_PyUnicode_AsString(op->func_name),
300+
op->func_name,
301301
nclosure, nfree);
302302
return -1;
303303
}

Objects/typeobject.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,10 +1295,15 @@ check_duplicates(PyObject *list)
12951295
for (j = i + 1; j < n; j++) {
12961296
if (PyList_GET_ITEM(list, j) == o) {
12971297
o = class_name(o);
1298-
PyErr_Format(PyExc_TypeError,
1299-
"duplicate base class %.400s",
1300-
o ? _PyUnicode_AsString(o) : "?");
1301-
Py_XDECREF(o);
1298+
if (o != NULL) {
1299+
PyErr_Format(PyExc_TypeError,
1300+
"duplicate base class %U",
1301+
o);
1302+
Py_DECREF(o);
1303+
} else {
1304+
PyErr_SetString(PyExc_TypeError,
1305+
"duplicate base class");
1306+
}
13021307
return -1;
13031308
}
13041309
}

Python/ceval.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3989,10 +3989,10 @@ update_keyword_args(PyObject *orig_kwdict, int nk, PyObject ***pp_stack,
39893989
if (PyDict_GetItem(kwdict, key) != NULL) {
39903990
PyErr_Format(PyExc_TypeError,
39913991
"%.200s%s got multiple values "
3992-
"for keyword argument '%.200s'",
3992+
"for keyword argument '%U'",
39933993
PyEval_GetFuncName(func),
39943994
PyEval_GetFuncDesc(func),
3995-
_PyUnicode_AsString(key));
3995+
key);
39963996
Py_DECREF(key);
39973997
Py_DECREF(value);
39983998
Py_DECREF(kwdict);

Python/import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,8 +2691,8 @@ PyImport_ReloadModule(PyObject *m)
26912691
parent = PyDict_GetItem(modules, parentname);
26922692
if (parent == NULL) {
26932693
PyErr_Format(PyExc_ImportError,
2694-
"reload(): parent %.200s not in sys.modules",
2695-
_PyUnicode_AsString(parentname));
2694+
"reload(): parent %U not in sys.modules",
2695+
parentname);
26962696
Py_DECREF(parentname);
26972697
imp_modules_reloading_clear();
26982698
return NULL;

0 commit comments

Comments
 (0)