summaryrefslogtreecommitdiff
path: root/Objects/codeobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-05-07 00:41:18 +0000
committerVictor Stinner <victor.stinner@haypocalc.com>2010-05-07 00:41:18 +0000
commit257bd4447c4fe98e1d26deaf6b7d7cf031603955 (patch)
tree9bed1443d4967fb637cfcb6ecc1a5530bba56ac4 /Objects/codeobject.c
parent1426c9bf67aeded078c7e94a832bdb64bb9175c9 (diff)
downloadcpython-257bd4447c4fe98e1d26deaf6b7d7cf031603955.tar.gz
code_repr(): use %U to format the filename
Avoid useless unicode decoding/recoding of the filename.
Diffstat (limited to 'Objects/codeobject.c')
-rw-r--r--Objects/codeobject.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 3e71e4cde3..ad2068bb2a 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 *