summaryrefslogtreecommitdiff
path: root/cffi
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2015-01-08 10:13:01 +0100
committerArmin Rigo <arigo@tunes.org>2015-01-08 10:13:01 +0100
commit6d2a5a8ca8d5f78eae073e78a7f0002107041a19 (patch)
treea6550a36674808783acc78f1c5d5af4b1ce8be9d /cffi
parentcab085261800b001208df051eb206f8326acf301 (diff)
downloadcffi-6d2a5a8ca8d5f78eae073e78a7f0002107041a19.tar.gz
Issue #173
Test and fix for the implicit __pycache__ directory location.
Diffstat (limited to 'cffi')
-rw-r--r--cffi/api.py15
-rw-r--r--cffi/verifier.py5
2 files changed, 18 insertions, 2 deletions
diff --git a/cffi/api.py b/cffi/api.py
index fec752f..94d0b1f 100644
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -347,11 +347,24 @@ class FFI(object):
(including calling macros). This is unlike 'ffi.dlopen()',
which requires binary compatibility in the signatures.
"""
- from .verifier import Verifier
+ from .verifier import Verifier, _caller_dir_pycache
+ #
+ # If set_unicode(True) was called, insert the UNICODE and
+ # _UNICODE macro declarations
if self._windows_unicode:
self._apply_windows_unicode(kwargs)
+ #
+ # Set the tmpdir here, and not in Verifier.__init__: it picks
+ # up the caller's directory, which we want to be the caller of
+ # ffi.verify(), as opposed to the caller of Veritier().
+ tmpdir = tmpdir or _caller_dir_pycache()
+ #
+ # Make a Verifier() and use it to load the library.
self.verifier = Verifier(self, source, tmpdir, **kwargs)
lib = self.verifier.load_library()
+ #
+ # Save the loaded library for keep-alive purposes, even
+ # if the caller doesn't keep it alive itself (it should).
self._libraries.append(lib)
return lib
diff --git a/cffi/verifier.py b/cffi/verifier.py
index 688a172..ca66be6 100644
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -44,7 +44,7 @@ class Verifier(object):
modulename = '_cffi_%s_%s%s%s' % (tag, self._vengine._class_key,
k1, k2)
suffix = _get_so_suffixes()[0]
- self.tmpdir = tmpdir or os.environ.get('CFFI_TMPDIR') or _caller_dir_pycache()
+ self.tmpdir = tmpdir or _caller_dir_pycache()
self.sourcefilename = os.path.join(self.tmpdir, modulename + source_extension)
self.modulefilename = os.path.join(self.tmpdir, modulename + suffix)
self.ext_package = ext_package
@@ -210,6 +210,9 @@ _TMPDIR = None
def _caller_dir_pycache():
if _TMPDIR:
return _TMPDIR
+ result = os.environ.get('CFFI_TMPDIR')
+ if result:
+ return result
filename = sys._getframe(2).f_code.co_filename
return os.path.abspath(os.path.join(os.path.dirname(filename),
'__pycache__'))