Skip to content

Commit

Permalink
Fix #2492: Crash if extension module has hidden import to ctypes.
Browse files Browse the repository at this point in the history
Includes regression test.
  • Loading branch information
htgoebel committed Mar 10, 2017
1 parent e13702c commit 17a49a9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 1 addition & 2 deletions PyInstaller/depend/analysis.py
Expand Up @@ -534,9 +534,8 @@ def get_co_using_ctypes(self):
referers = self.getReferers(node)
for r in referers:
r_ident = r.identifier
r_type = type(node).__name__
# Ensure that modulegraph objects has attribute 'code'.
if r_type 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
35 changes: 35 additions & 0 deletions tests/functional/test_regression.py
@@ -0,0 +1,35 @@
#-----------------------------------------------------------------------------
# Copyright (c) 2005-2017, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------


import pytest
import py.path

from PyInstaller.depend import analysis
from PyInstaller.building.build_main import Analysis

def test_issue_2492(monkeypatch, tmpdir):
# Crash if an extension module has an hidden import to ctypes (e.g. added
# by the hook).

# Need to set up some values
monkeypatch.setattr('PyInstaller.config.CONF',
{'workpath': str(tmpdir),
'spec': str(tmpdir),
'warnfile': str(tmpdir.join('warn.txt')),
'hiddenimports': []})
# Speedup: avoid analyzing base_library.zip
monkeypatch.setattr(analysis, 'PY3_BASE_MODULES', [])

script = tmpdir.join('script.py')
script.write('import _struct')
# create a hook
tmpdir.join('hook-_struct.py').write('hiddenimports = ["ctypes"]')
a = Analysis([str(script)], hookspath=[str(tmpdir)],
excludes=['encodings', 'pydoc', 'xml', 'distutils'])

0 comments on commit 17a49a9

Please sign in to comment.