Exemplo n.º 1
0
        def import_module(space, name, init=None, body='',
                          load_it=True, filename=None,
                          PY_SSIZE_T_CLEAN=False):
            """
            init specifies the overall template of the module.

            if init is None, the module source will be loaded from a file in this
            test direcory, give a name given by the filename parameter.

            if filename is None, the module name will be used to construct the
            filename.
            """
            name = name.encode()
            if body or init:
                body = body.encode()
                if init is None:
                    init = "return PyModule_Create(&moduledef);"
                else:
                    init = init.encode()
                code = """
                %(PY_SSIZE_T_CLEAN)s
                #include <Python.h>
                %(body)s

                PyMODINIT_FUNC
                PyInit_%(name)s(void) {
                %(init)s
                }
                """ % dict(name=name, init=init, body=body,
                           PY_SSIZE_T_CLEAN='#define PY_SSIZE_T_CLEAN'
                                            if PY_SSIZE_T_CLEAN else '')
                kwds = dict(separate_module_sources=[code])
            else:
                assert not PY_SSIZE_T_CLEAN
                if filename is None:
                    filename = name
                filename = py.path.local(pypydir) / 'module' \
                        / 'cpyext'/ 'test' / (filename + ".c")
                kwds = dict(separate_module_files=[filename])

            mod = compile_extension_module(space, name, **kwds)

            if load_it:
                api.load_extension_module(space, mod, name)
                self.imported_module_names.append(name)
                return space.getitem(
                    space.sys.get('modules'),
                    space.wrap(name))
            else:
                return os.path.dirname(mod)
Exemplo n.º 2
0
    def import_module(self,
                      name,
                      init=None,
                      body='',
                      load_it=True,
                      filename=None):
        """
        init specifies the overall template of the module.

        if init is None, the module source will be loaded from a file in this
        test direcory, give a name given by the filename parameter.

        if filename is None, the module name will be used to construct the
        filename.
        """
        if init is not None:
            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])
        else:
            if filename is None:
                filename = name
            filename = py.path.local(autopath.pypydir) / 'module' \
                    / 'cpyext'/ 'test' / (filename + ".c")
            kwds = dict(separate_module_files=[filename])

        mod = self.compile_module(name, **kwds)

        if load_it:
            api.load_extension_module(self.space, mod, name)
            self.imported_module_names.append(name)
            return self.space.getitem(self.space.sys.get('modules'),
                                      self.space.wrap(name))
        else:
            return os.path.dirname(mod)
Exemplo n.º 3
0
        def import_module(space, name, init=None, body='',
                          load_it=True, filename=None):
            """
            init specifies the overall template of the module.

            if init is None, the module source will be loaded from a file in this
            test direcory, give a name given by the filename parameter.

            if filename is None, the module name will be used to construct the
            filename.
            """
            if init is not None:
                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])
            else:
                if filename is None:
                    filename = name
                filename = py.path.local(pypydir) / 'module' \
                        / 'cpyext'/ 'test' / (filename + ".c")
                kwds = dict(separate_module_files=[filename])

            mod = compile_extension_module(space, name, **kwds)

            if load_it:
                api.load_extension_module(space, mod, name)
                self.imported_module_names.append(name)
                return space.getitem(
                    space.sys.get('modules'),
                    space.wrap(name))
            else:
                return os.path.dirname(mod)
Exemplo n.º 4
0
def load_c_extension(space, filename, modulename):
    from pypy.module.cpyext.api import load_extension_module
    load_extension_module(space, filename, modulename)
Exemplo n.º 5
0
 def load_module(self, mod, name):
     space = self.space
     api.load_extension_module(space, mod, name)
     return space.getitem(
         space.sys.get('modules'), space.wrap(name))
Exemplo n.º 6
0
 def reimport_module(space, mod, name):
     api.load_extension_module(space, mod, name)
     return space.getitem(
         space.sys.get('modules'),
         space.wrap(name))
Exemplo n.º 7
0
def load_c_extension(space, filename, modulename):
    # the next line is mandatory to init cpyext
    space.getbuiltinmodule("cpyext")
    from pypy.module.cpyext.api import load_extension_module
    load_extension_module(space, filename, modulename)
Exemplo n.º 8
0
def load_c_extension(space, filename, modulename):
    # the next line is mandatory to init cpyext
    space.getbuiltinmodule("cpyext")
    from pypy.module.cpyext.api import load_extension_module
    load_extension_module(space, filename, modulename)
Exemplo n.º 9
0
 def load_module(self, mod, name):
     space = self.space
     api.load_extension_module(space, mod, name)
     return space.getitem(space.sys.get('modules'), space.wrap(name))
Exemplo n.º 10
0
 def reimport_module(space, mod, name):
     api.load_extension_module(space, mod, name)
     return space.getitem(space.sys.get('modules'), space.wrap(name))
Exemplo n.º 11
0
def load_c_extension(space, filename, modulename):
    from pypy.module.cpyext.api import load_extension_module
    log_pyverbose(space, 1, "import %s # from %s\n" % (modulename, filename))
    return load_extension_module(space, filename, modulename)
Exemplo n.º 12
0
def load_c_extension(space, filename, modulename):
    from pypy.module.cpyext.api import load_extension_module
    load_extension_module(space, filename, modulename)
Exemplo n.º 13
0
def load_c_extension(space, filename, modulename):
    from pypy.module.cpyext.api import load_extension_module
    log_pyverbose(space, 1, "import %s # from %s\n" %
                  (modulename, filename))
    load_extension_module(space, filename, modulename)
Exemplo n.º 14
0
 def reimport_module(self, mod, name):
     api.load_extension_module(self.space, mod, name)
     return self.space.getitem(self.space.sys.get("modules"), self.space.wrap(name))