diff Objects/codeobject.c @ 43777:0d462d789b18

Merging the py3k-pep3137 branch back into the py3k branch. No detailed change log; just check out the change log for the py3k-pep3137 branch. The most obvious changes: - str8 renamed to bytes (PyString at the C level); - bytes renamed to buffer (PyBytes at the C level); - PyString and PyUnicode are no longer compatible. I.e. we now have an immutable bytes type and a mutable bytes type. The behavior of PyString was modified quite a bit, to make it more bytes-like. Some changes are still on the to-do list.
author Guido van Rossum <guido@python.org>
date Tue, 06 Nov 2007 21:34:58 +0000
parents 8fe24e5eeeff
children b70485011214
line wrap: on
line diff
--- a/Objects/codeobject.c	Tue Nov 06 20:51:31 2007 +0000
+++ b/Objects/codeobject.c	Tue Nov 06 21:34:58 2007 +0000
@@ -8,7 +8,7 @@
 /* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */
 
 static int
-all_name_chars(unsigned char *s)
+all_name_chars(Py_UNICODE *s)
 {
 	static char ok_name_char[256];
 	static unsigned char *name_chars = (unsigned char *)NAME_CHARS;
@@ -19,6 +19,8 @@
 			ok_name_char[*p] = 1;
 	}
 	while (*s) {
+		if (*s >= 128)
+			return 0;
 		if (ok_name_char[*s++] == 0)
 			return 0;
 	}
@@ -73,11 +75,11 @@
 	/* Intern selected string constants */
 	for (i = PyTuple_Size(consts); --i >= 0; ) {
 		PyObject *v = PyTuple_GetItem(consts, i);
-		if (!PyString_Check(v))
+		if (!PyUnicode_Check(v))
 			continue;
-		if (!all_name_chars((unsigned char *)PyString_AS_STRING(v)))
+		if (!all_name_chars(PyUnicode_AS_UNICODE(v)))
 			continue;
-		PyString_InternInPlace(&PyTuple_GET_ITEM(consts, i));
+		PyUnicode_InternInPlace(&PyTuple_GET_ITEM(consts, i));
 	}
 	co = PyObject_NEW(PyCodeObject, &PyCode_Type);
 	if (co != NULL) {
@@ -202,7 +204,7 @@
 	int firstlineno;
 	PyObject *lnotab;
 
-	if (!PyArg_ParseTuple(args, "iiiiiSO!O!O!SSiS|O!O!:code",
+	if (!PyArg_ParseTuple(args, "iiiiiSO!O!O!UUiS|O!O!:code",
 			      &argcount, &kwonlyargcount,
 				  &nlocals, &stacksize, &flags,
 			      &code,