Skip to content
Merged
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
83 changes: 0 additions & 83 deletions src/cffi/_imp_emulation.py

This file was deleted.

38 changes: 25 additions & 13 deletions src/cffi/vengine_cpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@
# DEPRECATED: implementation for ffi.verify()
#
import sys
import _imp
import importlib.machinery
import importlib.util
from . import model
from .error import VerificationError
from . import _imp_emulation as imp


def _load_dynamic(name, path):
loader = importlib.machinery.ExtensionFileLoader(name, path)
spec = importlib.util.spec_from_file_location(name, path, loader=loader)
module = importlib.util.module_from_spec(spec)
sys.modules[name] = module
try:
loader.exec_module(module)
except BaseException:
del sys.modules[name]
raise
return module


class VCPythonEngine:
Expand All @@ -21,18 +36,15 @@ def patch_extension_kwds(self, kwds):
pass

def find_module(self, module_name, path, so_suffixes):
try:
f, filename, descr = imp.find_module(module_name, path)
except ImportError:
spec = importlib.machinery.PathFinder.find_spec(module_name, path)
if spec is None or not spec.has_location:
return None
if f is not None:
f.close()
# Note that after a setuptools installation, there are both .py
# and .so files with the same basename. The code here relies on
# imp.find_module() locating the .so in priority.
if descr[0] not in so_suffixes:
# the path finder locating the .so in priority.
if not spec.origin.endswith(tuple(so_suffixes)):
return None
return filename
return spec.origin

def collect_types(self):
self._typesdict = {}
Expand Down Expand Up @@ -132,23 +144,23 @@ def write_source_to_f(self):
def load_library(self, flags=None):
# XXX review all usages of 'self' here!
# import it as a new extension module
imp.acquire_lock()
_imp.acquire_lock()
try:
if hasattr(sys, "getdlopenflags"):
previous_flags = sys.getdlopenflags()
try:
if hasattr(sys, "setdlopenflags") and flags is not None:
sys.setdlopenflags(flags)
module = imp.load_dynamic(self.verifier.get_module_name(),
self.verifier.modulefilename)
module = _load_dynamic(self.verifier.get_module_name(),
self.verifier.modulefilename)
except ImportError as e:
error = f"importing {self.verifier.modulefilename!r}: {e}"
raise VerificationError(error)
finally:
if hasattr(sys, "setdlopenflags"):
sys.setdlopenflags(previous_flags)
finally:
imp.release_lock()
_imp.release_lock()
#
# call loading_cpy_struct() to get the struct layout inferred by
# the C compiler
Expand Down
4 changes: 2 additions & 2 deletions testing/cffi0/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -1594,10 +1594,10 @@ def test_callback_in_thread():
if sys.platform == 'win32':
pytest.skip("pthread only")
import os, subprocess
from cffi import _imp_emulation as imp
import cffi
arg = os.path.join(os.path.dirname(__file__), 'callback_in_thread.py')
g = subprocess.Popen([sys.executable, arg,
os.path.dirname(imp.find_module('cffi')[1])])
os.path.dirname(os.path.dirname(cffi.__file__))])
result = g.wait()
assert result == 0

Expand Down
4 changes: 2 additions & 2 deletions testing/cffi1/test_verify1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1556,10 +1556,10 @@ def test_callback_in_thread():
if sys.platform == 'win32':
pytest.skip("pthread only")
import os, subprocess
from cffi import _imp_emulation as imp
import cffi
arg = os.path.join(os.path.dirname(__file__), 'callback_in_thread.py')
g = subprocess.Popen([sys.executable, arg,
os.path.dirname(imp.find_module('cffi')[1])])
os.path.dirname(os.path.dirname(cffi.__file__))])
result = g.wait()
assert result == 0

Expand Down
2 changes: 1 addition & 1 deletion testing/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import site, subprocess
from pathlib import Path
import pytest
from cffi._imp_emulation import load_dynamic
from cffi.vengine_cpy import _load_dynamic as load_dynamic

__all__ = ['load_dynamic']

Expand Down
Loading