summaryrefslogtreecommitdiffstats
path: root/Modules/_localemodule.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2007-08-26 07:21:45 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2007-08-26 07:21:45 (GMT)
commit7f9d29c660c6bd89d2febe0c0507f97513160a40 (patch)
tree93768bec98e99629f71c2daa8cc27dc3ea248c20 /Modules/_localemodule.c
parent93c56828a6741c41e3d248f913656332f8d2d77e (diff)
downloadcpython-7f9d29c660c6bd89d2febe0c0507f97513160a40.zip
cpython-7f9d29c660c6bd89d2febe0c0507f97513160a40.tar.gz
cpython-7f9d29c660c6bd89d2febe0c0507f97513160a40.tar.bz2
Use unicode
Diffstat (limited to 'Modules/_localemodule.c')
-rw-r--r--Modules/_localemodule.c53
1 files changed, 14 insertions, 39 deletions
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index 0ac7f36..7c816ff 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -107,7 +107,7 @@ PyLocale_setlocale(PyObject* self, PyObject* args)
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 @@ PyLocale_setlocale(PyObject* self, PyObject* args)
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 @@ PyLocale_localeconv(PyObject* self)
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 @@ PyLocale_strcoll(PyObject* self, PyObject* args)
#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 @@ PyLocale_strcoll(PyObject* self, PyObject* args)
/* 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 @@ PyLocale_strxfrm(PyObject* self, PyObject* args)
return PyErr_NoMemory();
strxfrm(buf, s, n2);
}
- result = PyString_FromString(buf);
+ result = PyUnicode_FromString(buf);
PyMem_Free(buf);
return result;
}
@@ -490,7 +465,7 @@ PyLocale_nl_langinfo(PyObject* self, PyObject* args)
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 @@ PyIntl_gettext(PyObject* self, PyObject *args)
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 @@ PyIntl_dgettext(PyObject* self, PyObject *args)
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 @@ PyIntl_dcgettext(PyObject *self, PyObject *args)
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 @@ PyIntl_textdomain(PyObject* self, PyObject* args)
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
- return PyString_FromString(domain);
+ return PyUnicode_FromString(domain);
}
PyDoc_STRVAR(bindtextdomain__doc__,
@@ -579,7 +554,7 @@ PyIntl_bindtextdomain(PyObject* self,PyObject*args)
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
- return PyString_FromString(dirname);
+ return PyUnicode_FromString(dirname);
}
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
@@ -595,7 +570,7 @@ PyIntl_bind_textdomain_codeset(PyObject* self,PyObject*args)
return NULL;
codeset = bind_textdomain_codeset(domain, codeset);
if (codeset)
- return PyString_FromString(codeset);
+ return PyUnicode_FromString(codeset);
Py_RETURN_NONE;
}
#endif