[Python-3000-checkins] r58551 - python/branches/py3k/Python/codecs.c python/branches/py3k/Python/structmember.c

guido.van.rossum python-3000-checkins at python.org
Fri Oct 19 23:48:41 CEST 2007


Author: guido.van.rossum
Date: Fri Oct 19 23:48:41 2007
New Revision: 58551

Modified:
   python/branches/py3k/Python/codecs.c
   python/branches/py3k/Python/structmember.c
Log:
This is the uncontroversial half of patch 1263 by Thomas Lee:
changes to codecs.c and structmember.c to use PyUnicode instead of
PyString.


Modified: python/branches/py3k/Python/codecs.c
==============================================================================
--- python/branches/py3k/Python/codecs.c	(original)
+++ python/branches/py3k/Python/codecs.c	Fri Oct 19 23:48:41 2007
@@ -55,16 +55,15 @@
     size_t len = strlen(string);
     char *p;
     PyObject *v;
-    
+
     if (len > PY_SSIZE_T_MAX) {
 	PyErr_SetString(PyExc_OverflowError, "string is too large");
 	return NULL;
     }
-	
-    v = PyString_FromStringAndSize(NULL, len);
-    if (v == NULL)
-	return NULL;
-    p = PyString_AS_STRING(v);
+
+    p = PyMem_Malloc(len + 1);
+    if (p == NULL)
+        return NULL;
     for (i = 0; i < len; i++) {
         register char ch = string[i];
         if (ch == ' ')
@@ -73,6 +72,11 @@
             ch = tolower(Py_CHARMASK(ch));
 	p[i] = ch;
     }
+    p[i] = '\0';
+    v = PyUnicode_FromString(p);
+    if (v == NULL)
+        return NULL;
+    PyMem_Free(p);
     return v;
 }
 
@@ -112,7 +116,7 @@
     v = normalizestring(encoding);
     if (v == NULL)
 	goto onError;
-    PyString_InternInPlace(&v);
+    PyUnicode_InternInPlace(&v);
 
     /* First, try to lookup the name in the registry dictionary */
     result = PyDict_GetItem(interp->codec_search_cache, v);
@@ -193,7 +197,7 @@
     if (errors) {
 	PyObject *v;
 	
-	v = PyString_FromString(errors);
+	v = PyUnicode_FromString(errors);
 	if (v == NULL) {
 	    Py_DECREF(args);
 	    return NULL;

Modified: python/branches/py3k/Python/structmember.c
==============================================================================
--- python/branches/py3k/Python/structmember.c	(original)
+++ python/branches/py3k/Python/structmember.c	Fri Oct 19 23:48:41 2007
@@ -51,13 +51,13 @@
 			v = Py_None;
 		}
 		else
-			v = PyString_FromString(*(char**)addr);
+			v = PyUnicode_FromString(*(char**)addr);
 		break;
 	case T_STRING_INPLACE:
-		v = PyString_FromString((char*)addr);
+		v = PyUnicode_FromString((char*)addr);
 		break;
 	case T_CHAR:
-		v = PyString_FromStringAndSize((char*)addr, 1);
+		v = PyUnicode_FromStringAndSize((char*)addr, 1);
 		break;
 	case T_OBJECT:
 		v = *(PyObject **)addr;
@@ -225,8 +225,8 @@
 		Py_XDECREF(oldv);
 		break;
 	case T_CHAR:
-		if (PyString_Check(v) && PyString_Size(v) == 1) {
-			*(char*)addr = PyString_AsString(v)[0];
+		if (PyUnicode_Check(v) && PyUnicode_GetSize(v) == 1) {
+			*(char*)addr = PyUnicode_AsString(v)[0];
 		}
 		else {
 			PyErr_BadArgument();


More information about the Python-3000-checkins mailing list