[pypy-commit] cffi default: Fix (motivated by a pypy without cpyext): if we're using vengine_gen.py,
arigo
noreply at buildbot.pypy.org
Mon May 20 13:52:36 CEST 2013
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r1253:617edf867775
Date: 2013-05-20 13:52 +0200
http://bitbucket.org/cffi/cffi/changeset/617edf867775/
Log: Fix (motivated by a pypy without cpyext): if we're using
vengine_gen.py, then we should not use imp.find_module() to locate
our compiled module, because it's actually not a CPython C API
module at all. Instead, just walk sys.path in that case.
diff --git a/cffi/vengine_cpy.py b/cffi/vengine_cpy.py
--- a/cffi/vengine_cpy.py
+++ b/cffi/vengine_cpy.py
@@ -15,6 +15,20 @@
def patch_extension_kwds(self, kwds):
pass
+ def find_module(self, module_name, path, so_suffix):
+ try:
+ f, filename, descr = imp.find_module(module_name, path)
+ except ImportError:
+ 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] != so_suffix:
+ return None
+ return filename
+
def collect_types(self):
self._typesdict = {}
self._generate("collecttype")
diff --git a/cffi/vengine_gen.py b/cffi/vengine_gen.py
--- a/cffi/vengine_gen.py
+++ b/cffi/vengine_gen.py
@@ -1,4 +1,4 @@
-import sys
+import sys, os
import types
from . import model, ffiplatform
@@ -20,6 +20,16 @@
# up in kwds['export_symbols'].
kwds.setdefault('export_symbols', self.export_symbols)
+ def find_module(self, module_name, path, so_suffix):
+ basename = module_name + so_suffix
+ if path is None:
+ path = sys.path
+ for dirname in path:
+ filename = os.path.join(dirname, basename)
+ if os.path.isfile(filename):
+ return filename
+ return None
+
def collect_types(self):
pass # not needed in the generic engine
diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -102,21 +102,10 @@
path = pkg.__path__
else:
path = None
- try:
- f, filename, descr = imp.find_module(self.get_module_name(),
- path)
- except ImportError:
+ filename = self._vengine.find_module(self.get_module_name(), path,
+ _get_so_suffix())
+ if filename is None:
return
- if f is not None:
- f.close()
- if filename.lower().endswith('.py'):
- # on PyPy, if there are both .py and .pypy-19.so files in
- # the same directory, the .py file is returned. That's the
- # case after a setuptools installation. We never want to
- # load the .py file here...
- filename = filename[:-3] + _get_so_suffix()
- if not os.path.isfile(filename):
- return
self.modulefilename = filename
self._vengine.collect_types()
self._has_module = True
More information about the pypy-commit
mailing list