Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: using ctypes leads to an exception and premature script exit #47

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ build_script:
# Patch the PyInstaller building\utils.py to avoid storing project path
# names.
- "pushd %PYTHON%\\Lib\\site-packages\\PyInstaller\\building && python -m patch %PROJDIR%\\hooks\\utils.py.diff && popd"
# Patch the PyInstall loader\pyiboot01_bootstrap.py to keep ctypes' patches a scope other than global
- "pushd %PYTHON%\\Lib\\site-packages\\PyInstaller\\loader && python -m patch %PROJDIR%\\hooks\\pyiboot01_bootstrap.py.diff && popd"
- del /S /Q %PYTHON%\*.pyc >NUL
- del /S /Q %PYTHON%\*.pyo >NUL
# Save the artifact immediately
Expand Down
33 changes: 33 additions & 0 deletions hooks/pyiboot01_bootstrap.py.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--- pyiboot01_bootstrap.py 2019-08-12 17:37:25.460219000 +1000
+++ pyiboot01_bootstrap.py 2019-08-13 18:10:32.084968800 +1000
@@ -123,11 +123,12 @@
if sys.warnoptions:
import warnings

-try:
+def _setup_ctypes():
import ctypes
import os
+ import sys
from ctypes import LibraryLoader, DEFAULT_MODE
-
+
def _frozen_name(name):
if name:
frozen_name = os.path.join(sys._MEIPASS, os.path.basename(name))
@@ -186,6 +186,8 @@

ctypes.OleDLL = PyInstallerOleDLL
ctypes.oledll = LibraryLoader(PyInstallerOleDLL)
+try:
+ _setup_ctypes()
except ImportError:
pass

@@ -213,4 +215,4 @@
# use-case, see issue #653.
if os.path.isdir(d):
for fn in os.listdir(d):
- sys.path.append(os.path.join(d, fn))
+ sys.path.append(os.path.join(d, fn))
\ No newline at end of file
2 changes: 1 addition & 1 deletion pyexe.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def skip(*args, **kwargs):
# Generate the globals/locals environment
globenv = {}
for key in list(globals().keys()):
if key.startswith('_') and key != '_frozen_name':
if key.startswith('_') and not key in ['_frozen_name','_setup_ctypes']:
globenv[key] = globals()[key]
if RunFile:
run_file(RunFile, RunFileArgv, SkipFirstLine, globenv)
Expand Down