示例#1
0
func PickleDumps(v interface{}) string {
	pickle_lock.Lock()
	_pickle_init()
	obj := interfaceToPyObj(v)
	str := C.PyObject_CallFunction1(pickle_dumps, obj)
	gostr := pyObjToInterface(str)
	C.Py_DecRef(obj)
	C.Py_DecRef(str)
	pickle_lock.Unlock()
	return gostr.(string)
}
示例#2
0
func PickleLoads(data []byte) interface{} {
	pickleLock.Lock()
	if initialized == 0 {
		pickleInit()
	}
	str := C.PyString_FromStringAndSize((*C.char)(unsafe.Pointer(&data[0])), C.Py_ssize_t(len(data)))
	obj := C.PyObject_CallFunction1(pickleLoads, str)
	v := pyObjToInterface(obj)
	C.Py_DecRef(obj)
	C.Py_DecRef(str)
	pickleLock.Unlock()
	return v
}
示例#3
0
func PickleLoads(data string) interface{} {
	pickle_lock.Lock()
	_pickle_init()
	datastr := C.CString(data)
	str := C.PyString_FromStringAndSize(datastr, C.Py_ssize_t(len(data)))
	C.free(unsafe.Pointer(datastr))
	obj := C.PyObject_CallFunction1(pickle_loads, str)
	v := pyObjToInterface(obj)
	C.Py_DecRef(obj)
	C.Py_DecRef(str)
	pickle_lock.Unlock()
	return v
}