[Python-checkins] r80900 - python/branches/py3k/Objects/codeobject.c

victor.stinner python-checkins at python.org
Fri May 7 02:41:18 CEST 2010


Author: victor.stinner
Date: Fri May  7 02:41:18 2010
New Revision: 80900

Log:
code_repr(): use %U to format the filename

Avoid useless unicode decoding/recoding of the filename.


Modified:
   python/branches/py3k/Objects/codeobject.c

Modified: python/branches/py3k/Objects/codeobject.c
==============================================================================
--- python/branches/py3k/Objects/codeobject.c	(original)
+++ python/branches/py3k/Objects/codeobject.c	Fri May  7 02:41:18 2010
@@ -340,16 +340,20 @@
 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 *


More information about the Python-checkins mailing list