mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
Ensure that code object names (co_name) are unicode.
Verify that they print properly too.
This commit is contained in:
parent
a5d16a3f85
commit
41103bf6f2
2 changed files with 11 additions and 6 deletions
|
@ -65,6 +65,13 @@ PyCode_New(int argcount, int kwonlyargcount,
|
||||||
PyErr_BadInternalCall();
|
PyErr_BadInternalCall();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if (PyString_Check(name)) {
|
||||||
|
name = PyUnicode_FromString(PyString_AS_STRING(name));
|
||||||
|
if (name == NULL)
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
Py_INCREF(name);
|
||||||
|
}
|
||||||
intern_strings(names);
|
intern_strings(names);
|
||||||
intern_strings(varnames);
|
intern_strings(varnames);
|
||||||
intern_strings(freevars);
|
intern_strings(freevars);
|
||||||
|
@ -106,6 +113,7 @@ PyCode_New(int argcount, int kwonlyargcount,
|
||||||
co->co_lnotab = lnotab;
|
co->co_lnotab = lnotab;
|
||||||
co->co_zombieframe = NULL;
|
co->co_zombieframe = NULL;
|
||||||
}
|
}
|
||||||
|
Py_DECREF(name);
|
||||||
return co;
|
return co;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,17 +296,14 @@ code_repr(PyCodeObject *co)
|
||||||
{
|
{
|
||||||
int lineno = -1;
|
int lineno = -1;
|
||||||
char *filename = "???";
|
char *filename = "???";
|
||||||
char *name = "???";
|
|
||||||
|
|
||||||
if (co->co_firstlineno != 0)
|
if (co->co_firstlineno != 0)
|
||||||
lineno = co->co_firstlineno;
|
lineno = co->co_firstlineno;
|
||||||
if (co->co_filename && PyString_Check(co->co_filename))
|
if (co->co_filename && PyString_Check(co->co_filename))
|
||||||
filename = PyString_AS_STRING(co->co_filename);
|
filename = PyString_AS_STRING(co->co_filename);
|
||||||
if (co->co_name && PyString_Check(co->co_name))
|
|
||||||
name = PyString_AS_STRING(co->co_name);
|
|
||||||
return PyUnicode_FromFormat(
|
return PyUnicode_FromFormat(
|
||||||
"<code object %.100s at %p, file \"%.300s\", line %d>",
|
"<code object %.100U at %p, file \"%.300s\", line %d>",
|
||||||
name, co, filename, lineno);
|
co->co_name, co, filename, lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -2991,7 +2991,7 @@ compiler_dictcomp(struct compiler *c, expr_ty e)
|
||||||
{
|
{
|
||||||
static identifier name;
|
static identifier name;
|
||||||
if (!name) {
|
if (!name) {
|
||||||
name = PyString_FromString("<dictcomp>");
|
name = PyUnicode_FromString("<dictcomp>");
|
||||||
if (!name)
|
if (!name)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue