Re: [go-nuts] Pass value from C code to GO code(CGO)
Nitish privately e-mailed me: Can you please specify the particular files in YottaDB repository that are exchanging key-value pairs between C and Go ? I am replying to the threadd. Look at the buffer_t* and key_t* files. You can also trace the implementations of NodeNextE(), SubNextE(), NodeNextST(), and SubNextST(). Regards – Bhaskar On Monday, April 29, 2019 at 4:08:24 PM UTC-4, ksbh...@gmail.com wrote: > > Nitish – > > As noted, you cannot pass to C a pointer to Go structure. However, Go can > use pointers C structures that are provided to it. YottaDB passes key-value > tuples between C and Go, and you can look at working code that does this at > https://gitlab.com/YottaDB/Lang/YDBGo with further documentation at > https://docs.yottadb.com/MultiLangProgGuide/goprogram.html > > After looking at the code and documentation, if you have specific > questions, I can get them answered. > > Regards > – Bhaskar > > On Monday, April 29, 2019 at 3:43:35 PM UTC-4, Tamás Gulácsi wrote: >> >> 2019. április 29., hétfő 17:41:51 UTC+2 időpontban Nitish Saboo a >> következőt írta: >>> >>> Hi Tamás, >>> >>> If I return LogMessage type of object from C code, what type of object >>> should be there on Go side to receive the return value because the Go side >>> doesn't have a LogMessage object ? >>> >>> Thanks >>> >>> >> That depends on what that LogMessage is. >> If it is a struct, then you can get its fields. >> And you can use that pointer in some C functions - this depends on the >> given API. >> >> If LogMessage is a struct, you may be able to convert it to its Go >> equivalent - if it is not too complicated (no union, no packing...). >> > -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Pass value from C code to GO code(CGO)
Nitish – As noted, you cannot pass to C a pointer to Go structure. However, Go can use pointers C structures that are provided to it. YottaDB passes key-value tuples between C and Go, and you can look at working code that does this at https://gitlab.com/YottaDB/Lang/YDBGo with further documentation at https://docs.yottadb.com/MultiLangProgGuide/goprogram.html After looking at the code and documentation, if you have specific questions, I can get them answered. Regards – Bhaskar On Monday, April 29, 2019 at 3:43:35 PM UTC-4, Tamás Gulácsi wrote: > > 2019. április 29., hétfő 17:41:51 UTC+2 időpontban Nitish Saboo a > következőt írta: >> >> Hi Tamás, >> >> If I return LogMessage type of object from C code, what type of object >> should be there on Go side to receive the return value because the Go side >> doesn't have a LogMessage object ? >> >> Thanks >> >> > That depends on what that LogMessage is. > If it is a struct, then you can get its fields. > And you can use that pointer in some C functions - this depends on the > given API. > > If LogMessage is a struct, you may be able to convert it to its Go > equivalent - if it is not too complicated (no union, no packing...). > -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Pass value from C code to GO code(CGO)
2019. április 29., hétfő 17:41:51 UTC+2 időpontban Nitish Saboo a következőt írta: > > Hi Tamás, > > If I return LogMessage type of object from C code, what type of object > should be there on Go side to receive the return value because the Go side > doesn't have a LogMessage object ? > > Thanks > > That depends on what that LogMessage is. If it is a struct, then you can get its fields. And you can use that pointer in some C functions - this depends on the given API. If LogMessage is a struct, you may be able to convert it to its Go equivalent - if it is not too complicated (no union, no packing...). -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Pass value from C code to GO code(CGO)
Hi Tamás, If I return LogMessage type of object from C code, what type of object should be there on Go side to receive the return value because the Go side doesn't have a LogMessage object ? Thanks On Mon, Apr 29, 2019 at 7:14 PM Tamás Gulácsi wrote: > LogMessage *match(...) { > ... > return msg; > } > > -- > 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. > For more options, visit https://groups.google.com/d/optout. > -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Pass value from C code to GO code(CGO)
LogMessage *match(...) { ... return msg; } -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Pass value from C code to GO code(CGO)
Hi, void match(const gchar *pattern, size_t pattern_len, const gchar *program, size_t program_len) { LogMessage *msg = log_msg_new_empty(); PDBInput input; log_msg_set_value(msg, LM_V_MESSAGE, pattern, pattern_len); log_msg_set_value(msg, LM_V_PROGRAM, program, program_len); pattern_db_process(patterndb, PDB_INPUT_WRAP_MESSAGE(, msg)); log_msg_unref(msg); } This match is being called from the GO code. log message object is getting created that has key-value pairs. I want to return the key-value pair log message object to the Go code.How can I achieve this ? Thanks On Fri, Apr 26, 2019 at 6:32 PM Ian Lance Taylor wrote: > On Fri, Apr 26, 2019 at 4:41 AM Nitish Saboo > wrote: > > > > Thanks for the info. Jan.My main issue is how can I access the value on > Go side after some manipulation within the C code ? > > You do it exactly as though you passed a pointer to a Go function, and > then accessed the value after the Go function returns. > > This is kind of hard to discuss in the abstract; maybe you should show > us some code? > > Ian > > > > On Fri, Apr 26, 2019 at 4:28 PM Jan Mercl <0xj...@gmail.com> wrote: > >> > >> On Fri, Apr 26, 2019 at 12:54 PM Nitish Saboo > wrote: > >> > >> > Can I pass a pointer to a value from Go to C, do some manipulation on > it within the C code and access the value from Go after the C code executes > ? > >> > >> The first part of the question is discussed in great detail here: > >> https://golang.org/cmd/cgo/#hdr-Passing_pointers > > > > -- > > 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. > > For more options, visit https://groups.google.com/d/optout. > -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Pass value from C code to GO code(CGO)
2019. április 26., péntek 13:41:53 UTC+2 időpontban Nitish Saboo a következőt írta: > > Thanks for the info. Jan.My main issue is how can I access the value on Go > side after some manipulation within the C code ? > > Thanks > > On Fri, Apr 26, 2019 at 4:28 PM Jan Mercl <0xj...@gmail.com > > wrote: > >> On Fri, Apr 26, 2019 at 12:54 PM Nitish Saboo > > wrote: >> >> > Can I pass a pointer to a value from Go to C, do some manipulation on >> it within the C code and access the value from Go after the C code executes >> ? >> >> The first part of the question is discussed in great detail here: >> https://golang.org/cmd/cgo/#hdr-Passing_pointers >> > You can call a C function from Go code. You can pass any value from Go to C as long as it does not contain a Go-allocated pointer. So you can pass a []byte as ```(*C.char)(unsafe.Pointer([0]))```. One strategy could be allocating on the C side (don't forget to free it!), and manipulate it from Go either directly (struct) or by calling helper C functions. Tamás -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Pass value from C code to GO code(CGO)
On Fri, Apr 26, 2019 at 4:41 AM Nitish Saboo wrote: > > Thanks for the info. Jan.My main issue is how can I access the value on Go > side after some manipulation within the C code ? You do it exactly as though you passed a pointer to a Go function, and then accessed the value after the Go function returns. This is kind of hard to discuss in the abstract; maybe you should show us some code? Ian > On Fri, Apr 26, 2019 at 4:28 PM Jan Mercl <0xj...@gmail.com> wrote: >> >> On Fri, Apr 26, 2019 at 12:54 PM Nitish Saboo >> wrote: >> >> > Can I pass a pointer to a value from Go to C, do some manipulation on it >> > within the C code and access the value from Go after the C code executes ? >> >> The first part of the question is discussed in great detail here: >> https://golang.org/cmd/cgo/#hdr-Passing_pointers > > -- > 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. > For more options, visit https://groups.google.com/d/optout. -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Pass value from C code to GO code(CGO)
Thanks for the info. Jan.My main issue is how can I access the value on Go side after some manipulation within the C code ? Thanks On Fri, Apr 26, 2019 at 4:28 PM Jan Mercl <0xj...@gmail.com> wrote: > On Fri, Apr 26, 2019 at 12:54 PM Nitish Saboo > wrote: > > > Can I pass a pointer to a value from Go to C, do some manipulation on it > within the C code and access the value from Go after the C code executes ? > > The first part of the question is discussed in great detail here: > https://golang.org/cmd/cgo/#hdr-Passing_pointers > -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Pass value from C code to GO code(CGO)
On Fri, Apr 26, 2019 at 12:54 PM Nitish Saboo wrote: > Can I pass a pointer to a value from Go to C, do some manipulation on it > within the C code and access the value from Go after the C code executes ? The first part of the question is discussed in great detail here: https://golang.org/cmd/cgo/#hdr-Passing_pointers -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Pass value from C code to GO code(CGO)
Hi Jan, Can I pass a pointer to a value from Go to C, do some manipulation on it within the C code and access the value from Go after the C code executes ? Thanks On Fri, Apr 26, 2019 at 4:09 PM Jan Mercl <0xj...@gmail.com> wrote: > On Fri, Apr 26, 2019 at 12:34 PM Nitish Saboo > wrote: > > > > Hi, > > > > I want to call C code from GO code.Once the C code gets executed I want > to pass the value back to the GO code. > > Can someone please guide me as in how to pass value back from C code to > the GO code. > > What C type the value is? Do you want to pass it using a return value > of a C function called from Go or access the value from Go after the C > code executes or pass the value to a Go function called from a C > function? > > Have you an example of what you tried and how/why it failed? > > PS: Please note that the name of the programming language is Go. > -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Pass value from C code to GO code(CGO)
On Fri, Apr 26, 2019 at 12:34 PM Nitish Saboo wrote: > > Hi, > > I want to call C code from GO code.Once the C code gets executed I want to > pass the value back to the GO code. > Can someone please guide me as in how to pass value back from C code to the > GO code. What C type the value is? Do you want to pass it using a return value of a C function called from Go or access the value from Go after the C code executes or pass the value to a Go function called from a C function? Have you an example of what you tried and how/why it failed? PS: Please note that the name of the programming language is Go. -- 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. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Pass value from C code to GO code(CGO)
Hi, I want to call C code from GO code.Once the C code gets executed I want to pass the value back to the GO code. Can someone please guide me as in how to pass value back from C code to the GO code. Thanks -- 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. For more options, visit https://groups.google.com/d/optout.