Skip to content

Commit

Permalink
Fix fix pyinstaller#2492: Crash if extension module has hidden import…
Browse files Browse the repository at this point in the history
… to ctypes.

Includes test-case.

The fix (see two commits back, 17a49a9)
raised another issue: ctype imports from the main script were ignored,
since "Script" is not part of "PURE_PYTHON_MODULE_TYPES".
  • Loading branch information
htgoebel committed Mar 11, 2017
1 parent 108706c commit 4319d4e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion PyInstaller/depend/analysis.py
Expand Up @@ -529,13 +529,14 @@ def get_co_using_ctypes(self):
:return: Code objects that might be scanned for module dependencies.
"""
co_dict = {}
pure_python_module_types = PURE_PYTHON_MODULE_TYPES | {'Script',}
node = self.findNode('ctypes')
if node:
referers = self.getReferers(node)
for r in referers:
r_ident = r.identifier
# Ensure that modulegraph objects has attribute 'code'.
if type(r).__name__ in PURE_PYTHON_MODULE_TYPES:
if type(r).__name__ in pure_python_module_types:
if r_ident == 'ctypes' or r_ident.startswith('ctypes.'):
# Skip modules of 'ctypes' package.
continue
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_pyimodulegraph.py
Expand Up @@ -9,12 +9,23 @@


import pytest
import types

from PyInstaller import HOMEPATH
from PyInstaller.depend import analysis
from PyInstaller.lib.modulegraph import modulegraph


def test_get_co_using_ctypes(tmpdir):
script = tmpdir.join('script.py')
script.write('import ctypes')
mg = analysis.PyiModuleGraph(HOMEPATH)
mg.run_script(str(script))
res = mg.get_co_using_ctypes()
assert len(res) == 1
assert isinstance(res[str(script)], types.CodeType)


def test_get_co_using_ctypes_from_extension():
# If an extension module has an hidden import to ctypes (e.g. added by the
# hook), the extension moduel must nor show up in the result of
Expand Down

0 comments on commit 4319d4e

Please sign in to comment.