summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-05-07 00:41:18 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-05-07 00:41:18 (GMT)
commite3c7381c39f02a29538ba0dc2f5731aee73ceb1a (patch)
tree5cb97a7150d6a6fe0a2d9ab6fb8f18fc99059302 /Objects
parentf650e466464e1417a3c60c8eb52e4591e3e3c352 (diff)
downloadcpython-e3c7381c39f02a29538ba0dc2f5731aee73ceb1a.zip
cpython-e3c7381c39f02a29538ba0dc2f5731aee73ceb1a.tar.gz
cpython-e3c7381c39f02a29538ba0dc2f5731aee73ceb1a.tar.bz2
code_repr(): use %U to format the filename
Avoid useless unicode decoding/recoding of the filename.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/codeobject.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 3e71e4c..ad2068b 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -340,16 +340,20 @@ code_dealloc(PyCodeObject *co)
static PyObject *
code_repr(PyCodeObject *co)
{
- int lineno = -1;
- char *filename = "???";
-
+ int lineno;
if (co->co_firstlineno != 0)
lineno = co->co_firstlineno;
- if (co->co_filename && PyUnicode_Check(co->co_filename))
- filename = _PyUnicode_AsString(co->co_filename);
- return PyUnicode_FromFormat(
- "<code object %.100U at %p, file \"%.300s\", line %d>",
- co->co_name, co, filename, lineno);
+ else
+ lineno = -1;
+ if (co->co_filename && PyUnicode_Check(co->co_filename)) {
+ return PyUnicode_FromFormat(
+ "<code object %.100U at %p, file \"%.300U\", line %d>",
+ co->co_name, co, co->co_filename, lineno);
+ } else {
+ return PyUnicode_FromFormat(
+ "<code object %.100U at %p, file ???, line %d>",
+ co->co_name, co, lineno);
+ }
}
static PyObject *