[pypy-commit] cffi cffi-1.0: Support dotted names in 'module_name'
arigo
noreply at buildbot.pypy.org
Sun Apr 26 18:10:39 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1852:288228787b93
Date: 2015-04-26 18:11 +0200
http://bitbucket.org/cffi/cffi/changeset/288228787b93/
Log: Support dotted names in 'module_name'
diff --git a/_cffi1/recompiler.py b/_cffi1/recompiler.py
--- a/_cffi1/recompiler.py
+++ b/_cffi1/recompiler.py
@@ -209,8 +209,9 @@
prnt()
#
# the init function, loading _cffi_backend and calling a method there
+ base_module_name = self.module_name.split('.')[-1]
prnt('PyMODINIT_FUNC')
- prnt('init%s(void)' % (self.module_name,))
+ prnt('init%s(void)' % (base_module_name,))
prnt('{')
prnt(' if (_cffi_init() < 0)')
prnt(' return;')
diff --git a/_cffi1/test_recompiler.py b/_cffi1/test_recompiler.py
--- a/_cffi1/test_recompiler.py
+++ b/_cffi1/test_recompiler.py
@@ -1,6 +1,7 @@
-import sys, py
+import sys, os, py
from cffi import FFI, VerificationError
from _cffi1 import recompiler
+from _cffi1.udir import udir
def check_type_table(input, expected_output):
@@ -400,3 +401,22 @@
assert ffi1.typeof(name) is not ffi2.typeof(name)
# sanity check: twice 'ffi1'
assert ffi1.typeof("struct foo_s*") is ffi1.typeof("struct foo_s *")
+
+def test_module_name_in_package():
+ ffi = FFI()
+ ffi.cdef("int foo(int);")
+ recompiler.recompile(ffi, "test_module_name_in_package.mymod",
+ "int foo(int x) { return x + 32; }",
+ tmpdir=str(udir))
+ old_sys_path = sys.path[:]
+ try:
+ package_dir = udir.join('test_module_name_in_package')
+ assert os.path.isdir(str(package_dir))
+ assert len(os.listdir(str(package_dir))) > 0
+ package_dir.join('__init__.py').write('')
+ #
+ sys.path.insert(0, str(udir))
+ import test_module_name_in_package.mymod
+ assert test_module_name_in_package.mymod.lib.foo(10) == 42
+ finally:
+ sys.path[:] = old_sys_path
More information about the pypy-commit
mailing list