Re: [go-nuts] How to return a Go struct to C

2017-03-21 Thread Konstantin Khomoutov
On Tue, 21 Mar 2017 11:23:39 +0300 Konstantin Khomoutov wrote: [...] Sorry, a couple of assorted fixes: > A sketch would look something like this: > > /* > typedef MediaHandle uint64_t Should be typedef uint64_t MediaHandle of course. > */ > import "C" > > import "unsafe" >

Re: [go-nuts] How to return a Go struct to C

2017-03-21 Thread Konstantin Khomoutov
On Mon, 20 Mar 2017 06:25:01 -0700 (PDT) Song Liu wrote: [...] > struct Media { > > char*Name; > > char*Path; > > uint64_t Size; > > }; [...] > func GetMediaFromDB(filename *C.char) *C.struct_Media { > > > c_struct_media := &C.struct_Media{} > > > return c_stru

Re: [go-nuts] How to return a Go struct to C

2017-03-20 Thread Song Liu
Thanks for your info, it seems that it's reporting the same error but still not have a solution. After tried to use unsafe: return (*C.struct_Media)(unsafe.Pointer(c_struct_media)) it reports same error: panic: runtime error: cgo result has Go pointer Any further insights about this issue? ma

Re: [go-nuts] How to return a Go struct to C

2017-03-20 Thread Steven Hartland
The following may help: http://feisky.xyz/2016/04/19/cgo-in-go-1-6/ On 20/03/2017 13:25, Song Liu wrote: Hi, I have a shared lib as bellow: | /* #include structMedia{ char*Name; char*Path; uint64_tSize; }; */ import"C" //exportGetMediaFromDB funcGetMediaFromDB(filename*C.char)*C.struct_Media{

[go-nuts] How to return a Go struct to C

2017-03-20 Thread Song Liu
Hi, I have a shared lib as bellow: /* #include struct Media { char*Name; char*Path; uint64_t Size; }; */ import "C" //export GetMediaFromDB func GetMediaFromDB(filename *C.char) *C.struct_Media { c_struct_media := &C.struct_Media{} return c_struct_med