diff --git a/Lib/ctypes/test/test_loading.py b/Lib/ctypes/test/test_loading.py --- a/Lib/ctypes/test/test_loading.py +++ b/Lib/ctypes/test/test_loading.py @@ -105,10 +105,17 @@ class LoaderTest(unittest.TestCase): windll.kernel32.GetProcAddress.argtypes = c_void_p, c_char_p windll.kernel32.GetProcAddress.restype = c_void_p proc = windll.kernel32.GetProcAddress(advapi32._handle, "CloseEventLog") self.assertTrue(proc) # This is the real test: call the function via 'call_function' self.assertEqual(0, call_function(proc, (None,))) + def test_LoadLibrary_args(self): + # cdll.LoadLibrary accepts both bytes-like and unicode objects + self.assertIsNotNone(libc_name) + + cdll.LoadLibrary(libc_name) + cdll.LoadLibrary(libc_name.decode('ascii')) + if __name__ == "__main__": unittest.main() diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -1276,17 +1276,17 @@ Load an executable (usually a DLL), and The handle may be used to locate exported functions in this\n\ module.\n"; static PyObject *load_library(PyObject *self, PyObject *args) { TCHAR *name; 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)); if (!name) { PyErr_NoMemory(); return NULL; }