[go-nuts] Passing Struct from Go to C

2019-07-10 Thread Nitish Saboo
Hi, I am trying to pass a Struct from Go to C (this is cgo).I m passing a callback function in that struct that will be called from C code to Go. main.go === type Callback struct { Func func(*C.char , *C.char , C.size_t, C.int) UserData int32 } Calling C code in the following manner =

Re: [go-nuts] Passing Struct from Go to C

2019-07-10 Thread Nitish Saboo
Hi, Looks like I was able to resolve the C error.I am getting the following Go error while running 'make' command: gcc -L/usr/local/lib -lsyslog-ng -o syslog-node.so -L/usr/local/lib/syslog-ng -ldbparser -c `pkg-config --libs --cflags glib-2.0` -I/usr/local/include/syslog-ng/ -I./syslog-ng-3.6.2/

Re: [go-nuts] Passing Struct from Go to C

2019-07-10 Thread Tamás Gulácsi
*C.foo -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.c

Re: [go-nuts] Passing Struct from Go to C

2019-07-10 Thread Nitish Saboo
Hi Tamas, I made it *C.Foo but still getting the error. main.go === type Callback struct { Func func(*C.char , *C.char , C.size_t, C.int) UserData int32 } Calling C code in the following manner = C.initialize_engine(pattern_db, module_path, (*C.F

Re: [go-nuts] Passing Struct from Go to C

2019-07-10 Thread andrey mirtchovski
i don't think you can use a go function directly in the callback. you need a correctly-typed C helper to do it. at least that used to be the case. see examples: https://github.com/mirtchovski/clamav/blob/master/cfuncs.go https://github.com/mirtchovski/clamav/blob/master/callback.go -- You receiv

Re: [go-nuts] Passing Struct from Go to C

2019-07-10 Thread Nitish Saboo
Hi Andrey, I understand the issue here but how can I pass a callback function in a struct to C code.I need a struct because I want to pass and an extra parameter 'userdata' as well that I would require back as part of callback. Thanks, Nitish On Wed, Jul 10, 2019 at 4:39 PM andrey mirtchovski w

Re: [go-nuts] Passing Struct from Go to C

2019-07-10 Thread andrey mirtchovski
what i do is have a similar struct in Go, and the original C one. here 'callbacks' is the go one, and "type Engine C.struct_cl_engine" is the opaque C one: https://github.com/mirtchovski/clamav/blob/master/callback.go#L63 On Wed, Jul 10, 2019 at 5:25 AM Nitish Saboo wrote: > > Hi Andrey, > > I u

Re: [go-nuts] Passing Struct from Go to C

2019-07-10 Thread Nitish Saboo
Hi Andrey, I am new to Go and cgo therefore did not exactly understand your point. Can you explain me in the context of the code that I had posted.It will really help me to get hold of the things much better. Thanks, Nitish On Wed, Jul 10, 2019 at 5:19 PM andrey mirtchovski wrote: > what i do

Re: [go-nuts] Passing Struct from Go to C

2019-07-10 Thread andrey mirtchovski
the Go "Callback" struct may have completely different size and alignment than the C.Foo one expected by C.initialize_engine. therefore you want to construct the C version when calling C.initialize_engine, and the Go version for everything else. Your call may look something like this: initStruct :

Re: [go-nuts] Passing Struct from Go to C

2019-07-10 Thread Nitish Saboo
Hi Andrey, I made the following changes as suggested by you: InitStruct := C.calloc(1, C.sizeof_struct_Foo) InitStruct.key_value_cb = C.callOnMeGo_cgo InitStruct.data = C.int(1) C.initialize_engine(pattern_db, module_path, (*C.Foo)(unsafe.Pointer(InitStruct))) Still Getting following error: Am