Re: [go-nuts] Pass C struct from Go to C method

2020-03-06 Thread Nitish Saboo
Thankyou Ian for your responses. Thanks, Nitish On Fri, 6 Mar 2020, 21:01 Ian Lance Taylor, wrote: > On Fri, Mar 6, 2020 at 7:18 AM Nitish Saboo > wrote: > > > > > 3) Why is 'fmt.Println(InitStruct)' printing the struct fields even > after freeing the memory ? [b] > > > > Because that's how

Re: [go-nuts] Pass C struct from Go to C method

2020-03-06 Thread Ian Lance Taylor
On Fri, Mar 6, 2020 at 7:18 AM Nitish Saboo wrote: > > > 3) Why is 'fmt.Println(InitStruct)' printing the struct fields even after > > freeing the memory ? [b] > > Because that's how C works. C is not a memory safe language, and it > doesn't become memory safe just because you make the calls

Re: [go-nuts] Pass C struct from Go to C method

2020-03-06 Thread Nitish Saboo
Hi Ian, > 3) Why is 'fmt.Println(InitStruct)' printing the struct fields even after freeing the memory ? [b] Because that's how C works. C is not a memory safe language, and it doesn't become memory safe just because you make the calls from Go. 1)You mean to say the dangling pointer will

Re: [go-nuts] Pass C struct from Go to C method

2020-03-06 Thread Ian Lance Taylor
On Fri, Mar 6, 2020 at 4:25 AM Nitish Saboo wrote: > > So what did I do : > > main.go > > > var InitStruct *C.struct_Foo; > > func InitializeEngine(pattern string, path string) { > pattern_db := C.CString(pattern) > module_path := C.CString(path) > if InitStruct != nil{ >

Re: [go-nuts] Pass C struct from Go to C method

2020-03-06 Thread Nitish Saboo
Hi Ian, So what did I do : main.go var InitStruct *C.struct_Foo; func InitializeEngine(pattern string, path string) { pattern_db := C.CString(pattern) module_path := C.CString(path) if InitStruct != nil{ C.free(unsafe.Pointer(InitStruct)) } InitStruct := (*C.Foo)(C.calloc(1,

Re: [go-nuts] Pass C struct from Go to C method

2020-03-05 Thread Ian Lance Taylor
On Wed, Mar 4, 2020 at 10:06 PM Nitish Saboo wrote: > > Thank you for the response.Got it. > Basically, fmt.Println(InitStruct) is printing the values of fields, cb and > data, for the struct Foo pointed by InitStruct. > fmt.Printf("%p\n", InitStruct) is printing the memory address. > Btw..can

Re: [go-nuts] Pass C struct from Go to C method

2020-03-04 Thread Nitish Saboo
Hi Ian, Thank you for the response.Got it. Basically, fmt.Println(InitStruct) is printing the values of fields, cb and data, for the struct Foo pointed by InitStruct. fmt.Printf("%p\n", InitStruct) is printing the memory address. Btw..can you please clarify the following : 1)Is this the correct

Re: [go-nuts] Pass C struct from Go to C method

2020-03-04 Thread Ian Lance Taylor
On Wed, Mar 4, 2020 at 3:57 AM Nitish Saboo wrote: > > I have CGO project. > > Following is my C header file and Go code > > syslog-node.h > === > > #ifndef _TEST_H_ > #define _TEST_H_ > > #include > > typedef void (*key_value_cb)(const char* key, const char* value, size_t >

[go-nuts] Pass C struct from Go to C method

2020-03-04 Thread Nitish Saboo
Hi, I have CGO project. Following is my C header file and Go code syslog-node.h === #ifndef _TEST_H_ #define _TEST_H_ #include typedef void (*key_value_cb)(const char* key, const char* value, size_t value_len, int work); typedef struct Foo{ key_value_cb cb; int data;