[Python-3000-checkins] r59109 - in python/branches/py3k: Objects/setobject.c Objects/stringobject.c Python/ast.c Python/getargs.c Python/peephole.c

amaury.forgeotdarc python-3000-checkins at python.org
Thu Nov 22 03:48:13 CET 2007


Author: amaury.forgeotdarc
Date: Thu Nov 22 03:48:12 2007
New Revision: 59109

Modified:
   python/branches/py3k/Objects/setobject.c
   python/branches/py3k/Objects/stringobject.c
   python/branches/py3k/Python/ast.c
   python/branches/py3k/Python/getargs.c
   python/branches/py3k/Python/peephole.c
Log:
PyString_AsString is permissive and accepts unicode strings.

Replace it with PyUnicode_AsString when the argument is known to be a str.


Modified: python/branches/py3k/Objects/setobject.c
==============================================================================
--- python/branches/py3k/Objects/setobject.c	(original)
+++ python/branches/py3k/Objects/setobject.c	Thu Nov 22 03:48:12 2007
@@ -2303,7 +2303,7 @@
 	/* Exercise direct iteration */
 	i = 0, count = 0;
 	while (_PySet_Next((PyObject *)dup, &i, &x)) {
-		s = PyString_AsString(x);
+		s = PyUnicode_AsString(x);
 		assert(s && (s[0] == 'a' || s[0] == 'b' || s[0] == 'c'));
 		count++;
 	}

Modified: python/branches/py3k/Objects/stringobject.c
==============================================================================
--- python/branches/py3k/Objects/stringobject.c	(original)
+++ python/branches/py3k/Objects/stringobject.c	Thu Nov 22 03:48:12 2007
@@ -3273,7 +3273,7 @@
 	if (!result)
 		return NULL;
 
-	buf = PyString_AsString(result);
+	buf = PyUnicode_AsString(result);
 	if (!buf) {
 		Py_DECREF(result);
 		return NULL;
@@ -3284,7 +3284,7 @@
 		PyErr_BadInternalCall();
 		return NULL;
 	}
-	llen = PyString_Size(result);
+	llen = PyUnicode_GetSize(result);
 	if (llen > INT_MAX) {
 		PyErr_SetString(PyExc_ValueError,
 				"string too large in _PyString_FormatLong");

Modified: python/branches/py3k/Python/ast.c
==============================================================================
--- python/branches/py3k/Python/ast.c	(original)
+++ python/branches/py3k/Python/ast.c	Thu Nov 22 03:48:12 2007
@@ -1299,7 +1299,7 @@
                 if (errstr) {
                     char *s = "";
                     char buf[128];
-                    s = PyString_AsString(errstr);
+                    s = PyUnicode_AsString(errstr);
                     PyOS_snprintf(buf, sizeof(buf), "(unicode error) %s", s);
                     ast_error(n, buf);
                 } else {

Modified: python/branches/py3k/Python/getargs.c
==============================================================================
--- python/branches/py3k/Python/getargs.c	(original)
+++ python/branches/py3k/Python/getargs.c	Thu Nov 22 03:48:12 2007
@@ -768,7 +768,7 @@
 		else if (PyUnicode_Check(arg) &&
 			 PyUnicode_GET_SIZE(arg) == 1 &&
 			 PyUnicode_AS_UNICODE(arg)[0] < 256)
-			*p = PyUnicode_AS_UNICODE(arg)[0];
+			*p = (char)PyUnicode_AS_UNICODE(arg)[0];
 		else
 			return converterr("char < 256", arg, msgbuf, bufsize);
 		break;
@@ -823,7 +823,7 @@
 			}
 			else
 				return converterr("string", arg, msgbuf, bufsize);
-			if ((Py_ssize_t)strlen(*p) != PyString_Size(arg))
+			if ((Py_ssize_t)strlen(*p) != PyUnicode_GetSize(arg))
 				return converterr("string without null bytes",
 						  arg, msgbuf, bufsize);
 		}
@@ -899,7 +899,7 @@
 				format++;
 			}
 			else if (*p != NULL &&
-				 (Py_ssize_t)strlen(*p) != PyString_Size(arg))
+				 (Py_ssize_t)strlen(*p) != PyUnicode_GetSize(arg))
 				return converterr(
 					"string without null bytes or None",
 					arg, msgbuf, bufsize);
@@ -1596,7 +1596,7 @@
 					        "keywords must be strings");
 				return cleanreturn(0, freelist);
 			}
-			ks = PyString_AsString(key);
+			ks = PyUnicode_AsString(key);
 			for (i = 0; i < max; i++) {
 				if (!strcmp(ks, kwlist[i])) {
 					match = 1;

Modified: python/branches/py3k/Python/peephole.c
==============================================================================
--- python/branches/py3k/Python/peephole.c	(original)
+++ python/branches/py3k/Python/peephole.c	Thu Nov 22 03:48:12 2007
@@ -407,7 +407,7 @@
 			case LOAD_NAME:
 			case LOAD_GLOBAL:
 				j = GETARG(codestr, i);
-				name = PyString_AsString(PyTuple_GET_ITEM(names, j));
+				name = PyUnicode_AsString(PyTuple_GET_ITEM(names, j));
 				h = load_global(codestr, i, name, consts);
 				if (h < 0)
 					goto exitUnchanged;


More information about the Python-3000-checkins mailing list