(original) (raw)
changeset: 106105:4ce22d69e134 branch: 2.7 parent: 106100:3a01ade11123 user: Serhiy Storchaka storchaka@gmail.com date: Thu Jan 12 17:00:32 2017 +0200 files: Lib/ctypes/test/test_loading.py Misc/NEWS Modules/_ctypes/callproc.c description: Issue #29082: Fixed loading libraries in ctypes by unicode names on Windows. Original patch by Chi Hsuan Yen. diff -r 3a01ade11123 -r 4ce22d69e134 Lib/ctypes/test/test_loading.py --- a/Lib/ctypes/test/test_loading.py Wed Jan 11 23:40:23 2017 -0800 +++ b/Lib/ctypes/test/test_loading.py Thu Jan 12 17:00:32 2017 +0200 @@ -3,6 +3,7 @@ import os from ctypes.util import find_library from ctypes.test import is_resource_enabled +import test.test_support as support libc_name = None if os.name == "nt": @@ -27,6 +28,12 @@ CDLL(os.path.basename(libc_name)) self.assertRaises(OSError, CDLL, self.unknowndll) + @support.requires_unicode + @unittest.skipUnless(libc_name is not None, 'could not find libc') + def test_load_unicode(self): + CDLL(unicode(libc_name)) + self.assertRaises(OSError, CDLL, unicode(self.unknowndll)) + @unittest.skipUnless(libc_name is not None, 'could not find libc') @unittest.skipUnless(libc_name is not None and os.path.basename(libc_name) == "libc.so.6", diff -r 3a01ade11123 -r 4ce22d69e134 Misc/NEWS --- a/Misc/NEWS Wed Jan 11 23:40:23 2017 -0800 +++ b/Misc/NEWS Thu Jan 12 17:00:32 2017 +0200 @@ -23,6 +23,9 @@ Library ------- +- Issue #29082: Fixed loading libraries in ctypes by unicode names on Windows. + Original patch by Chi Hsuan Yen. + - Issue #29006: Revert change from issue #10513 for making sqlite more liable to emit "database table is locked" errors. diff -r 3a01ade11123 -r 4ce22d69e134 Modules/_ctypes/callproc.c --- a/Modules/_ctypes/callproc.c Wed Jan 11 23:40:23 2017 -0800 +++ b/Modules/_ctypes/callproc.c Thu Jan 12 17:00:32 2017 +0200 @@ -1281,7 +1281,7 @@ PyObject *nameobj; PyObject *ignored; HMODULE hMod; - if (!PyArg_ParseTuple(args, "S|O:LoadLibrary", &nameobj, &ignored)) + if (!PyArg_ParseTuple(args, "O|O:LoadLibrary", &nameobj, &ignored)) return NULL; #ifdef _UNICODE name = alloca((PyString_Size(nameobj) + 1) * sizeof(WCHAR)); /storchaka@gmail.com