summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-09-03 20:50:59 (GMT)
committerGuido van Rossum <guido@python.org>1992-09-03 20:50:59 (GMT)
commit2dff991f6b3f0be50e8f97d2172ddb140adeec50 (patch)
treebcf11bfa3876401de389e53b32e7947c0267d59e /Python/compile.c
parent97f02772084eb521a3daf34b2e04bcc1460ee617 (diff)
downloadcpython-2dff991f6b3f0be50e8f97d2172ddb140adeec50.zip
cpython-2dff991f6b3f0be50e8f97d2172ddb140adeec50.tar.gz
cpython-2dff991f6b3f0be50e8f97d2172ddb140adeec50.tar.bz2
Give code objects a more useful representation.
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c
index dd4fe15..483e524 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -72,6 +72,23 @@ code_dealloc(co)
DEL(co);
}
+static object *
+code_repr(co)
+ codeobject *co;
+{
+ char buf[500];
+ int lineno = -1;
+ char *p = GETSTRINGVALUE(co->co_code);
+ char *filename = "???";
+ if (*p == SET_LINENO)
+ lineno = (p[1] & 0xff) | ((p[2] & 0xff) << 8);
+ if (co->co_filename && is_stringobject(co->co_filename))
+ filename = getstringvalue(co->co_filename);
+ sprintf(buf, "<code object at %lx, file \"%.400s\", line %d>",
+ (long)co, filename, lineno);
+ return newstringobject(buf);
+}
+
typeobject Codetype = {
OB_HEAD_INIT(&Typetype)
0,
@@ -83,7 +100,7 @@ typeobject Codetype = {
code_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
- 0, /*tp_repr*/
+ code_repr, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/