Re: [go-nuts] cgo: passing unsafe.Pointer of Slice without explicit pinning?

2024-07-08 Thread Antonio Caceres Cabrera
wrote: > On Mon, Jul 8, 2024 at 12:38 PM Antonio Caceres Cabrera > wrote: > > > > Sorry, accidentally hit the wrong response button, so I'm posting it > again: > > > > Thanks for the clarification, Ian. > > > > Is it also possible to pin memory to local

Re: [go-nuts] cgo: passing unsafe.Pointer of Slice without explicit pinning?

2024-07-08 Thread Antonio Caceres Cabrera
yte)` ? Julio On Sunday, July 7, 2024 at 5:38:13 PM UTC+2 Ian Lance Taylor wrote: > On Sun, Jul 7, 2024 at 6:17 AM Antonio Caceres Cabrera > wrote: > > > > I'm trying to use cgo for a C library, specifically a function which > takes a void pointer to a buffer, and I'm t

[go-nuts] cgo: passing unsafe.Pointer of Slice without explicit pinning?

2024-07-07 Thread Antonio Caceres Cabrera
Hi Gophers, I'm trying to use cgo for a C library, specifically a function which takes a void pointer to a buffer, and I'm trying to pass a Go-Slice as this buffer. ``` func Write(buf []byte) (int, error) { // var pin rumtime.Pinner // pin.Pin([0]) // defer pin.Unpin() // is

[go-nuts] cgo: Special case in unpinned go pointer checks

2024-01-07 Thread Antonio Caceres Cabrera
Dear golang nuts, I was trying to gain a better understanding of how cgo works internally, when I stumbled upon this implementation detail: https://github.com/golang/go/blob/8db131082d08e497fd8e9383d0ff7715e1bef478/src/runtime/cgocall.go#L628 ``` case kindStruct: st :=

Re: [go-nuts] Is it safe to keep noCopy types in a slice which might copy on re-alloc?

2023-08-27 Thread Antonio Caceres Cabrera
On Sunday, August 27, 2023 at 7:05:15 PM UTC+2 Ian Lance Taylor wrote: > On Sun, Aug 27, 2023 at 7:54 AM Antonio Caceres Cabrera > wrote: > > > > Go vet complains about this minimal example code > > > > type Foo struct { > > val atomic.Uint64 > > } > > &

[go-nuts] Is it safe to keep noCopy types in a slice which might copy on re-alloc?

2023-08-27 Thread Antonio Caceres Cabrera
Go vet complains about this minimal example code type Foo struct { val atomic.Uint64 } func main() { var foos = make([]Foo, 0) var bar Foo bar.val.Store(5) foos = append(foos, bar) // call of append copies lock value: example.com/foo.Foo contains

[go-nuts] Is atomic.CompareAndSwap a read-aquire (even if it returns false)?

2023-08-20 Thread Antonio Caceres Cabrera
Hi Gophers, I have a question about a more subtle part of the language, the memory model regarding atomic operations. The memory model doc on go.dev states: >If the effect of an atomic operation *A* is observed by atomic operation *B*, then *A* is synchronized before *B*.[...] I.e. "observing