[Python-3000-checkins] r57426 - in python/branches/py3k: Objects/codeobject.c Python/compile.c

neal.norwitz python-3000-checkins at python.org
Sat Aug 25 01:12:06 CEST 2007


Author: neal.norwitz
Date: Sat Aug 25 01:12:06 2007
New Revision: 57426

Modified:
   python/branches/py3k/Objects/codeobject.c
   python/branches/py3k/Python/compile.c
Log:
Ensure that code object names (co_name) are unicode.
Verify that they print properly too.


Modified: python/branches/py3k/Objects/codeobject.c
==============================================================================
--- python/branches/py3k/Objects/codeobject.c	(original)
+++ python/branches/py3k/Objects/codeobject.c	Sat Aug 25 01:12:06 2007
@@ -65,6 +65,13 @@
 		PyErr_BadInternalCall();
 		return NULL;
 	}
+	if (PyString_Check(name)) {
+		name = PyUnicode_FromString(PyString_AS_STRING(name));
+		if (name == NULL)
+			return NULL;
+	} else {
+		Py_INCREF(name);
+	}
 	intern_strings(names);
 	intern_strings(varnames);
 	intern_strings(freevars);
@@ -106,6 +113,7 @@
 		co->co_lnotab = lnotab;
                 co->co_zombieframe = NULL;
 	}
+	Py_DECREF(name);
 	return co;
 }
 
@@ -288,17 +296,14 @@
 {
 	int lineno = -1;
 	char *filename = "???";
-	char *name = "???";
 
 	if (co->co_firstlineno != 0)
 		lineno = co->co_firstlineno;
 	if (co->co_filename && PyString_Check(co->co_filename))
 		filename = PyString_AS_STRING(co->co_filename);
-	if (co->co_name && PyString_Check(co->co_name))
-		name = PyString_AS_STRING(co->co_name);
 	return PyUnicode_FromFormat(
-	                "<code object %.100s at %p, file \"%.300s\", line %d>",
-	                name, co, filename, lineno);
+	                "<code object %.100U at %p, file \"%.300s\", line %d>",
+	                co->co_name, co, filename, lineno);
 }
 
 static PyObject *

Modified: python/branches/py3k/Python/compile.c
==============================================================================
--- python/branches/py3k/Python/compile.c	(original)
+++ python/branches/py3k/Python/compile.c	Sat Aug 25 01:12:06 2007
@@ -2991,7 +2991,7 @@
 {
 	static identifier name;
 	if (!name) {
-		name = PyString_FromString("<dictcomp>");
+		name = PyUnicode_FromString("<dictcomp>");
 		if (!name)
 			return 0;
 	}


More information about the Python-3000-checkins mailing list