diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-11-22 01:27:30 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-11-22 01:27:30 (GMT) |
commit | 9d3b93ba305e8a83bf1cec5146def2078e40b1a5 (patch) | |
tree | d618d2ca564f2a027522b22491f4fec656fceb09 /Modules | |
parent | b84d723509d1b8c7e052f61117624627d334cf30 (diff) | |
download | cpython-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')
-rw-r--r-- | Modules/_ctypes/_ctypes.c | 4 | ||||
-rw-r--r-- | Modules/posixmodule.c | 26 | ||||
-rw-r--r-- | Modules/socketmodule.c | 2 |
3 files changed, 16 insertions, 16 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index b45eea9..31906bf 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -4255,7 +4255,7 @@ Array_subscript(PyObject *_self, PyObject *item) wchar_t *dest; if (slicelen <= 0) - return PyUnicode_FromUnicode(NULL, 0); + return PyUnicode_New(0, 0); if (step == 1) { return PyUnicode_FromWideChar(ptr + start, slicelen); @@ -4930,7 +4930,7 @@ Pointer_subscript(PyObject *_self, PyObject *item) wchar_t *dest; if (len <= 0) - return PyUnicode_FromUnicode(NULL, 0); + return PyUnicode_New(0, 0); if (step == 1) { return PyUnicode_FromWideChar(ptr + start, len); 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)) { diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 4742b44..40a18ed 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -3900,7 +3900,7 @@ socket_gethostname(PyObject *self, PyObject *unused) PyObject *result; if (GetComputerNameExW(ComputerNamePhysicalDnsHostname, buf, &size)) - return PyUnicode_FromUnicode(buf, size); + return PyUnicode_FromWideChar(buf, size); if (GetLastError() != ERROR_MORE_DATA) return PyErr_SetFromWindowsErr(0); |