func (mod *Module) AddObject(name string, obj *Base) error { if obj == nil { return AssertionError.Err("ValueError: obj == nil!") } cname := C.CString(name) defer C.free(unsafe.Pointer(cname)) ret := C.PyModule_AddObject(mod.c(), cname, obj.c()) if ret < 0 { return exception() } return nil }
// int PyModule_AddObject(PyObject *module, const char *name, PyObject *value) // Add an object to module as name. This is a convenience function which can be used from the module’s initialization function. This steals a reference to value. Return -1 on error, 0 on success. // // New in version 2.0. func PyModule_AddObject(self *PyObject, name string, value *PyObject) error { c_name := C.CString(name) defer C.free(unsafe.Pointer(c_name)) return int2err(C.PyModule_AddObject(topy(self), c_name, topy(value))) }