rgbkrk / libvirt-go

[DEPRECATED] Go bindings for libvirt
https://github.com/libvirt/libvirt-go
MIT License
166 stars 50 forks source link

cgo compilation error #123

Open antongulenko opened 7 years ago

antongulenko commented 7 years ago

Hello,

We encountered the following error when trying to compile a project that uses libvirt-go:

.../libvirt-go/events.go:219: type [1073741824]C.struct__virDomainEventGraphicsSubjectIdentity larger than address space .../libvirt-go/events.go:219: type [1073741824]C.struct__virDomainEventGraphicsSubjectIdentity too large

This happened on a colleagues machine, and I was not yet able to get all required information to document this (OS, versions, etc). I will obtain that as soon as possible. I cannot reproduce this on my machines, so my guess is that this is a 32-bit issue. The code that produces the error contains a cast to a [1 << 30]-array pointer, which is immediately sliced to a shorter size. I am not familiar with this pattern, could somebody explain the rationale? Is this the recommended way to convert a C-array-pointer to a slice with a given length and capacity?

If there is no other way to do it, maybe the array-size could be reduced to something like [1 << 27] to make it work on 32-bit machines?

Cheers, Anton

antongulenko commented 7 years ago

See below for details about the host that produced the error. It is indeed a 32bit machine.

Go: 1.6 linux/386 OS: Ubuntu 14.04.2 LTS Kernel: Linux DFX-Rel-00 3.13.0-39-generic #66-Ubuntu SMP Tue Oct 28 13:31:23 UTC 2014 i686 i686 i686 GNU/Linux

rmohr commented 7 years ago

1 << 27 would probably also be big enough, but we could also do it like this:

var identities []C.virDomainEventGraphicsSubjectIdentity
header := (*reflect.SliceHeader)(unsafe.Pointer(&identities))
*header = reflect.SliceHeader{uintptr(unsafe.Pointer(&subject.identities)), nidentities, nidentities}

This seems to be more portable. See here for an example playground.