Since go 1.15 new() on CGo structs is no longer supported: (#85)

./fakelibusb_test.go:101:87: libusbContext can't be allocated in Go; it is incomplete (or unallocatable)
./fakelibusb_test.go:131:10: libusbDevHandle can't be allocated in Go; it is incomplete (or unallocatable)

Use CGo malloc to obtain unique pointers.
This commit is contained in:
Sebastian Zagrodzki
2020-11-09 09:50:43 +01:00
committed by GitHub
parent e4c3f66a15
commit 0995919da4
2 changed files with 11 additions and 2 deletions

View File

@@ -98,7 +98,7 @@ type fakeLibusb struct {
claims map[*libusbDevice]map[uint8]bool
}
func (f *fakeLibusb) init() (*libusbContext, error) { return new(libusbContext), nil }
func (f *fakeLibusb) init() (*libusbContext, error) { return newContextPointer(), nil }
func (f *fakeLibusb) handleEvents(c *libusbContext, done <-chan struct{}) { <-done }
func (f *fakeLibusb) getDevices(*libusbContext) ([]*libusbDevice, error) {
ret := make([]*libusbDevice, 0, len(fakeDevices))
@@ -128,7 +128,7 @@ func (f *fakeLibusb) getDeviceDesc(d *libusbDevice) (*DeviceDesc, error) {
return nil, fmt.Errorf("invalid USB device %p", d)
}
func (f *fakeLibusb) open(d *libusbDevice) (*libusbDevHandle, error) {
h := new(libusbDevHandle)
h := newDevHandlePointer()
f.mu.Lock()
defer f.mu.Unlock()
f.handles[h] = d