From: Serhiy Storchaka Date: Thu, 12 Jan 2017 15:00:32 +0000 (+0200) Subject: Issue #29082: Fixed loading libraries in ctypes by unicode names on Windows. X-Git-Tag: v2.7.14rc1~305 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=99ba17f5535ab07d999b302f48457eeb5e9b6840;p=python Issue #29082: Fixed loading libraries in ctypes by unicode names on Windows. Original patch by Chi Hsuan Yen. --- diff --git a/Lib/ctypes/test/test_loading.py b/Lib/ctypes/test/test_loading.py index 81a27e35df..e64fff7b03 100644 --- a/Lib/ctypes/test/test_loading.py +++ b/Lib/ctypes/test/test_loading.py @@ -3,6 +3,7 @@ import sys, unittest 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 @@ class LoaderTest(unittest.TestCase): 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 --git a/Misc/NEWS b/Misc/NEWS index ce3853c09f..8b5f146d11 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -23,6 +23,9 @@ Extension Modules 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 --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 3a12eb603e..91233d508c 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -1281,7 +1281,7 @@ static PyObject *load_library(PyObject *self, PyObject *args) 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));