summaryrefslogtreecommitdiff
path: root/PC
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2011-09-28 07:41:54 +0200
committerMartin v. Löwis <martin@v.loewis.de>2011-09-28 07:41:54 +0200
commitd63a3b8beb4a0841cb59fb3515347ccaab34b733 (patch)
tree3b4e3cc63151c5a5a910c3550a190aefaea96ad4 /PC
parent48d49497c50e79d14e9df9527d766ca3a0a38be5 (diff)
downloadcpython-git-d63a3b8beb4a0841cb59fb3515347ccaab34b733.tar.gz
Implement PEP 393.
Diffstat (limited to 'PC')
-rw-r--r--PC/_subprocess.c61
-rw-r--r--PC/import_nt.c2
-rwxr-xr-xPC/msvcrtmodule.c8
-rw-r--r--PC/pyconfig.h4
-rw-r--r--PC/winreg.c8
5 files changed, 36 insertions, 47 deletions
diff --git a/PC/_subprocess.c b/PC/_subprocess.c
index f11e3e3a16..f0ad55996f 100644
--- a/PC/_subprocess.c
+++ b/PC/_subprocess.c
@@ -329,12 +329,9 @@ gethandle(PyObject* obj, char* name)
static PyObject*
getenvironment(PyObject* environment)
{
- int i;
- Py_ssize_t envsize;
- PyObject* out = NULL;
- PyObject* keys;
- PyObject* values;
- Py_UNICODE* p;
+ Py_ssize_t i, envsize, totalsize;
+ Py_UCS4 *buffer = NULL, *p, *end;
+ PyObject *keys, *values, *res;
/* convert environment dictionary to windows enviroment string */
if (! PyMapping_Check(environment)) {
@@ -350,14 +347,8 @@ getenvironment(PyObject* environment)
if (!keys || !values)
goto error;
- out = PyUnicode_FromUnicode(NULL, 2048);
- if (! out)
- goto error;
-
- p = PyUnicode_AS_UNICODE(out);
-
+ totalsize = 1; /* trailing null character */
for (i = 0; i < envsize; i++) {
- Py_ssize_t ksize, vsize, totalsize;
PyObject* key = PyList_GET_ITEM(keys, i);
PyObject* value = PyList_GET_ITEM(values, i);
@@ -366,36 +357,42 @@ getenvironment(PyObject* environment)
"environment can only contain strings");
goto error;
}
- ksize = PyUnicode_GET_SIZE(key);
- vsize = PyUnicode_GET_SIZE(value);
- totalsize = (p - PyUnicode_AS_UNICODE(out)) + ksize + 1 +
- vsize + 1 + 1;
- if (totalsize > PyUnicode_GET_SIZE(out)) {
- Py_ssize_t offset = p - PyUnicode_AS_UNICODE(out);
- PyUnicode_Resize(&out, totalsize + 1024);
- p = PyUnicode_AS_UNICODE(out) + offset;
- }
- Py_UNICODE_COPY(p, PyUnicode_AS_UNICODE(key), ksize);
- p += ksize;
+ totalsize += PyUnicode_GET_LENGTH(key) + 1; /* +1 for '=' */
+ totalsize += PyUnicode_GET_LENGTH(value) + 1; /* +1 for '\0' */
+ }
+
+ buffer = PyMem_Malloc(totalsize * sizeof(Py_UCS4));
+ if (! buffer)
+ goto error;
+ p = buffer;
+ end = buffer + totalsize;
+
+ for (i = 0; i < envsize; i++) {
+ PyObject* key = PyList_GET_ITEM(keys, i);
+ PyObject* value = PyList_GET_ITEM(values, i);
+ if (!PyUnicode_AsUCS4(key, p, end - p, 0))
+ goto error;
+ p += PyUnicode_GET_LENGTH(key);
*p++ = '=';
- Py_UNICODE_COPY(p, PyUnicode_AS_UNICODE(value), vsize);
- p += vsize;
+ if (!PyUnicode_AsUCS4(value, p, end - p, 0))
+ goto error;
+ p += PyUnicode_GET_LENGTH(value);
*p++ = '\0';
}
/* add trailing null byte */
*p++ = '\0';
- PyUnicode_Resize(&out, p - PyUnicode_AS_UNICODE(out));
-
- /* PyObject_Print(out, stdout, 0); */
+ assert(p == end);
Py_XDECREF(keys);
Py_XDECREF(values);
- return out;
+ res = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, buffer, p - buffer);
+ PyMem_Free(buffer);
+ return res;
error:
- Py_XDECREF(out);
+ PyMem_Free(buffer);
Py_XDECREF(keys);
Py_XDECREF(values);
return NULL;
@@ -609,7 +606,7 @@ sp_GetModuleFileName(PyObject* self, PyObject* args)
if (! result)
return PyErr_SetFromWindowsErr(GetLastError());
- return PyUnicode_FromUnicode(filename, Py_UNICODE_strlen(filename));
+ return PyUnicode_FromWideChar(filename, wcslen(filename));
}
static PyMethodDef sp_functions[] = {
diff --git a/PC/import_nt.c b/PC/import_nt.c
index c372051154..3b607182e6 100644
--- a/PC/import_nt.c
+++ b/PC/import_nt.c
@@ -93,7 +93,7 @@ _PyWin_FindRegisteredModule(PyObject *moduleName,
}
if (fdp->suffix == NULL)
return NULL;
- path = PyUnicode_FromUnicode(pathBuf, wcslen(pathBuf));
+ path = PyUnicode_FromWideChar(pathBuf, wcslen(pathBuf));
if (path == NULL)
return NULL;
fp = _Py_fopen(path, fdp->mode);
diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c
index 166df036f2..e5a0a177bc 100755
--- a/PC/msvcrtmodule.c
+++ b/PC/msvcrtmodule.c
@@ -212,7 +212,6 @@ static PyObject *
msvcrt_getwch(PyObject *self, PyObject *args)
{
Py_UNICODE ch;
- Py_UNICODE u[1];
if (!PyArg_ParseTuple(args, ":getwch"))
return NULL;
@@ -220,8 +219,7 @@ msvcrt_getwch(PyObject *self, PyObject *args)
Py_BEGIN_ALLOW_THREADS
ch = _getwch();
Py_END_ALLOW_THREADS
- u[0] = ch;
- return PyUnicode_FromUnicode(u, 1);
+ return PyUnicode_FromOrdinal(ch);
}
PyDoc_STRVAR(getwch_doc,
@@ -257,7 +255,6 @@ static PyObject *
msvcrt_getwche(PyObject *self, PyObject *args)
{
Py_UNICODE ch;
- Py_UNICODE s[1];
if (!PyArg_ParseTuple(args, ":getwche"))
return NULL;
@@ -265,8 +262,7 @@ msvcrt_getwche(PyObject *self, PyObject *args)
Py_BEGIN_ALLOW_THREADS
ch = _getwche();
Py_END_ALLOW_THREADS
- s[0] = ch;
- return PyUnicode_FromUnicode(s, 1);
+ return PyUnicode_FromOrdinal(ch);
}
PyDoc_STRVAR(getwche_doc,
diff --git a/PC/pyconfig.h b/PC/pyconfig.h
index 752d64f2ed..983fa3d40d 100644
--- a/PC/pyconfig.h
+++ b/PC/pyconfig.h
@@ -550,10 +550,6 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
/* Define if you want to use the GNU readline library */
/* #define WITH_READLINE 1 */
-/* Define as the size of the unicode type. */
-/* This is enough for unicodeobject.h to do the "right thing" on Windows. */
-#define Py_UNICODE_SIZE 2
-
/* Use Python's own small-block memory-allocator. */
#define WITH_PYMALLOC 1
diff --git a/PC/winreg.c b/PC/winreg.c
index 1bc47b958b..38e22f8a3c 100644
--- a/PC/winreg.c
+++ b/PC/winreg.c
@@ -882,7 +882,7 @@ Reg2Py(BYTE *retDataBuf, DWORD retDataSize, DWORD typ)
retDataSize -= 2;
if (retDataSize <= 0)
data = L"";
- obData = PyUnicode_FromUnicode(data, retDataSize/2);
+ obData = PyUnicode_FromWideChar(data, retDataSize/2);
break;
}
case REG_MULTI_SZ:
@@ -913,7 +913,7 @@ Reg2Py(BYTE *retDataBuf, DWORD retDataSize, DWORD typ)
}
PyList_SetItem(obData,
index,
- PyUnicode_FromUnicode(str[index], len));
+ PyUnicode_FromWideChar(str[index], len));
}
free(str);
@@ -1123,7 +1123,7 @@ PyEnumKey(PyObject *self, PyObject *args)
if (rc != ERROR_SUCCESS)
return PyErr_SetFromWindowsErrWithFunction(rc, "RegEnumKeyEx");
- retStr = PyUnicode_FromUnicode(tmpbuf, len);
+ retStr = PyUnicode_FromWideChar(tmpbuf, len);
return retStr; /* can be NULL */
}
@@ -1394,7 +1394,7 @@ PyQueryValue(PyObject *self, PyObject *args)
"RegQueryValue");
}
- retStr = PyUnicode_FromUnicode(retBuf, wcslen(retBuf));
+ retStr = PyUnicode_FromWideChar(retBuf, wcslen(retBuf));
PyMem_Free(retBuf);
return retStr;
}