summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-11-22 01:27:30 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-11-22 01:27:30 (GMT)
commit9d3b93ba305e8a83bf1cec5146def2078e40b1a5 (patch)
treed618d2ca564f2a027522b22491f4fec656fceb09 /Modules/posixmodule.c
parentb84d723509d1b8c7e052f61117624627d334cf30 (diff)
downloadcpython-9d3b93ba305e8a83bf1cec5146def2078e40b1a5.zip
cpython-9d3b93ba305e8a83bf1cec5146def2078e40b1a5.tar.gz
cpython-9d3b93ba305e8a83bf1cec5146def2078e40b1a5.tar.bz2
Use the new Unicode API
* Replace PyUnicode_FromUnicode(NULL, 0) by PyUnicode_New(0, 0) * Replce PyUnicode_FromUnicode(str, len) by PyUnicode_FromWideChar(str, len) * Replace Py_UNICODE by wchar_t * posix_putenv() uses PyUnicode_FromFormat() to create the string, instead of PyUnicode_FromUnicode() + _snwprintf()
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 078010b..975cd9a 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -2599,7 +2599,7 @@ posix_listdir(PyObject *self, PyObject *args)
/* Skip over . and .. */
if (wcscmp(wFileData.cFileName, L".") != 0 &&
wcscmp(wFileData.cFileName, L"..") != 0) {
- v = PyUnicode_FromUnicode(wFileData.cFileName, wcslen(wFileData.cFileName));
+ v = PyUnicode_FromWideChar(wFileData.cFileName, wcslen(wFileData.cFileName));
if (v == NULL) {
Py_DECREF(d);
d = NULL;
@@ -2967,7 +2967,7 @@ posix__getfullpathname(PyObject *self, PyObject *args)
result = GetFullPathNameW(wpath, result, woutbufp, &wtemp);
}
if (result)
- v = PyUnicode_FromUnicode(woutbufp, wcslen(woutbufp));
+ v = PyUnicode_FromWideChar(woutbufp, wcslen(woutbufp));
else
v = win32_error_object("GetFullPathNameW", po);
if (woutbufp != woutbuf)
@@ -3054,7 +3054,7 @@ posix__getfinalpathname(PyObject *self, PyObject *args)
return win32_error_object("CloseHandle", po);
target_path[result_length] = 0;
- result = PyUnicode_FromUnicode(target_path, result_length);
+ result = PyUnicode_FromWideChar(target_path, result_length);
free(target_path);
return result;
@@ -7750,7 +7750,7 @@ static PyObject *
posix_putenv(PyObject *self, PyObject *args)
{
#ifdef MS_WINDOWS
- wchar_t *s1, *s2;
+ PyObject *s1, *s2;
wchar_t *newenv;
#else
PyObject *os1, *os2;
@@ -7762,7 +7762,7 @@ posix_putenv(PyObject *self, PyObject *args)
#ifdef MS_WINDOWS
if (!PyArg_ParseTuple(args,
- "uu:putenv",
+ "UU:putenv",
&s1, &s2))
return NULL;
#else
@@ -7799,26 +7799,26 @@ posix_putenv(PyObject *self, PyObject *args)
/* len includes space for a trailing \0; the size arg to
PyBytes_FromStringAndSize does not count that */
#ifdef MS_WINDOWS
- len = wcslen(s1) + wcslen(s2) + 2;
- newstr = PyUnicode_FromUnicode(NULL, (int)len - 1);
-#else
- len = PyBytes_GET_SIZE(os1) + PyBytes_GET_SIZE(os2) + 2;
- newstr = PyBytes_FromStringAndSize(NULL, (int)len - 1);
-#endif
+ newstr = PyUnicode_FromFormat("%U=%U", s1, s2);
if (newstr == NULL) {
PyErr_NoMemory();
goto error;
}
-#ifdef MS_WINDOWS
newenv = PyUnicode_AsUnicode(newstr);
if (newenv == NULL)
goto error;
- _snwprintf(newenv, len, L"%s=%s", s1, s2);
if (_wputenv(newenv)) {
posix_error();
goto error;
}
#else
+ len = PyBytes_GET_SIZE(os1) + PyBytes_GET_SIZE(os2) + 2;
+ newstr = PyBytes_FromStringAndSize(NULL, (int)len - 1);
+ if (newstr == NULL) {
+ PyErr_NoMemory();
+ goto error;
+ }
+
newenv = PyBytes_AS_STRING(newstr);
PyOS_snprintf(newenv, len, "%s=%s", s1, s2);
if (putenv(newenv)) {