@@ -104,7 +104,6 @@ import "C"
104104
105105import (
106106 "fmt"
107- "reflect"
108107 "strings"
109108 "unsafe"
110109)
@@ -459,11 +458,7 @@ type Interface_Descriptor struct {
459458}
460459
461460func (x * Struct_Libusb_Interface_Descriptor ) c2go () * Interface_Descriptor {
462- var list []Struct_Libusb_Endpoint_Descriptor
463- hdr := (* reflect .SliceHeader )(unsafe .Pointer (& list ))
464- hdr .Cap = int (x .bNumEndpoints )
465- hdr .Len = int (x .bNumEndpoints )
466- hdr .Data = uintptr (unsafe .Pointer (x .endpoint ))
461+ list := unsafe .Slice ((* Struct_Libusb_Endpoint_Descriptor )(unsafe .Pointer (x .endpoint )), int (x .bNumEndpoints ))
467462 endpoints := make ([]* Endpoint_Descriptor , x .bNumEndpoints )
468463 for i := range endpoints {
469464 endpoints [i ] = (& list [i ]).c2go ()
@@ -517,11 +512,7 @@ type Interface struct {
517512}
518513
519514func (x * Struct_Libusb_Interface ) c2go () * Interface {
520- var list []Struct_Libusb_Interface_Descriptor
521- hdr := (* reflect .SliceHeader )(unsafe .Pointer (& list ))
522- hdr .Cap = int (x .num_altsetting )
523- hdr .Len = int (x .num_altsetting )
524- hdr .Data = uintptr (unsafe .Pointer (x .altsetting ))
515+ list := unsafe .Slice ((* Struct_Libusb_Interface_Descriptor )(unsafe .Pointer (x .altsetting )), int (x .num_altsetting ))
525516 altsetting := make ([]* Interface_Descriptor , x .num_altsetting )
526517 for i := range altsetting {
527518 altsetting [i ] = (& list [i ]).c2go ()
@@ -567,11 +558,7 @@ type Config_Descriptor struct {
567558}
568559
569560func (x * Struct_Libusb_Config_Descriptor ) c2go () * Config_Descriptor {
570- var list []Struct_Libusb_Interface
571- hdr := (* reflect .SliceHeader )(unsafe .Pointer (& list ))
572- hdr .Cap = int (x .bNumInterfaces )
573- hdr .Len = int (x .bNumInterfaces )
574- hdr .Data = uintptr (unsafe .Pointer (x ._interface ))
561+ list := unsafe .Slice ((* Struct_Libusb_Interface )(unsafe .Pointer (x ._interface )), int (x .bNumInterfaces ))
575562 interfaces := make ([]* Interface , x .bNumInterfaces )
576563 for i := range interfaces {
577564 interfaces [i ] = (& list [i ]).c2go ()
@@ -682,12 +669,8 @@ type BOS_Descriptor struct {
682669}
683670
684671func (x * Struct_Libusb_BOS_Descriptor ) c2go () * BOS_Descriptor {
685- var list []* Struct_Libusb_BOS_Dev_Capability_Descriptor
686672 x_c := (* C .struct_libusb_bos_descriptor )(x )
687- hdr := (* reflect .SliceHeader )(unsafe .Pointer (& list ))
688- hdr .Cap = int (x .bNumDeviceCaps )
689- hdr .Len = int (x .bNumDeviceCaps )
690- hdr .Data = uintptr (unsafe .Pointer (C .dev_capability_ptr (x_c )))
673+ list := unsafe .Slice ((* * Struct_Libusb_BOS_Dev_Capability_Descriptor )(unsafe .Pointer (C .dev_capability_ptr (x_c ))), int (x .bNumDeviceCaps ))
691674 dev_capability := make ([]* BOS_Dev_Capability_Descriptor , x .bNumDeviceCaps )
692675 for i := range dev_capability {
693676 dev_capability [i ] = list [i ].c2go ()
@@ -994,11 +977,7 @@ func Get_Device_List(ctx Context) ([]Device, error) {
994977 return nil , & libusb_error {rc }
995978 }
996979 // turn the c array into a slice of device pointers
997- var list []Device
998- hdr := (* reflect .SliceHeader )(unsafe .Pointer (& list ))
999- hdr .Cap = rc
1000- hdr .Len = rc
1001- hdr .Data = uintptr (unsafe .Pointer (hdl ))
980+ list := unsafe .Slice ((* Device )(unsafe .Pointer (hdl )), rc )
1002981 return list , nil
1003982}
1004983
0 commit comments