Author: Jeremy Thurgood <[email protected]>
Branch: split-verify
Changeset: r1354:e5fe5874e20f
Date: 2013-10-06 13:21 +0200
http://bitbucket.org/cffi/cffi/changeset/e5fe5874e20f/
Log: Move FFIBuilder into its own module.
diff --git a/cffi/__init__.py b/cffi/__init__.py
--- a/cffi/__init__.py
+++ b/cffi/__init__.py
@@ -1,7 +1,8 @@
__all__ = ['FFI', 'VerificationError', 'VerificationMissing', 'CDefError',
- 'FFIError']
+ 'FFIError', 'FFIBuilder']
-from .api import FFI, CDefError, FFIError, FFIBuilder
+from .api import FFI, CDefError, FFIError
+from .builder import FFIBuilder
from .ffiplatform import VerificationError, VerificationMissing
__version__ = "0.7.2"
diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -448,74 +448,3 @@
return None
else:
return ffi._get_cached_btype(tp)
-
-
-class FFIBuilder(object):
- def __init__(self, module_name, module_path, backend=None):
- self._module_name = module_name
- self._module_path = module_path
- self.ffi = FFI(backend=backend)
- self._built_files = []
- self._module_source = "\n".join([
- "from cffi import FFI",
- "",
- "ffi = FFI()",
- "",
- ])
-
- def cdef(self, csource, override=False):
- self.ffi.cdef(csource, override=override)
- self._module_source += "ffi.cdef(%r, override=%r)\n" % (
- csource, override)
-
- def add_dlopen(self, libname, name, flags=0):
- lib = self.ffi.dlopen(name, flags=flags)
- self._module_source += '\n'.join([
- "def load_%s():",
- " return ffi.dlopen(%r, flags=%r)",
- "",
- ]) % (libname, name, flags)
- return lib
-
- def makelib(self, libname, source='', **kwargs):
- # XXX: We use force_generic_engine here because vengine_cpy collects
- # types when it writes the source.
- import os.path
- from .verifier import Verifier, _get_so_suffix
- self.ffi.verifier = Verifier(
- self.ffi, source, force_generic_engine=True, **kwargs)
- libfilename = '_'.join([self._module_name, libname])
- libfilepath = os.path.join(
- self._module_path, libfilename + _get_so_suffix())
- self.ffi.verifier.make_library(libfilepath)
- self._module_source += '\n'.join([
- "def load_%s():",
- " from cffi.verifier import Verifier",
- " import os.path",
- " module_path = os.path.dirname(__file__)",
- " verifier = Verifier(",
- " ffi, None, module_path, %r, force_generic_engine=True)",
- " verifier._has_module = True",
- " return verifier._load_library()",
- "",
- ]) % (libname, libfilename)
- self._built_files.append(libfilepath)
-
- def write_ffi_module(self):
- import os
- try:
- os.makedirs(self._module_path)
- except OSError:
- pass
-
- module_filepath = os.path.join(
- self._module_path, self._module_name + '.py')
- file = open(module_filepath, 'w')
- try:
- file.write(self._module_source)
- finally:
- file.close()
- self._built_files.append(module_filepath)
-
- def list_built_files(self):
- return self._built_files
diff --git a/cffi/builder.py b/cffi/builder.py
new file mode 100644
--- /dev/null
+++ b/cffi/builder.py
@@ -0,0 +1,72 @@
+from .api import FFI
+
+
+class FFIBuilder(object):
+ def __init__(self, module_name, module_path, backend=None):
+ self._module_name = module_name
+ self._module_path = module_path
+ self.ffi = FFI(backend=backend)
+ self._built_files = []
+ self._module_source = "\n".join([
+ "from cffi import FFI",
+ "",
+ "ffi = FFI()",
+ "",
+ ])
+
+ def cdef(self, csource, override=False):
+ self.ffi.cdef(csource, override=override)
+ self._module_source += "ffi.cdef(%r, override=%r)\n" % (
+ csource, override)
+
+ def add_dlopen(self, libname, name, flags=0):
+ lib = self.ffi.dlopen(name, flags=flags)
+ self._module_source += '\n'.join([
+ "def load_%s():",
+ " return ffi.dlopen(%r, flags=%r)",
+ "",
+ ]) % (libname, name, flags)
+ return lib
+
+ def makelib(self, libname, source='', **kwargs):
+ # XXX: We use force_generic_engine here because vengine_cpy collects
+ # types when it writes the source.
+ import os.path
+ from .verifier import Verifier, _get_so_suffix
+ self.ffi.verifier = Verifier(
+ self.ffi, source, force_generic_engine=True, **kwargs)
+ libfilename = '_'.join([self._module_name, libname])
+ libfilepath = os.path.join(
+ self._module_path, libfilename + _get_so_suffix())
+ self.ffi.verifier.make_library(libfilepath)
+ self._module_source += '\n'.join([
+ "def load_%s():",
+ " from cffi.verifier import Verifier",
+ " import os.path",
+ " module_path = os.path.dirname(__file__)",
+ " verifier = Verifier(",
+ " ffi, None, module_path, %r, force_generic_engine=True)",
+ " verifier._has_module = True",
+ " return verifier._load_library()",
+ "",
+ ]) % (libname, libfilename)
+ self._built_files.append(libfilepath)
+
+ def write_ffi_module(self):
+ import os
+ try:
+ os.makedirs(self._module_path)
+ except OSError:
+ pass
+
+ module_filepath = os.path.join(
+ self._module_path, self._module_name + '.py')
+ file = open(module_filepath, 'w')
+ try:
+ file.write(self._module_source)
+ finally:
+ file.close()
+ self._built_files.append(module_filepath)
+
+ def list_built_files(self):
+ return self._built_files
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit