Esempio n. 1
0
 def test_abi_tag(self):
     space1 = maketestobjspace(make_config(None, soabi='footest'))
     space2 = maketestobjspace(make_config(None, soabi=''))
     assert importing.get_so_extension(space1).startswith('.footest')
     if sys.platform == 'win32':
         assert importing.get_so_extension(space2) == '.pyd'
     else:
         assert importing.get_so_extension(space2) == '.so'
Esempio n. 2
0
 def test_abi_tag(self):
     space1 = gettestobjspace(soabi='TEST')
     space2 = gettestobjspace(soabi='')
     if sys.platform == 'win32':
         assert importing.get_so_extension(space1) == '.TESTi.pyd'
         assert importing.get_so_extension(space2) == '.pyd'
     else:
         assert importing.get_so_extension(space1) == '.TESTi.so'
         assert importing.get_so_extension(space2) == '.so'
Esempio n. 3
0
 def test_abi_tag(self):
     space1 = maketestobjspace(make_config(None, soabi="TEST"))
     space2 = maketestobjspace(make_config(None, soabi=""))
     if sys.platform == "win32":
         assert importing.get_so_extension(space1) == ".TESTi.pyd"
         assert importing.get_so_extension(space2) == ".pyd"
     else:
         assert importing.get_so_extension(space1) == ".TESTi.so"
         assert importing.get_so_extension(space2) == ".so"
Esempio n. 4
0
 def test_abi_tag(self):
     space1 = maketestobjspace(make_config(None, soabi='TEST'))
     space2 = maketestobjspace(make_config(None, soabi=''))
     if sys.platform == 'win32':
         assert importing.get_so_extension(space1) == '.TESTi.pyd'
         assert importing.get_so_extension(space2) == '.pyd'
     else:
         assert importing.get_so_extension(space1) == '.TESTi.so'
         assert importing.get_so_extension(space2) == '.so'
Esempio n. 5
0
 def test_abi_tag(self):
     space1 = maketestobjspace(make_config(None, soabi='TEST'))
     space2 = maketestobjspace(make_config(None, soabi=''))
     if sys.platform == 'win32':
         assert importing.get_so_extension(space1) == '.TESTi.pyd'
         assert importing.get_so_extension(space2) == '.pyd'
     else:
         assert importing.get_so_extension(space1) == '.TESTi.so'
         assert importing.get_so_extension(space2) == '.so'
Esempio n. 6
0
 def test_abi_tag(self):
     space1 = gettestobjspace(soabi='TEST')
     space2 = gettestobjspace(soabi='')
     if sys.platform == 'win32':
         assert importing.get_so_extension(space1) == '.TESTi.pyd'
         assert importing.get_so_extension(space2) == '.pyd'
     else:
         assert importing.get_so_extension(space1) == '.TESTi.so'
         assert importing.get_so_extension(space2) == '.so'
Esempio n. 7
0
    def setup_method(self, func):
        AppTestCpythonExtensionBase.setup_method(self, func)

        if hasattr(self, 'cmodule'):
            return

        import os, ctypes

        init = """
        if (Py_IsInitialized())
            Py_InitModule("bar", methods);
        """
        body = """
        long bar_unwrap(PyObject* arg)
        {
            return PyLong_AsLong(arg);
        }
        PyObject* bar_wrap(long l)
        {
            return PyLong_FromLong(l);
        }
        static PyMethodDef methods[] = {
            { NULL }
        };
        """

        modname = self.import_module(name='bar', init=init, body=body, load_it=False)
        from pypy.module.imp.importing import get_so_extension
        soext = get_so_extension(self.space)
        fullmodname = os.path.join(modname, 'bar' + soext)
        self.cmodule = ctypes.CDLL(fullmodname, ctypes.RTLD_GLOBAL)
Esempio n. 8
0
def compile_module(space, modname, **kwds):
    """
    Build an extension module and return the filename of the resulting native
    code file.

    modname is the name of the module, possibly including dots if it is a module
    inside a package.

    Any extra keyword arguments are passed on to ExternalCompilationInfo to
    build the module (so specify your source with one of those).
    """
    modname = modname.split('.')[-1]
    eci = ExternalCompilationInfo(
        export_symbols=['init%s' % (modname,)],
        include_dirs=api.include_dirs,
        **kwds
        )
    eci = eci.convert_sources_to_files()
    dirname = (udir/uniquemodulename('module')).ensure(dir=1)
    soname = platform.platform.compile(
        [], eci,
        outputfilename=str(dirname/modname),
        standalone=False)
    from pypy.module.imp.importing import get_so_extension
    pydname = soname.new(purebasename=modname, ext=get_so_extension(space))
    soname.rename(pydname)
    return str(pydname)
Esempio n. 9
0
def compile_module(space, modname, **kwds):
    """
    Build an extension module and return the filename of the resulting native
    code file.

    modname is the name of the module, possibly including dots if it is a module
    inside a package.

    Any extra keyword arguments are passed on to ExternalCompilationInfo to
    build the module (so specify your source with one of those).
    """
    modname = modname.split('.')[-1]
    eci = ExternalCompilationInfo(export_symbols=['init%s' % (modname, )],
                                  include_dirs=api.include_dirs,
                                  **kwds)
    eci = eci.convert_sources_to_files()
    dirname = (udir / uniquemodulename('module')).ensure(dir=1)
    soname = platform.platform.compile([],
                                       eci,
                                       outputfilename=str(dirname / modname),
                                       standalone=False)
    from pypy.module.imp.importing import get_so_extension
    pydname = soname.new(purebasename=modname, ext=get_so_extension(space))
    soname.rename(pydname)
    return str(pydname)
Esempio n. 10
0
def get_cpyext_info(space):
    from pypy.module.imp.importing import get_so_extension
    state = space.fromcache(State)
    api_library = state.api_lib
    if sys.platform == 'win32':
        libraries = [api_library]
        # '%s' undefined; assuming extern returning int
        compile_extra = ["/we4013"]
        # prevent linking with PythonXX.lib
        w_maj, w_min = space.fixedview(space.sys.get('version_info'), 5)[:2]
        link_extra = ["/NODEFAULTLIB:Python%d%d.lib" %
            (space.int_w(w_maj), space.int_w(w_min))]
    else:
        libraries = []
        if sys.platform.startswith('linux'):
            compile_extra = [
                "-Werror", "-g", "-O0", "-Wp,-U_FORTIFY_SOURCE", "-fPIC"]
            link_extra = ["-g"]
        else:
            compile_extra = link_extra = None
    return SpaceCompiler(space,
        builddir_base=udir,
        include_extra=api.include_dirs,
        compile_extra=compile_extra,
        link_extra=link_extra,
        extra_libs=libraries,
        ext=get_so_extension(space))
Esempio n. 11
0
        def create_cdll(space, name, init, body):
            # the following is loosely from test_cpyext.py import_module; it
            # is copied here to be able to tweak the call to
            # compile_extension_module and to get a different return result
            # than in that function
            code = """
            #include <Python.h>
            /* fix for cpython 2.7 Python.h if running tests with -A
               since pypy compiles with -fvisibility-hidden */
            #undef PyMODINIT_FUNC
            #define PyMODINIT_FUNC RPY_EXPORTED void

            %(body)s

            PyMODINIT_FUNC
            init%(name)s(void) {
            %(init)s
            }
            """ % dict(name=name, init=init, body=body)
            kwds = dict(separate_module_sources=[code])
            mod = compile_extension_module(space, name, **kwds)

            # explicitly load the module as a CDLL rather than as a module
            from pypy.module.imp.importing import get_so_extension
            fullmodname = os.path.join(os.path.dirname(mod),
                                       name + get_so_extension(space))
            return space.newtext(fullmodname)
Esempio n. 12
0
def get_cpyext_info(space):
    from pypy.module.imp.importing import get_so_extension
    state = space.fromcache(State)
    api_library = state.api_lib
    if sys.platform == 'win32':
        libraries = [api_library]
        # '%s' undefined; assuming extern returning int
        compile_extra = ["/we4013"]
        # prevent linking with PythonXX.lib
        w_maj, w_min = space.fixedview(space.sys.get('version_info'), 5)[:2]
        link_extra = [
            "/NODEFAULTLIB:Python%d%d.lib" %
            (space.int_w(w_maj), space.int_w(w_min))
        ]
    else:
        libraries = []
        if sys.platform.startswith('linux'):
            compile_extra = [
                "-Werror", "-g", "-O0", "-Wp,-U_FORTIFY_SOURCE", "-fPIC"
            ]
            link_extra = ["-g"]
        else:
            compile_extra = link_extra = None
    return SpaceCompiler(space,
                         builddir_base=udir,
                         include_extra=api.include_dirs,
                         compile_extra=compile_extra,
                         link_extra=link_extra,
                         extra_libs=libraries,
                         ext=get_so_extension(space))
Esempio n. 13
0
        def create_cdll(space, name, init, body):
            # the following is loosely from test_cpyext.py import_module; it
            # is copied here to be able to tweak the call to
            # compile_extension_module and to get a different return result
            # than in that function
            code = """
            #include <Python.h>
            /* fix for cpython 2.7 Python.h if running tests with -A
               since pypy compiles with -fvisibility-hidden */
            #undef PyMODINIT_FUNC
            #define PyMODINIT_FUNC RPY_EXPORTED void

            %(body)s

            PyMODINIT_FUNC
            init%(name)s(void) {
            %(init)s
            }
            """ % dict(
                name=name, init=init, body=body
            )
            kwds = dict(separate_module_sources=[code])
            mod = compile_extension_module(space, name, **kwds)

            # explicitly load the module as a CDLL rather than as a module
            from pypy.module.imp.importing import get_so_extension

            fullmodname = os.path.join(os.path.dirname(mod), name + get_so_extension(space))
            return space.wrap(fullmodname)
Esempio n. 14
0
        def create_cdll(space, name, init, body, w_symbols):
            # the following is loosely from test_cpyext.py import_module; it
            # is copied here to be able to tweak the call to
            # compile_extension_module and to get a different return result
            # than in that function
            code = """
            #include <Python.h>
            %(body)s

            PyMODINIT_FUNC
            init%(name)s(void) {
            %(init)s
            }
            """ % dict(name=name, init=init, body=body)
            kwds = dict(separate_module_sources=[code])
            symbols = [
                space.str_w(w_item) for w_item in space.fixedview(w_symbols)
            ]
            mod = compile_extension_module(space, name, symbols, **kwds)

            # explicitly load the module as a CDLL rather than as a module
            from pypy.module.imp.importing import get_so_extension
            fullmodname = os.path.join(os.path.dirname(mod),
                                       name + get_so_extension(space))
            return space.wrap(fullmodname)
Esempio n. 15
0
def get_suffixes(space):
    w = space.wrap
    suffixes_w = []
    if space.config.objspace.usemodules.cpyext:
        suffixes_w.append(space.newtuple([w(importing.get_so_extension(space)), w("rb"), w(importing.C_EXTENSION)]))
    suffixes_w.extend(
        [
            space.newtuple([w(".py"), w("U"), w(importing.PY_SOURCE)]),
            space.newtuple([w(".pyc"), w("rb"), w(importing.PY_COMPILED)]),
        ]
    )
    return space.newlist(suffixes_w)
Esempio n. 16
0
def get_suffixes(space):
    w = space.wrap
    suffixes_w = []
    if importing.has_so_extension(space):
        suffixes_w.append(
            space.newtuple([w(importing.get_so_extension(space)),
                            w('rb'), w(importing.C_EXTENSION)]))
    suffixes_w.extend([
        space.newtuple([w('.py'), w('U'), w(importing.PY_SOURCE)]),
        space.newtuple([w('.pyc'), w('rb'), w(importing.PY_COMPILED)]),
        ])
    return space.newlist(suffixes_w)
Esempio n. 17
0
def get_suffixes(space):
    w = space.wrap
    suffixes_w = []
    if space.config.objspace.usemodules.cpyext:
        suffixes_w.append(
            space.newtuple([w(importing.get_so_extension(space)),
                            w('rb'), w(importing.C_EXTENSION)]))
    suffixes_w.extend([
        space.newtuple([w('.py'), w('U'), w(importing.PY_SOURCE)]),
        space.newtuple([w('.pyc'), w('rb'), w(importing.PY_COMPILED)]),
        ])
    return space.newlist(suffixes_w)
Esempio n. 18
0
def get_suffixes(space):
    suffixes_w = []
    if importing.has_so_extension(space):
        suffixes_w.append(
            space.newtuple([space.newtext(importing.get_so_extension(space)),
                            space.newtext('rb'),
                            space.newint(importing.C_EXTENSION)]))
    suffixes_w.extend([
        space.newtuple([space.newtext('.py'),
                        space.newtext('U'),
                        space.newint(importing.PY_SOURCE)]),
        space.newtuple([space.newtext('.pyc'),
                        space.newtext('rb'),
                        space.newint(importing.PY_COMPILED)]),
        ])
    return space.newlist(suffixes_w)
Esempio n. 19
0
def compile_extension_module(space, modname, **kwds):
    """
    Build an extension module and return the filename of the resulting native
    code file.

    modname is the name of the module, possibly including dots if it is a module
    inside a package.

    Any extra keyword arguments are passed on to ExternalCompilationInfo to
    build the module (so specify your source with one of those).
    """
    state = space.fromcache(State)
    api_library = state.api_lib
    if sys.platform == 'win32':
        kwds["libraries"] = [api_library]
        # '%s' undefined; assuming extern returning int
        kwds["compile_extra"] = ["/we4013"]
        # prevent linking with PythonXX.lib
        w_maj, w_min = space.fixedview(space.sys.get('version_info'), 5)[:2]
        kwds["link_extra"] = [
            "/NODEFAULTLIB:Python%d%d.lib" %
            (space.int_w(w_maj), space.int_w(w_min))
        ]
    elif sys.platform == 'darwin':
        kwds["link_files"] = [str(api_library + '.dylib')]
    else:
        kwds["link_files"] = [str(api_library + '.so')]
        if sys.platform.startswith('linux'):
            kwds["compile_extra"] = [
                "-Werror=implicit-function-declaration", "-g", "-O0"
            ]
            kwds["link_extra"] = ["-g"]

    modname = modname.split('.')[-1]
    eci = ExternalCompilationInfo(include_dirs=api.include_dirs, **kwds)
    eci = eci.convert_sources_to_files()
    dirname = (udir / uniquemodulename('module')).ensure(dir=1)
    soname = platform.platform.compile([],
                                       eci,
                                       outputfilename=str(dirname / modname),
                                       standalone=False)
    from pypy.module.imp.importing import get_so_extension
    pydname = soname.new(purebasename=modname, ext=get_so_extension(space))
    soname.rename(pydname)
    return str(pydname)
Esempio n. 20
0
def compile_extension_module(space, modname, **kwds):
    """
    Build an extension module and return the filename of the resulting native
    code file.

    modname is the name of the module, possibly including dots if it is a module
    inside a package.

    Any extra keyword arguments are passed on to ExternalCompilationInfo to
    build the module (so specify your source with one of those).
    """
    state = space.fromcache(State)
    api_library = state.api_lib
    if sys.platform == 'win32':
        kwds["libraries"] = [api_library]
        # '%s' undefined; assuming extern returning int
        kwds["compile_extra"] = ["/we4013"]
        # prevent linking with PythonXX.lib
        w_maj, w_min = space.fixedview(space.sys.get('version_info'), 5)[:2]
        kwds["link_extra"] = ["/NODEFAULTLIB:Python%d%d.lib" %
                              (space.int_w(w_maj), space.int_w(w_min))]
    elif sys.platform == 'darwin':
        kwds["link_files"] = [str(api_library + '.dylib')]
    else:
        kwds["link_files"] = [str(api_library + '.so')]
        if sys.platform.startswith('linux'):
            kwds["compile_extra"]=["-Werror=implicit-function-declaration",
                                   "-g", "-O0"]
            kwds["link_extra"]=["-g"]

    modname = modname.split('.')[-1]
    eci = ExternalCompilationInfo(
        include_dirs=api.include_dirs,
        **kwds
        )
    eci = eci.convert_sources_to_files()
    dirname = (udir/uniquemodulename('module')).ensure(dir=1)
    soname = platform.platform.compile(
        [], eci,
        outputfilename=str(dirname/modname),
        standalone=False)
    from pypy.module.imp.importing import get_so_extension
    pydname = soname.new(purebasename=modname, ext=get_so_extension(space))
    soname.rename(pydname)
    return str(pydname)
Esempio n. 21
0
        def create_cdll(space, name, init, body, w_symbols):
            # the following is loosely from test_cpyext.py import_module; it
            # is copied here to be able to tweak the call to
            # compile_extension_module and to get a different return result
            # than in that function
            code = """
            #include <Python.h>
            %(body)s

            void init%(name)s(void) {
            %(init)s
            }
            """ % dict(name=name, init=init, body=body)
            kwds = dict(separate_module_sources=[code])
            symbols = [space.str_w(w_item) for w_item in space.fixedview(w_symbols)]
            mod = compile_extension_module(space, name, symbols, **kwds)

            # explicitly load the module as a CDLL rather than as a module
            from pypy.module.imp.importing import get_so_extension
            fullmodname = os.path.join(
                os.path.dirname(mod), name + get_so_extension(space))
            return space.wrap(fullmodname)
Esempio n. 22
0
def patch_distutils():
    sysconfig.get_python_inc = get_python_inc
    sysconfig.get_config_vars()['SO'] = get_so_extension(space)
Esempio n. 23
0
def extension_suffixes(space):
    suffixes_w = []
    if 1:  #if space.config.objspace.usemodules.cpyext:
        suffixes_w.append(space.newtext(importing.get_so_extension(space)))
    return space.newlist(suffixes_w)
Esempio n. 24
0
def patch_distutils():
    sysconfig.get_python_inc = get_python_inc
    sysconfig.get_config_vars()['SO'] = get_so_extension(space)