Ejemplo n.º 1
0
// int PyModule_AddStringConstant(PyObject *module, const char *name, const char *value)
// Add a string constant to module as name. This convenience function can be used from the module’s initialization function. The string value must be null-terminated. Return -1 on error, 0 on success.
//
// New in version 2.0.
func PyModule_AddStringConstant(self *PyObject, name, value string) error {
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))

	c_value := C.CString(value)
	defer C.free(unsafe.Pointer(c_value))

	return int2err(C.PyModule_AddStringConstant(topy(self), c_name, c_value))
}
Ejemplo n.º 2
0
func (mod *Module) AddStringConstant(name, value string) error {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	cvalue := C.CString(value)
	defer C.free(unsafe.Pointer(cvalue))

	ret := C.PyModule_AddStringConstant(mod.c(), cname, cvalue)
	if ret < 0 {
		return exception()
	}

	return nil
}