summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2007-08-24 23:12:06 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2007-08-24 23:12:06 (GMT)
commit41103bf6f2f5787ddf7106fb3e5a0a98bb6b1c7d (patch)
treef72b9c3d7b66bf39928689e29ac583fdcc297960 /Objects
parenta5d16a3f855540a0d67a8bd3ff6927455ed7a8b5 (diff)
downloadcpython-41103bf6f2f5787ddf7106fb3e5a0a98bb6b1c7d.zip
cpython-41103bf6f2f5787ddf7106fb3e5a0a98bb6b1c7d.tar.gz
cpython-41103bf6f2f5787ddf7106fb3e5a0a98bb6b1c7d.tar.bz2
Ensure that code object names (co_name) are unicode.
Verify that they print properly too.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/codeobject.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 0a7c141..7bd292a 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -65,6 +65,13 @@ PyCode_New(int argcount, int kwonlyargcount,
PyErr_BadInternalCall();
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(varnames);
intern_strings(freevars);
@@ -106,6 +113,7 @@ PyCode_New(int argcount, int kwonlyargcount,
co->co_lnotab = lnotab;
co->co_zombieframe = NULL;
}
+ Py_DECREF(name);
return co;
}
@@ -288,17 +296,14 @@ code_repr(PyCodeObject *co)
{
int lineno = -1;
char *filename = "???";
- char *name = "???";
if (co->co_firstlineno != 0)
lineno = co->co_firstlineno;
if (co->co_filename && PyString_Check(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(
- "<code object %.100s at %p, file \"%.300s\", line %d>",
- name, co, filename, lineno);
+ "<code object %.100U at %p, file \"%.300s\", line %d>",
+ co->co_name, co, filename, lineno);
}
static PyObject *