diff options
author | Guido van Rossum <guido@python.org> | 2007-10-24 18:41:19 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-10-24 18:41:19 +0000 |
commit | f1c6c9e69b185485f8c4b885026ec10e07f20ec1 (patch) | |
tree | cc3599315163050b902df925548c36977e580d99 /Modules/_ctypes/callproc.c | |
parent | 37befa29ebd1589792bd6765d8c24a94e075dcd6 (diff) | |
download | cpython-f1c6c9e69b185485f8c4b885026ec10e07f20ec1.tar.gz |
Patch #1318 by Amaury Forgeot d'Arc.
Updates to ctypes for python 3.0 to make the tests pass.
Notable changes are:
- return bytes instead of str8
- integers in range(256) are accepted as "one char string":
libc.strchr("abcdef", 98) is now valid.
- directly use the wide-char version of the win32 function LoadLibrary.
Diffstat (limited to 'Modules/_ctypes/callproc.c')
-rw-r--r-- | Modules/_ctypes/callproc.c | 36 |
1 files changed, 10 insertions, 26 deletions
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 1c66c48be8..bc524f7a34 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -770,7 +770,7 @@ void Extend_Error_Info(PyObject *exc_class, char *fmt, ...) PyObject *tp, *v, *tb, *s, *cls_str, *msg_str; va_start(vargs, fmt); - s = PyString_FromFormatV(fmt, vargs); + s = PyUnicode_FromFormatV(fmt, vargs); va_end(vargs); if (!s) return; @@ -779,18 +779,18 @@ void Extend_Error_Info(PyObject *exc_class, char *fmt, ...) PyErr_NormalizeException(&tp, &v, &tb); cls_str = PyObject_Str(tp); if (cls_str) { - PyString_ConcatAndDel(&s, cls_str); - PyString_ConcatAndDel(&s, PyString_FromString(": ")); + PyUnicode_AppendAndDel(&s, cls_str); + PyUnicode_AppendAndDel(&s, PyUnicode_FromString(": ")); if (s == NULL) goto error; } else PyErr_Clear(); - msg_str = PyObject_Str(v); + msg_str = PyObject_Unicode(v); if (msg_str) - PyString_ConcatAndDel(&s, msg_str); + PyUnicode_AppendAndDel(&s, msg_str); else { PyErr_Clear(); - PyString_ConcatAndDel(&s, PyString_FromString("???")); + PyUnicode_AppendAndDel(&s, PyUnicode_FromString("???")); if (s == NULL) goto error; } @@ -1087,34 +1087,18 @@ The handle may be used to locate exported functions in this\n\ module.\n"; static PyObject *load_library(PyObject *self, PyObject *args) { - TCHAR *name; + WCHAR *name; PyObject *nameobj; PyObject *ignored; HMODULE hMod; if (!PyArg_ParseTuple(args, "O|O:LoadLibrary", &nameobj, &ignored)) return NULL; -#ifdef _UNICODE - name = alloca((PyString_Size(nameobj) + 1) * sizeof(WCHAR)); - if (!name) { - PyErr_NoMemory(); - return NULL; - } - { - int r; - char *aname = PyString_AsString(nameobj); - if(!aname) - return NULL; - r = MultiByteToWideChar(CP_ACP, 0, aname, -1, name, PyString_Size(nameobj) + 1); - name[r] = 0; - } -#else - name = PyString_AsString(nameobj); - if(!name) + name = PyUnicode_AsUnicode(nameobj); + if (!name) return NULL; -#endif - hMod = LoadLibrary(name); + hMod = LoadLibraryW(name); if (!hMod) return PyErr_SetFromWindowsErr(GetLastError()); #ifdef _WIN64 |