I'm calling a Go function from Python. Go function returns a string, specifically, a GoString
with the string itself being allocated on Go's side.
Question
Who's responsible for deallocation of this memory?
A very simplified example follows.
Go side:
func Create(optsEncoded string) (res string, serr string) {
opts := map[string]interface{}{}
if err := json.Unmarshal([]byte(optsEncoded), &opts); err != nil {
return "", errWithStack(err)
}
options := translateCreateOptions(opts)
result := ...
payload, err := json.Marshal(result)
if err != nil {
return "", errWithStack(err)
}
return string(payload), ""
}
Cython bindings:
cpdef object py_create(object items, bytes options):
cdef GoString opts = ...
cdef bytes message
cdef Create_return result = Create(opts)
if result.r0.n == 0:
message = result.r1.p
raise Exception("Something happened")
message = result.r0.p
# Do I need to deallocate result.r0 and result.r1?
return message.decode("utf-8")