Mercurial > cpython-lru_cache-weakref
diff Python/compile.c @ 1029:2f9805c963e8 legacy-trunk
Give code objects a more useful representation.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 03 Sep 1992 20:50:59 +0000 |
| parents | dc3b455f7632 |
| children | 1cabc2b6c970 |
line wrap: on
line diff
--- a/Python/compile.c Thu Sep 03 20:49:55 1992 +0000 +++ b/Python/compile.c Thu Sep 03 20:50:59 1992 +0000 @@ -72,6 +72,23 @@ 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 @@ 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*/
