[Python-3000-checkins] r57506 - python/branches/py3k/Modules/_localemodule.c

neal.norwitz python-3000-checkins at python.org
Sun Aug 26 09:21:45 CEST 2007


Author: neal.norwitz
Date: Sun Aug 26 09:21:45 2007
New Revision: 57506

Modified:
   python/branches/py3k/Modules/_localemodule.c
Log:
Use unicode

Modified: python/branches/py3k/Modules/_localemodule.c
==============================================================================
--- python/branches/py3k/Modules/_localemodule.c	(original)
+++ python/branches/py3k/Modules/_localemodule.c	Sun Aug 26 09:21:45 2007
@@ -107,7 +107,7 @@
             PyErr_SetString(Error, "unsupported locale setting");
             return NULL;
         }
-        result_object = PyString_FromString(result);
+        result_object = PyUnicode_FromString(result);
         if (!result_object)
             return NULL;
     } else {
@@ -117,7 +117,7 @@
             PyErr_SetString(Error, "locale query failed");
             return NULL;
         }
-        result_object = PyString_FromString(result);
+        result_object = PyUnicode_FromString(result);
     }
     return result_object;
 }
@@ -143,7 +143,7 @@
        involved herein */
 
 #define RESULT_STRING(s)\
-    x = PyString_FromString(l->s);\
+    x = PyUnicode_FromString(l->s);\
     if (!x) goto failed;\
     PyDict_SetItemString(result, #s, x);\
     Py_XDECREF(x)
@@ -206,33 +206,14 @@
 #else
     PyObject *os1, *os2, *result = NULL;
     wchar_t *ws1 = NULL, *ws2 = NULL;
-    int rel1 = 0, rel2 = 0, len1, len2;
+    int len1, len2;
     
     if (!PyArg_UnpackTuple(args, "strcoll", 2, 2, &os1, &os2))
         return NULL;
-    /* If both arguments are byte strings, use strcoll.  */
-    if (PyString_Check(os1) && PyString_Check(os2))
-        return PyInt_FromLong(strcoll(PyString_AS_STRING(os1),
-                                      PyString_AS_STRING(os2)));
-    /* If neither argument is unicode, it's an error.  */
-    if (!PyUnicode_Check(os1) && !PyUnicode_Check(os2)) {
+    /* Both arguments must be unicode, or it's an error.  */
+    if (!PyUnicode_Check(os1) || !PyUnicode_Check(os2)) {
         PyErr_SetString(PyExc_ValueError, "strcoll arguments must be strings");
     }
-    /* Convert the non-unicode argument to unicode. */
-    if (!PyUnicode_Check(os1)) {
-        os1 = PyUnicode_FromObject(os1);
-        if (!os1)
-            return NULL;
-        rel1 = 1;
-    }
-    if (!PyUnicode_Check(os2)) {
-        os2 = PyUnicode_FromObject(os2);
-        if (!os2) {
-            Py_DECREF(os1);
-            return NULL;
-        } 
-        rel2 = 1;
-    }
     /* Convert the unicode strings to wchar[]. */
     len1 = PyUnicode_GET_SIZE(os1) + 1;
     ws1 = PyMem_MALLOC(len1 * sizeof(wchar_t));
@@ -258,12 +239,6 @@
     /* Deallocate everything. */
     if (ws1) PyMem_FREE(ws1);
     if (ws2) PyMem_FREE(ws2);
-    if (rel1) {
-        Py_DECREF(os1);
-    }
-    if (rel2) {
-        Py_DECREF(os2);
-    }
     return result;
 #endif
 }
@@ -295,7 +270,7 @@
             return PyErr_NoMemory();
         strxfrm(buf, s, n2);
     }
-    result = PyString_FromString(buf);
+    result = PyUnicode_FromString(buf);
     PyMem_Free(buf);
     return result;
 }
@@ -490,7 +465,7 @@
         return NULL;
     /* Check whether this is a supported constant. GNU libc sometimes
        returns numeric values in the char* return value, which would
-       crash PyString_FromString.  */
+       crash PyUnicode_FromString.  */
     for (i = 0; langinfo_constants[i].name; i++)
         if (langinfo_constants[i].value == item) {
             /* Check NULL as a workaround for GNU libc's returning NULL
@@ -516,7 +491,7 @@
 	char *in;
 	if (!PyArg_ParseTuple(args, "z", &in))
 		return 0;
-	return PyString_FromString(gettext(in));
+	return PyUnicode_FromString(gettext(in));
 }
 
 PyDoc_STRVAR(dgettext__doc__,
@@ -529,7 +504,7 @@
 	char *domain, *in;
 	if (!PyArg_ParseTuple(args, "zz", &domain, &in))
 		return 0;
-	return PyString_FromString(dgettext(domain, in));
+	return PyUnicode_FromString(dgettext(domain, in));
 }
 
 PyDoc_STRVAR(dcgettext__doc__,
@@ -543,7 +518,7 @@
 	int category;
 	if (!PyArg_ParseTuple(args, "zzi", &domain, &msgid, &category))
 		return 0;
-	return PyString_FromString(dcgettext(domain,msgid,category));
+	return PyUnicode_FromString(dcgettext(domain,msgid,category));
 }
 
 PyDoc_STRVAR(textdomain__doc__,
@@ -561,7 +536,7 @@
 		PyErr_SetFromErrno(PyExc_OSError);
 		return NULL;
 	}
-	return PyString_FromString(domain);
+	return PyUnicode_FromString(domain);
 }
 
 PyDoc_STRVAR(bindtextdomain__doc__,
@@ -579,7 +554,7 @@
 		PyErr_SetFromErrno(PyExc_OSError);
 		return NULL;
 	}
-	return PyString_FromString(dirname);
+	return PyUnicode_FromString(dirname);
 }
 
 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
@@ -595,7 +570,7 @@
 		return NULL;
 	codeset = bind_textdomain_codeset(domain, codeset);
 	if (codeset)
-		return PyString_FromString(codeset);
+		return PyUnicode_FromString(codeset);
 	Py_RETURN_NONE;
 }
 #endif


More information about the Python-3000-checkins mailing list