Esempio n. 1
0
    def setup_class(cls):
        from rpython.tool.udir import udir
        from rpython.translator.tool.cbuild import ExternalCompilationInfo
        from rpython.translator.platform import platform

        BaseFfiTest.setup_class()
        # prepare C code as an example, so we can load it and call
        # it via rlib.libffi
        c_file = udir.ensure("test_libffi", dir=1).join("foolib.c")
        # automatically collect the C source from the docstrings of the tests
        snippets = []
        for name in dir(cls):
            if name.startswith('test_'):
                meth = getattr(cls, name)
                # the heuristic to determine it it's really C code could be
                # improved: so far we just check that there is a '{' :-)
                if meth.__doc__ is not None and '{' in meth.__doc__:
                    snippets.append(meth.__doc__)
        #
        INCLUDE = '#include "src/precommondefs.h"\n'
        c_file.write(INCLUDE + str(py.code.Source('\n'.join(snippets))))
        eci = ExternalCompilationInfo(include_dirs=[cdir])
        cls.libfoo_name = str(
            platform.compile([c_file], eci, 'x', standalone=False))
        cls.dll = cls.CDLL(cls.libfoo_name)
Esempio n. 2
0
    def setup_class(cls):
        from rpython.tool.udir import udir
        from rpython.translator.tool.cbuild import ExternalCompilationInfo
        from rpython.translator.platform import platform

        BaseFfiTest.setup_class()
        # prepare C code as an example, so we can load it and call
        # it via rlib.libffi
        c_file = udir.ensure("test_libffi", dir=1).join("foolib.c")
        # automatically collect the C source from the docstrings of the tests
        snippets = []
        for name in dir(cls):
            if name.startswith('test_'):
                meth = getattr(cls, name)
                # the heuristic to determine it it's really C code could be
                # improved: so far we just check that there is a '{' :-)
                if meth.__doc__ is not None and '{' in meth.__doc__:
                    snippets.append(meth.__doc__)
        #
        INCLUDE = '#include "src/precommondefs.h"\n'
        c_file.write(INCLUDE + str(py.code.Source('\n'.join(snippets))))
        eci = ExternalCompilationInfo(include_dirs=[cdir])
        cls.libfoo_name = str(platform.compile([c_file], eci, 'x',
                                               standalone=False))
        cls.dll = cls.CDLL(cls.libfoo_name)
Esempio n. 3
0
    def setup_class(cls):
        from rpython.tool.udir import udir
        from rpython.translator.tool.cbuild import ExternalCompilationInfo
        from rpython.translator.tool.cbuild import STANDARD_DEFINES
        from rpython.translator.platform import platform

        BaseFfiTest.setup_class()
        # prepare C code as an example, so we can load it and call
        # it via rlib.libffi
        c_file = udir.ensure("test_libffi", dir=1).join("foolib.c")
        # automatically collect the C source from the docstrings of the tests
        snippets = []
        exports = []
        for name in dir(cls):
            if name.startswith('test_'):
                meth = getattr(cls, name)
                # the heuristic to determine it it's really C code could be
                # improved: so far we just check that there is a '{' :-)
                if meth.__doc__ is not None and '{' in meth.__doc__:
                    snippets.append(meth.__doc__)
                    import re
                    for match in re.finditer(" ([A-Za-z_]+)\(", meth.__doc__):
                        exports.append(match.group(1))
        #
        c_file.write(STANDARD_DEFINES + str(py.code.Source('\n'.join(snippets))))
        eci = ExternalCompilationInfo(export_symbols=exports)
        cls.libfoo_name = str(platform.compile([c_file], eci, 'x',
                                               standalone=False))
        cls.dll = cls.CDLL(cls.libfoo_name)