Re: [Xen-devel] [PATCH v3 1/8] golang/xenlight: Don't try to marshall zero-length arrays in fromC
On 1/20/20 11:39 PM, Nick Rosbrook wrote: > Sorry I didn't catch this the first time around, but: > >> diff --git a/tools/golang/xenlight/helpers.gen.go >> b/tools/golang/xenlight/helpers.gen.go >> index b9a7e828a0..889807d928 100644 >> --- a/tools/golang/xenlight/helpers.gen.go >> +++ b/tools/golang/xenlight/helpers.gen.go >> @@ -623,12 +623,14 @@ func (x *SchedParams) toC(xc *C.libxl_sched_params) >> (err error) { >> >> func (x *VcpuSchedParams) fromC(xc *C.libxl_vcpu_sched_params) error { >> x.Sched = Scheduler(xc.sched) >> - numVcpus := int(xc.num_vcpus) >> - cVcpus := (*[1 << >> 28]C.libxl_sched_params)(unsafe.Pointer(xc.vcpus))[:numVcpus:numVcpus] >> - x.Vcpus = make([]SchedParams, numVcpus) >> - for i, v := range cVcpus { >> - if err := x.Vcpus[i].fromC(); err != nil { >> - return err >> + x.Vcpus = nil >> + if numVcpus := int(xc.num_vcpus); numVcpus > 0 { > > > Since `numX` is now scoped to this if block, we could probably just > use `n` or similar and then drop `golenvar` from > `xenlight_golang_array_fromC`. It would remove some pretty ugly > variable names from the generated code :) Yes, that looks good. -George ___ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3 1/8] golang/xenlight: Don't try to marshall zero-length arrays in fromC
Sorry I didn't catch this the first time around, but: > diff --git a/tools/golang/xenlight/helpers.gen.go > b/tools/golang/xenlight/helpers.gen.go > index b9a7e828a0..889807d928 100644 > --- a/tools/golang/xenlight/helpers.gen.go > +++ b/tools/golang/xenlight/helpers.gen.go > @@ -623,12 +623,14 @@ func (x *SchedParams) toC(xc *C.libxl_sched_params) > (err error) { > > func (x *VcpuSchedParams) fromC(xc *C.libxl_vcpu_sched_params) error { > x.Sched = Scheduler(xc.sched) > - numVcpus := int(xc.num_vcpus) > - cVcpus := (*[1 << > 28]C.libxl_sched_params)(unsafe.Pointer(xc.vcpus))[:numVcpus:numVcpus] > - x.Vcpus = make([]SchedParams, numVcpus) > - for i, v := range cVcpus { > - if err := x.Vcpus[i].fromC(); err != nil { > - return err > + x.Vcpus = nil > + if numVcpus := int(xc.num_vcpus); numVcpus > 0 { Since `numX` is now scoped to this if block, we could probably just use `n` or similar and then drop `golenvar` from `xenlight_golang_array_fromC`. It would remove some pretty ugly variable names from the generated code :) -NR ___ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3 1/8] golang/xenlight: Don't try to marshall zero-length arrays in fromC
On 1/17/20 3:57 PM, George Dunlap wrote: > The current fromC array code will do the "magic" casting and > martialling even when num_foo variable is 0. Go crashes when doing > the cast. > > Only do array marshalling if the number of elements is non-zero; > otherwise, leave the target pointer empty (nil for Go slices, NULL for > C arrays). > > Signed-off-by: George Dunlap > --- > v2: > - Remove toC part of this, which has been folded into Nick's patch > series. Er, obviously the subject line should say "v2", for the whole series. :-/ -George ___ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel