Beispiel #1
0
func ExecCodeModule(name string, code *Base) (*Module, error) {
	s := C.CString(name)
	defer C.free(unsafe.Pointer(s))
	ret := C.PyImport_ExecCodeModule(s, code.c())
	if ret == nil {
		return nil, exception()
	}
	return newModule(ret), nil
}
Beispiel #2
0
// PyObject* PyImport_ExecCodeModule(char *name, PyObject *co)
// Return value: New reference.
// Given a module name (possibly of the form package.module) and a code object read from a Python bytecode file or obtained from the built-in function compile(), load the module. Return a new reference to the module object, or NULL with an exception set if an error occurred. Before Python 2.4, the module could still be created in error cases. Starting with Python 2.4, name is removed from sys.modules in error cases, and even if name was already in sys.modules on entry to PyImport_ExecCodeModule(). Leaving incompletely initialized modules in sys.modules is dangerous, as imports of such modules have no way to know that the module object is an unknown (and probably damaged with respect to the module author’s intents) state.
//
// The module’s __file__ attribute will be set to the code object’s co_filename.
//
// This function will reload the module if it was already imported. See PyImport_ReloadModule() for the intended way to reload a module.
//
// If name points to a dotted name of the form package.module, any package structures not already created will still not be created.
//
// Changed in version 2.4: name is removed from sys.modules in error cases.
func PyImport_ExecCodeModule(name string, co *PyObject) *PyObject {
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))

	return togo(C.PyImport_ExecCodeModule(c_name, topy(co)))
}