Author: Stefano Rivera <stef...@rivera.za.net> Branch: split-verify Changeset: r1369:1e3bfa8c08ae Date: 2013-10-07 01:37 +0200 http://bitbucket.org/cffi/cffi/changeset/1e3bfa8c08ae/
Log: Port distutils_package_2 to FFIBuilder diff --git a/testing/snippets/distutils_package_2/setup.py b/testing/snippets/distutils_package_2/setup.py --- a/testing/snippets/distutils_package_2/setup.py +++ b/testing/snippets/distutils_package_2/setup.py @@ -1,8 +1,13 @@ +from distutils.core import setup -from distutils.core import setup -import snip_basic_verify2 +from cffi.packaging import FFIExtension, build_ext + +import snip_basic_module2.ffibuilder + setup( - packages=['snip_basic_verify2'], - ext_package='snip_basic_verify2', - ext_modules=[snip_basic_verify2.ffi.verifier.get_extension()]) + packages=['snip_basic_module2'], + ext_package='snip_basic_module2', + ext_modules=[FFIExtension(snip_basic_module2.ffibuilder.build_ffi)], + cmdclass={'build_ext': build_ext}, +) diff --git a/testing/snippets/distutils_package_2/snip_basic_module2/__init__.py b/testing/snippets/distutils_package_2/snip_basic_module2/__init__.py new file mode 100644 diff --git a/testing/snippets/distutils_package_2/snip_basic_verify2/__init__.py b/testing/snippets/distutils_package_2/snip_basic_module2/ffibuilder.py rename from testing/snippets/distutils_package_2/snip_basic_verify2/__init__.py rename to testing/snippets/distutils_package_2/snip_basic_module2/ffibuilder.py --- a/testing/snippets/distutils_package_2/snip_basic_verify2/__init__.py +++ b/testing/snippets/distutils_package_2/snip_basic_module2/ffibuilder.py @@ -1,18 +1,21 @@ - -from cffi import FFI import sys -ffi = FFI() -ffi.cdef(""" // some declarations from the man page +from cffi import FFIBuilder + + +def build_ffi(path): + builder = FFIBuilder('_ffi', path) + builder.cdef(""" // some declarations from the man page struct passwd { char *pw_name; ...; }; struct passwd *getpwuid(int uid); -""") -C = ffi.verify(""" // passed to the real C compiler -#include <sys/types.h> -#include <pwd.h> -""", libraries=[], # or a list of libraries to link with - ext_package='snip_basic_verify2', - force_generic_engine=hasattr(sys, '_force_generic_engine_')) + """) + builder.makelib('passwd', """ // passed to the real C compiler + #include <sys/types.h> + #include <pwd.h> + """, libraries=[], # or a list of libraries to link with + force_generic_engine=hasattr(sys, '_force_generic_engine_')) + builder.write_ffi_module() + return builder.list_built_files() diff --git a/testing/test_zintegration.py b/testing/test_zintegration.py --- a/testing/test_zintegration.py +++ b/testing/test_zintegration.py @@ -108,9 +108,10 @@ def test_distutils_package_2(): run_setup_and_program("distutils_package_2", ''' - import snip_basic_verify2 - p = snip_basic_verify2.C.getpwuid(0) - assert snip_basic_verify2.ffi.string(p.pw_name) == b"root" + from snip_basic_module2 import _ffi + lib = _ffi.load_passwd() + p = lib.getpwuid(0) + assert _ffi.string(p.pw_name) == b"root" ''') def test_setuptools_module(): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit