I have to use a massive third party API so it's not really a choice to use 
cgo.

Do you have any safer options to pass C pointers between packages?
The C pointers are all C allocated and package B needs to call C functions 
directly and pass those pointers.

On Friday, 14 February 2020 01:02:24 UTC+8, Jake Montgomery wrote:
>
> You need to read https://golang.org/pkg/unsafe/#Pointer *very, very, very* 
> carefully before using unsafe.Pointer in any way. It spells out 6 
> conversions that are considered "valid". It says: "Code not using these 
> patterns is likely to be invalid today or to become invalid in the future." 
> AFAICT, your code does not fit any of those 6 allowable patterns. 
>
> Go is simple and easy, CGO is tricky, difficult and full of dragons.
>
>
> On Thursday, February 13, 2020 at 11:42:30 AM UTC-5, Alex wrote:
>>
>> I have to pass C pointers between packages so I used uintptr like how 
>> syscall does things.
>> However go vet gives the message "possible misuse of unsafe.Pointer". 
>>
>> Is there something I could do to avoid vet complaining?
>>
>> Package A:
>> type Foo struct {
>> procAddr uintptr
>> }
>>
>> func (f Foo) ProcAddr() uintptr {
>> return f.procAddr
>> }
>>
>> func Bar() Foo {
>>         return Foo{C.SomeFunc()}
>> }
>>
>> Package B:
>> p := C.ASDF(unsafe.Pointer(A.Bar().ProcAddr())) // possible misuse of 
>> unsafe.Pointer
>>
>>

-- 
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.com/d/msgid/golang-nuts/0a3688f2-e505-4e32-819d-242400a4bd82%40googlegroups.com.

Reply via email to