Re: [go-nuts] Re: Mapping C pointer to BYTE to golang []byte

2017-12-15 Thread 'Bryan C. Mills' via golang-nuts
You can ignore the vet warning if you are certain that the uintptr values you are converting to unsafe.Pointer are *valid pointers* (i.e., not non-pointer sentinel values) that point *outside the Go heap*. It sounds like that is probably the case, but you might want to check with someone more

Re: [go-nuts] Re: Mapping C pointer to BYTE to golang []byte

2017-12-15 Thread snmed
Sorry if I wasn't clear about that, I calling CertFindCertificateInStore which according to MSDN returns a pointer to a struct of type PCCERT_CONTEXT and must be freed with CertFreeCertificateContext

Re: [go-nuts] Re: Mapping C pointer to BYTE to golang []byte

2017-12-15 Thread 'Bryan C. Mills' via golang-nuts
You haven't actually said which system call you're invoking, but from the name CERT_CONTEXT and the layout of the struct I'm guessing it's probably CertCreateCertificateContext or CertEnumCertificatesInStore

[go-nuts] Re: Mapping C pointer to BYTE to golang []byte

2017-12-14 Thread snmed
Hi Bryan But the returned uintptr from syscall is as far as i know a pointer to a struct which has been created by the C API, so go runtime won't touch it or do I miss something? Am Freitag, 15. Dezember 2017 00:48:51 UTC+1 schrieb Bryan Mills: > > In this case, the vet tool is correct if

[go-nuts] Re: Mapping C pointer to BYTE to golang []byte

2017-12-14 Thread 'Bryan Mills' via golang-nuts
In this case, the vet tool is correct if you're making the syscall with Go-allocated memory. The Go runtime is allowed to move values around: the address of a Go variable is only pinned for the duration of the syscall itself. If you've got C-allocated memory (or statically-allocated memory),

[go-nuts] Re: Mapping C pointer to BYTE to golang []byte

2017-12-14 Thread snmed
Okay I found a way, this seems to work: ca := (*[100]byte) (unsafe.Pointer(certctx.pbCertEncoded))[:certctx. cbCertEncoded] or mm := make([]byte, certctx.cbCertEncoded) for i := uint32(0) ; i < certctx.cbCertEncoded; i++ { mm[i] = *((*byte)(unsafe.Pointer(certctx.pbCertEncoded +

[go-nuts] Re: Mapping C pointer to BYTE to golang []byte

2017-12-14 Thread snmed
Hi Miki I'm using syscall package and no C import, but maybe it is possible to use this function as well? Am Donnerstag, 14. Dezember 2017 09:18:26 UTC+1 schrieb Miki Tebeka: > > Do you mean > > func C.GoBytes(unsafe.Pointer, C.int) []byte > > ? > > On Thursday, December 14, 2017 at 9:05:32

[go-nuts] Re: Mapping C pointer to BYTE to golang []byte

2017-12-14 Thread Miki Tebeka
Do you mean func C.GoBytes(unsafe.Pointer, C.int) []byte ? On Thursday, December 14, 2017 at 9:05:32 AM UTC+2, snmed wrote: > > Hi all > > I'm trying to map a C structure to an equivalent go struct, but I bumped > into a problem with a pointer to byte that is actually an array of bytes. > >