Skip to content

Commit

Permalink
Merge pull request #2098 from virtuald/cdll-none
Browse files Browse the repository at this point in the history
Fix: First argument to ctypes.CDLL can be None.
  • Loading branch information
htgoebel committed Jul 22, 2016
2 parents 14dabc5 + 63e47e3 commit 8c577c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
21 changes: 10 additions & 11 deletions PyInstaller/loader/pyiboot01_bootstrap.py
Expand Up @@ -123,21 +123,24 @@ def isatty(self):
import os
from ctypes import LibraryLoader, DEFAULT_MODE

class PyInstallerCDLL(ctypes.CDLL):
def __init__(self, name, *args, **kwargs):
def _frozen_name(name):
if name:
frozen_name = os.path.join(sys._MEIPASS, os.path.basename(name))
if os.path.exists(frozen_name):
name = frozen_name
return name

class PyInstallerCDLL(ctypes.CDLL):
def __init__(self, name, *args, **kwargs):
name = _frozen_name(name)
super(PyInstallerCDLL, self).__init__(name, *args, **kwargs)

ctypes.CDLL = PyInstallerCDLL
ctypes.cdll = LibraryLoader(PyInstallerCDLL)

class PyInstallerPyDLL(ctypes.PyDLL):
def __init__(self, name, *args, **kwargs):
frozen_name = os.path.join(sys._MEIPASS, os.path.basename(name))
if os.path.exists(frozen_name):
name = frozen_name
name = _frozen_name(name)
super(PyInstallerPyDLL, self).__init__(name, *args, **kwargs)

ctypes.PyDLL = PyInstallerPyDLL
Expand All @@ -146,19 +149,15 @@ def __init__(self, name, *args, **kwargs):
if sys.platform.startswith('win'):
class PyInstallerWinDLL(ctypes.WinDLL):
def __init__(self, name,*args, **kwargs):
frozen_name = os.path.join(sys._MEIPASS, os.path.basename(name))
if os.path.exists(frozen_name):
name = frozen_name
name = _frozen_name(name)
super(PyInstallerWinDLL, self).__init__(name, *args, **kwargs)

ctypes.WinDLL = PyInstallerWinDLL
ctypes.windll = LibraryLoader(PyInstallerWinDLL)

class PyInstallerOleDLL(ctypes.OleDLL):
def __init__(self, name,*args, **kwargs):
frozen_name = os.path.join(sys._MEIPASS, os.path.basename(name))
if os.path.exists(frozen_name):
name = frozen_name
name = _frozen_name(name)
super(PyInstallerOleDLL, self).__init__(name, *args, **kwargs)

ctypes.OleDLL = PyInstallerOleDLL
Expand Down
11 changes: 11 additions & 0 deletions tests/functional/test_import.py
Expand Up @@ -191,6 +191,17 @@ def test_ctypes_CDLL_c(pyi_builder):
assert lib is not None
""")

@skipif_no_compiler
def test_ctypes_CDLL_None(pyi_builder):
# Make sure we are able to load CDLL(None)
# -> pip does this for some reason
pyi_builder.test_source(
"""
import ctypes, ctypes.util
lib = ctypes.CDLL(None)
assert lib is not None
""")

import PyInstaller.depend.utils
__orig_resolveCtypesImports = PyInstaller.depend.utils._resolveCtypesImports

Expand Down

0 comments on commit 8c577c1

Please sign in to comment.