Re: [go-nuts] Re: C Third Party Lib CGO

2021-07-09 Thread snmed
Okay, will store the pointer directly in a struct as a private field. Thanks for your time and input, I greatly appreciate it. Tamás Gulácsi schrieb am Freitag, 9. Juli 2021 um 14:17:48 UTC+2: > The runtime and checks does not know what's inside an uintptr, so > converting an uintptr to a(n u

Re: [go-nuts] Re: C Third Party Lib CGO

2021-07-09 Thread Tamás Gulácsi
The runtime and checks does not know what's inside an uintptr, so converting an uintptr to a(n unsafe.)Pointer triggers the warnings. Only the special specified cases are legal. TL;DR; Do not use uintptr. (More elaborate: do not use an uintptr to store and retrieve a pointer - just store the poi

Re: [go-nuts] Re: C Third Party Lib CGO

2021-07-09 Thread snmed
Yes uintptr is the address the C pointer is pointing to , right? So C doesn't move any memory and therefore the address is still valid until deleted in C code. If I take the value of uintptr variable, convert it back with unsafe.Pointer(uintptr) and pass it to a C function, does C not interpret

Re: [go-nuts] Re: C Third Party Lib CGO

2021-07-09 Thread Tamás Gulácsi
An uintptr *is not a pointer*, so 2. is false. NOTHING at Go's side holds anything regarding MyAppHwnd, and it doesn't seem to be a pointer at all (just a number), so converting that to an unsafe.Pointer is unsafe. The rules about uintptr are there for a reason! Only the allowed use cases are gua

Re: [go-nuts] Re: C Third Party Lib CGO

2021-07-08 Thread snmed
Thx Ian to pointing me to the documentation I read it, but still unsure regarding my example. Probably rule number 4 could apply, so let me go through my example and correct me if I'm wrong. 1. C.CreateApp() creates memory in C code and returns it as C void pointer 2. Go function CreateApp() re

Re: [go-nuts] Re: C Third Party Lib CGO

2021-07-08 Thread Ian Lance Taylor
On Thu, Jul 8, 2021 at 10:09 AM snmed wrote: > > Thanks for your reply. I came across a similar solution today, I made a > struct which is visible outside the package and use a private field myApp > C.MyAppPtr to hide the C type. > I still wondering why the uintptr version works but shows a warn

[go-nuts] Re: C Third Party Lib CGO

2021-07-08 Thread snmed
Thanks for your reply. I came across a similar solution today, I made a struct which is visible outside the package and use a private field myApp C.MyAppPtr to hide the C type. I still wondering why the uintptr version works but shows a warning "possible misuse of unsafe.pointer", CGO documentat

[go-nuts] Re: C Third Party Lib CGO

2021-07-08 Thread Tamás Gulácsi
Use *C.MyAppPtr on Go side, don't hide it behind an uintptr. snmed a következőt írta (2021. július 7., szerda, 19:47:44 UTC+2): > > Hi all > > Once again I have a 3th party library which looks like this example: > https://play.golang.org/p/Ue9yQ8s8Ymq and I need it to integrate in our > go tool