예제 #1
0
파일: pickle.go 프로젝트: redbo/goswiftobj
func pickleInit() {
	C.Py_Initialize()
	var cPickle *C.PyObject = C.PyImport_ImportModule(C.CString("cPickle"))
	pickleLoads = C.PyObject_GetAttrString(cPickle, C.CString("loads"))
	pickleDumps = C.PyObject_GetAttrString(cPickle, C.CString("dumps"))
	highestProtocol = C.PyObject_GetAttrString(cPickle, C.CString("HIGHEST_PROTOCOL"))
	C.Py_DecRef(cPickle)
	initialized = 1
}
예제 #2
0
func _pickle_init() {
	if initialized == 0 {
		C.Py_Initialize()
		var cPickle *C.PyObject = C.PyImport_ImportModule(C.CString("cPickle"))
		pickle_loads = C.PyObject_GetAttrString(cPickle, C.CString("loads"))
		pickle_dumps = C.PyObject_GetAttrString(cPickle, C.CString("dumps"))
		C.Py_DecRef(cPickle)
		initialized = 1
	}
}
예제 #3
0
파일: python.go 프로젝트: tsavola/go-python
func getAttr(pyObject *C.PyObject, name string) (pyResult *C.PyObject, err error) {
	cName := C.CString(name)
	defer C.free(unsafe.Pointer(cName))

	if pyResult = C.PyObject_GetAttrString(pyObject, cName); pyResult == nil {
		err = getError()
	}
	return
}
예제 #4
0
파일: object.go 프로젝트: MogeiWang/py
func (obj *Base) CallMethodObject(name string, args *Tuple) (*Base, error) {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	f := C.PyObject_GetAttrString(obj.c(), cname)
	if f == nil {
		return nil, AttributeError.Err(name)
	}
	defer C.decref(f)

	if C.PyCallable_Check(f) == 0 {
		return nil, TypeError.Err("attribute of type '%s' is not callable", name)
	}

	ret := C.PyObject_CallObject(f, args.c())
	return obj2ObjErr(ret)
}
예제 #5
0
파일: base.go 프로젝트: xushiwei/gopy
func (obj *BaseObject) CallMethodObjArgs(name string, args ...Object) (Object, error) {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	f := C.PyObject_GetAttrString(c(obj), cname)
	if f == nil {
		return nil, AttributeError.Err(name)
	}
	defer C.decref(f)

	if C.PyCallable_Check(f) == 0 {
		return nil, TypeError.Err("attribute of type '%s' is not callable", name)
	}

	t, err := PackTuple(args...)
	if err != nil {
		return nil, err
	}

	ret := C.PyObject_CallObject(f, c(t))
	return obj2ObjErr(ret)
}
예제 #6
0
파일: object.go 프로젝트: z0mbie42/py3
func (self *PyObject) GetAttrString(attr_name string) *PyObject {
	c_attr_name := C.CString(attr_name)
	defer C.free(unsafe.Pointer(c_attr_name))
	return PyObjectToGO(C.PyObject_GetAttrString(self.ptr, c_attr_name))
}
예제 #7
0
파일: object.go 프로젝트: MogeiWang/py
// Retrieve an attribute named attr_name from object o. Returns the attribute value
// on success, or NULL on failure. This is the equivalent to the Python "obj.name".
//
// Return value: New reference.
func (obj *Base) GetAttrString(name string) (*Base, error) {
	s := C.CString(name)
	defer C.free(unsafe.Pointer(s))
	ret := C.PyObject_GetAttrString(obj.c(), s)
	return obj2ObjErr(ret)
}