Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3d7a90d

Browse files
committed
Get the locale and pwd tests working on the Solaris box where there
are some unicode values used. I'm not sure if this is the correct on all operating systems, but this works on Linux w/o unicode.
1 parent 8866e0a commit 3d7a90d

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

Modules/_localemodule.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ PyLocale_localeconv(PyObject* self)
143143
involved herein */
144144

145145
#define RESULT_STRING(s)\
146-
x = PyUnicode_FromString(l->s);\
146+
x = PyUnicode_DecodeUnicodeEscape(l->s, strlen(l->s), "strict");\
147147
if (!x) goto failed;\
148148
PyDict_SetItemString(result, #s, x);\
149149
Py_XDECREF(x)
@@ -471,8 +471,10 @@ PyLocale_nl_langinfo(PyObject* self, PyObject* args)
471471
/* Check NULL as a workaround for GNU libc's returning NULL
472472
instead of an empty string for nl_langinfo(ERA). */
473473
const char *result = nl_langinfo(item);
474+
result = result != NULL ? result : "";
474475
/* XXX may have to convert this to wcs first. */
475-
return PyUnicode_FromString(result != NULL ? result : "");
476+
return PyUnicode_DecodeUnicodeEscape(result, strlen(result),
477+
"strict");
476478
}
477479
PyErr_SetString(PyExc_ValueError, "unsupported langinfo constant");
478480
return NULL;

Modules/pwdmodule.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ static PyTypeObject StructPwdType;
4848
static void
4949
sets(PyObject *v, int i, const char* val)
5050
{
51-
if (val)
52-
PyStructSequence_SET_ITEM(v, i, PyUnicode_FromString(val));
51+
if (val) {
52+
PyObject *o =
53+
PyUnicode_DecodeUnicodeEscape(val, strlen(val), "strict");
54+
PyStructSequence_SET_ITEM(v, i, o);
55+
}
5356
else {
5457
PyStructSequence_SET_ITEM(v, i, Py_None);
5558
Py_INCREF(Py_None);

0 commit comments

Comments
 (0)