From patchwork Mon Mar 9 14:49:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 11427303 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A2AF914E3 for ; Mon, 9 Mar 2020 14:50:50 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 733B621655 for ; Mon, 9 Mar 2020 14:50:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="bW8EEFDK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 733B621655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jBJix-0001SC-Ly; Mon, 09 Mar 2020 14:49:43 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jBJiw-0001Rx-J4 for xen-devel@lists.xenproject.org; Mon, 09 Mar 2020 14:49:42 +0000 X-Inumbo-ID: 34524e68-6215-11ea-8eb5-bc764e2007e4 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 34524e68-6215-11ea-8eb5-bc764e2007e4; Mon, 09 Mar 2020 14:49:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1583765380; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=VMalUWW/mwd8J6AjIboGstDjtuqifUX+O/azJByuSJE=; b=bW8EEFDKD4yjtzI83pwpRw9V4CWOFVTBsHoO4a1G5MKYOAPERpzELpsX xR779d3d5ztTfCP7ZZn7c6lOMhkUCiDRvdp2Ldp5DzZn7O1Aq574FKPas G+gXyljBoo+ZVnWgqOTUKKzi9n5SQ3CT1EKbkXhiSCddpaUNkUwPunxv2 k=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: k1abInyTpTh98QElWzbpYh7AJj8MEao3MhqxK4MSGi/SrV+4VKxomcxGS6/Wa/eZiJrM8a6qVk ++BN4ElD89t9qZ0Va9SLNAVAzmmgTVsgV2K3Hu+RDH0NB1K8uVyQGKWM1T3CYLAnhMeyxJKIzP POa7X1MQkwFq946yOTKLT65UGZcmc0juRIUU8SQUP7mIV7ECxOC0SRheu7vO8taAz9dk+o2svr U6T/SZn8bENQq/P0jNJJPAEg6teBmNxJ3MtGRlc1PRJ6Q87pFamdQd3ryVSMxWOJ/x8tVbh2JM VjE= X-SBRS: 2.7 X-MesageID: 14059255 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,533,1574139600"; d="scan'208";a="14059255" From: George Dunlap To: Date: Mon, 9 Mar 2020 14:49:30 +0000 Message-ID: <20200309144932.866097-1-george.dunlap@citrix.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 1/3] golang/xenlight: Don't try to marshall zero-length arrays in fromC X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Nick Rosbrook , George Dunlap Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 Reviewed-by: Nick Rosbrook --- v4: - Replace fieldname-based variable with 'n' v2: - Remove toC part of this, which has been folded into Nick's patch series. CC: Nick Rosbrook --- tools/golang/xenlight/gengotypes.py | 11 +- tools/golang/xenlight/helpers.gen.go | 440 +++++++++++++++------------ 2 files changed, 257 insertions(+), 194 deletions(-) diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/gengotypes.py index 50dada309b..e9ad92afa0 100644 --- a/tools/golang/xenlight/gengotypes.py +++ b/tools/golang/xenlight/gengotypes.py @@ -426,13 +426,12 @@ def xenlight_golang_array_from_C(ty = None): cname = ty.name cslice = 'c{}'.format(goname) clenvar = ty.type.lenvar.name - golenvar = xenlight_golang_fmt_name(clenvar,exported=False) - s += '{} := int(xc.{})\n'.format(golenvar, clenvar) + s += 'x.{} = nil\n'.format(goname) + s += 'if n := int(xc.{}); n > 0 {{\n'.format(clenvar) s += '{} := '.format(cslice) - s +='(*[1<<28]C.{})(unsafe.Pointer(xc.{}))[:{}:{}]\n'.format(ctypename, cname, - golenvar, golenvar) - s += 'x.{} = make([]{}, {})\n'.format(goname, gotypename, golenvar) + s +='(*[1<<28]C.{})(unsafe.Pointer(xc.{}))[:n:n]\n'.format(ctypename, cname) + s += 'x.{} = make([]{}, n)\n'.format(goname, gotypename) s += 'for i, v := range {} {{\n'.format(cslice) is_enum = isinstance(ty.type.elem_type,idl.Enumeration) @@ -442,7 +441,7 @@ def xenlight_golang_array_from_C(ty = None): s += 'if err := x.{}[i].fromC(&v); err != nil {{\n'.format(goname) s += 'return fmt.Errorf("converting field {}: %v", err) }}\n'.format(goname) - s += '}\n' + s += '}\n}\n' return s diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/helpers.gen.go index 344ce9a461..16e26d27f5 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -889,12 +889,14 @@ func NewVcpuSchedParams() (*VcpuSchedParams, 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(&v); err != nil { - return fmt.Errorf("converting field Vcpus: %v", err) + x.Vcpus = nil + if n := int(xc.num_vcpus); n > 0 { + cVcpus := (*[1 << 28]C.libxl_sched_params)(unsafe.Pointer(xc.vcpus))[:n:n] + x.Vcpus = make([]SchedParams, n) + for i, v := range cVcpus { + if err := x.Vcpus[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Vcpus: %v", err) + } } } @@ -991,11 +993,13 @@ func NewVnodeInfo() (*VnodeInfo, error) { func (x *VnodeInfo) fromC(xc *C.libxl_vnode_info) error { x.Memkb = uint64(xc.memkb) - numDistances := int(xc.num_distances) - cDistances := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.distances))[:numDistances:numDistances] - x.Distances = make([]uint32, numDistances) - for i, v := range cDistances { - x.Distances[i] = uint32(v) + x.Distances = nil + if n := int(xc.num_distances); n > 0 { + cDistances := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.distances))[:n:n] + x.Distances = make([]uint32, n) + for i, v := range cDistances { + x.Distances[i] = uint32(v) + } } x.Pnode = uint32(xc.pnode) if err := x.Vcpus.fromC(&xc.vcpus); err != nil { @@ -1095,20 +1099,24 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { if err := x.Nodemap.fromC(&xc.nodemap); err != nil { return fmt.Errorf("converting field Nodemap: %v", err) } - numVcpuHardAffinity := int(xc.num_vcpu_hard_affinity) - cVcpuHardAffinity := (*[1 << 28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_hard_affinity))[:numVcpuHardAffinity:numVcpuHardAffinity] - x.VcpuHardAffinity = make([]Bitmap, numVcpuHardAffinity) - for i, v := range cVcpuHardAffinity { - if err := x.VcpuHardAffinity[i].fromC(&v); err != nil { - return fmt.Errorf("converting field VcpuHardAffinity: %v", err) + x.VcpuHardAffinity = nil + if n := int(xc.num_vcpu_hard_affinity); n > 0 { + cVcpuHardAffinity := (*[1 << 28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_hard_affinity))[:n:n] + x.VcpuHardAffinity = make([]Bitmap, n) + for i, v := range cVcpuHardAffinity { + if err := x.VcpuHardAffinity[i].fromC(&v); err != nil { + return fmt.Errorf("converting field VcpuHardAffinity: %v", err) + } } } - numVcpuSoftAffinity := int(xc.num_vcpu_soft_affinity) - cVcpuSoftAffinity := (*[1 << 28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_soft_affinity))[:numVcpuSoftAffinity:numVcpuSoftAffinity] - x.VcpuSoftAffinity = make([]Bitmap, numVcpuSoftAffinity) - for i, v := range cVcpuSoftAffinity { - if err := x.VcpuSoftAffinity[i].fromC(&v); err != nil { - return fmt.Errorf("converting field VcpuSoftAffinity: %v", err) + x.VcpuSoftAffinity = nil + if n := int(xc.num_vcpu_soft_affinity); n > 0 { + cVcpuSoftAffinity := (*[1 << 28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_soft_affinity))[:n:n] + x.VcpuSoftAffinity = make([]Bitmap, n) + for i, v := range cVcpuSoftAffinity { + if err := x.VcpuSoftAffinity[i].fromC(&v); err != nil { + return fmt.Errorf("converting field VcpuSoftAffinity: %v", err) + } } } if err := x.NumaPlacement.fromC(&xc.numa_placement); err != nil { @@ -1133,12 +1141,14 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { return fmt.Errorf("converting field Cpuid: %v", err) } x.BlkdevStart = C.GoString(xc.blkdev_start) - numVnumaNodes := int(xc.num_vnuma_nodes) - cVnumaNodes := (*[1 << 28]C.libxl_vnode_info)(unsafe.Pointer(xc.vnuma_nodes))[:numVnumaNodes:numVnumaNodes] - x.VnumaNodes = make([]VnodeInfo, numVnumaNodes) - for i, v := range cVnumaNodes { - if err := x.VnumaNodes[i].fromC(&v); err != nil { - return fmt.Errorf("converting field VnumaNodes: %v", err) + x.VnumaNodes = nil + if n := int(xc.num_vnuma_nodes); n > 0 { + cVnumaNodes := (*[1 << 28]C.libxl_vnode_info)(unsafe.Pointer(xc.vnuma_nodes))[:n:n] + x.VnumaNodes = make([]VnodeInfo, n) + for i, v := range cVnumaNodes { + if err := x.VnumaNodes[i].fromC(&v); err != nil { + return fmt.Errorf("converting field VnumaNodes: %v", err) + } } } x.MaxGrantFrames = uint32(xc.max_grant_frames) @@ -1163,26 +1173,32 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { if err := x.SchedParams.fromC(&xc.sched_params); err != nil { return fmt.Errorf("converting field SchedParams: %v", err) } - numIoports := int(xc.num_ioports) - cIoports := (*[1 << 28]C.libxl_ioport_range)(unsafe.Pointer(xc.ioports))[:numIoports:numIoports] - x.Ioports = make([]IoportRange, numIoports) - for i, v := range cIoports { - if err := x.Ioports[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Ioports: %v", err) + x.Ioports = nil + if n := int(xc.num_ioports); n > 0 { + cIoports := (*[1 << 28]C.libxl_ioport_range)(unsafe.Pointer(xc.ioports))[:n:n] + x.Ioports = make([]IoportRange, n) + for i, v := range cIoports { + if err := x.Ioports[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Ioports: %v", err) + } } } - numIrqs := int(xc.num_irqs) - cIrqs := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.irqs))[:numIrqs:numIrqs] - x.Irqs = make([]uint32, numIrqs) - for i, v := range cIrqs { - x.Irqs[i] = uint32(v) + x.Irqs = nil + if n := int(xc.num_irqs); n > 0 { + cIrqs := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.irqs))[:n:n] + x.Irqs = make([]uint32, n) + for i, v := range cIrqs { + x.Irqs[i] = uint32(v) + } } - numIomem := int(xc.num_iomem) - cIomem := (*[1 << 28]C.libxl_iomem_range)(unsafe.Pointer(xc.iomem))[:numIomem:numIomem] - x.Iomem = make([]IomemRange, numIomem) - for i, v := range cIomem { - if err := x.Iomem[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Iomem: %v", err) + x.Iomem = nil + if n := int(xc.num_iomem); n > 0 { + cIomem := (*[1 << 28]C.libxl_iomem_range)(unsafe.Pointer(xc.iomem))[:n:n] + x.Iomem = make([]IomemRange, n) + for i, v := range cIomem { + if err := x.Iomem[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Iomem: %v", err) + } } } if err := x.ClaimMode.fromC(&xc.claim_mode); err != nil { @@ -2791,12 +2807,14 @@ func (x *DeviceVdispl) fromC(xc *C.libxl_device_vdispl) error { x.BackendDomname = C.GoString(xc.backend_domname) x.Devid = Devid(xc.devid) x.BeAlloc = bool(xc.be_alloc) - numConnectors := int(xc.num_connectors) - cConnectors := (*[1 << 28]C.libxl_connector_param)(unsafe.Pointer(xc.connectors))[:numConnectors:numConnectors] - x.Connectors = make([]ConnectorParam, numConnectors) - for i, v := range cConnectors { - if err := x.Connectors[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Connectors: %v", err) + x.Connectors = nil + if n := int(xc.num_connectors); n > 0 { + cConnectors := (*[1 << 28]C.libxl_connector_param)(unsafe.Pointer(xc.connectors))[:n:n] + x.Connectors = make([]ConnectorParam, n) + for i, v := range cConnectors { + if err := x.Connectors[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Connectors: %v", err) + } } } @@ -2848,17 +2866,21 @@ func NewVsndParams() (*VsndParams, error) { } func (x *VsndParams) fromC(xc *C.libxl_vsnd_params) error { - numSampleRates := int(xc.num_sample_rates) - cSampleRates := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.sample_rates))[:numSampleRates:numSampleRates] - x.SampleRates = make([]uint32, numSampleRates) - for i, v := range cSampleRates { - x.SampleRates[i] = uint32(v) - } - numSampleFormats := int(xc.num_sample_formats) - cSampleFormats := (*[1 << 28]C.libxl_vsnd_pcm_format)(unsafe.Pointer(xc.sample_formats))[:numSampleFormats:numSampleFormats] - x.SampleFormats = make([]VsndPcmFormat, numSampleFormats) - for i, v := range cSampleFormats { - x.SampleFormats[i] = VsndPcmFormat(v) + x.SampleRates = nil + if n := int(xc.num_sample_rates); n > 0 { + cSampleRates := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.sample_rates))[:n:n] + x.SampleRates = make([]uint32, n) + for i, v := range cSampleRates { + x.SampleRates[i] = uint32(v) + } + } + x.SampleFormats = nil + if n := int(xc.num_sample_formats); n > 0 { + cSampleFormats := (*[1 << 28]C.libxl_vsnd_pcm_format)(unsafe.Pointer(xc.sample_formats))[:n:n] + x.SampleFormats = make([]VsndPcmFormat, n) + for i, v := range cSampleFormats { + x.SampleFormats[i] = VsndPcmFormat(v) + } } x.ChannelsMin = uint32(xc.channels_min) x.ChannelsMax = uint32(xc.channels_max) @@ -2964,12 +2986,14 @@ func (x *VsndPcm) fromC(xc *C.libxl_vsnd_pcm) error { if err := x.Params.fromC(&xc.params); err != nil { return fmt.Errorf("converting field Params: %v", err) } - numVsndStreams := int(xc.num_vsnd_streams) - cStreams := (*[1 << 28]C.libxl_vsnd_stream)(unsafe.Pointer(xc.streams))[:numVsndStreams:numVsndStreams] - x.Streams = make([]VsndStream, numVsndStreams) - for i, v := range cStreams { - if err := x.Streams[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Streams: %v", err) + x.Streams = nil + if n := int(xc.num_vsnd_streams); n > 0 { + cStreams := (*[1 << 28]C.libxl_vsnd_stream)(unsafe.Pointer(xc.streams))[:n:n] + x.Streams = make([]VsndStream, n) + for i, v := range cStreams { + if err := x.Streams[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Streams: %v", err) + } } } @@ -3029,12 +3053,14 @@ func (x *DeviceVsnd) fromC(xc *C.libxl_device_vsnd) error { if err := x.Params.fromC(&xc.params); err != nil { return fmt.Errorf("converting field Params: %v", err) } - numVsndPcms := int(xc.num_vsnd_pcms) - cPcms := (*[1 << 28]C.libxl_vsnd_pcm)(unsafe.Pointer(xc.pcms))[:numVsndPcms:numVsndPcms] - x.Pcms = make([]VsndPcm, numVsndPcms) - for i, v := range cPcms { - if err := x.Pcms[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Pcms: %v", err) + x.Pcms = nil + if n := int(xc.num_vsnd_pcms); n > 0 { + cPcms := (*[1 << 28]C.libxl_vsnd_pcm)(unsafe.Pointer(xc.pcms))[:n:n] + x.Pcms = make([]VsndPcm, n) + for i, v := range cPcms { + if err := x.Pcms[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Pcms: %v", err) + } } } @@ -3100,124 +3126,154 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { if err := x.BInfo.fromC(&xc.b_info); err != nil { return fmt.Errorf("converting field BInfo: %v", err) } - numDisks := int(xc.num_disks) - cDisks := (*[1 << 28]C.libxl_device_disk)(unsafe.Pointer(xc.disks))[:numDisks:numDisks] - x.Disks = make([]DeviceDisk, numDisks) - for i, v := range cDisks { - if err := x.Disks[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Disks: %v", err) + x.Disks = nil + if n := int(xc.num_disks); n > 0 { + cDisks := (*[1 << 28]C.libxl_device_disk)(unsafe.Pointer(xc.disks))[:n:n] + x.Disks = make([]DeviceDisk, n) + for i, v := range cDisks { + if err := x.Disks[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Disks: %v", err) + } } } - numNics := int(xc.num_nics) - cNics := (*[1 << 28]C.libxl_device_nic)(unsafe.Pointer(xc.nics))[:numNics:numNics] - x.Nics = make([]DeviceNic, numNics) - for i, v := range cNics { - if err := x.Nics[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Nics: %v", err) + x.Nics = nil + if n := int(xc.num_nics); n > 0 { + cNics := (*[1 << 28]C.libxl_device_nic)(unsafe.Pointer(xc.nics))[:n:n] + x.Nics = make([]DeviceNic, n) + for i, v := range cNics { + if err := x.Nics[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Nics: %v", err) + } } } - numPcidevs := int(xc.num_pcidevs) - cPcidevs := (*[1 << 28]C.libxl_device_pci)(unsafe.Pointer(xc.pcidevs))[:numPcidevs:numPcidevs] - x.Pcidevs = make([]DevicePci, numPcidevs) - for i, v := range cPcidevs { - if err := x.Pcidevs[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Pcidevs: %v", err) + x.Pcidevs = nil + if n := int(xc.num_pcidevs); n > 0 { + cPcidevs := (*[1 << 28]C.libxl_device_pci)(unsafe.Pointer(xc.pcidevs))[:n:n] + x.Pcidevs = make([]DevicePci, n) + for i, v := range cPcidevs { + if err := x.Pcidevs[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Pcidevs: %v", err) + } } } - numRdms := int(xc.num_rdms) - cRdms := (*[1 << 28]C.libxl_device_rdm)(unsafe.Pointer(xc.rdms))[:numRdms:numRdms] - x.Rdms = make([]DeviceRdm, numRdms) - for i, v := range cRdms { - if err := x.Rdms[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Rdms: %v", err) + x.Rdms = nil + if n := int(xc.num_rdms); n > 0 { + cRdms := (*[1 << 28]C.libxl_device_rdm)(unsafe.Pointer(xc.rdms))[:n:n] + x.Rdms = make([]DeviceRdm, n) + for i, v := range cRdms { + if err := x.Rdms[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Rdms: %v", err) + } } } - numDtdevs := int(xc.num_dtdevs) - cDtdevs := (*[1 << 28]C.libxl_device_dtdev)(unsafe.Pointer(xc.dtdevs))[:numDtdevs:numDtdevs] - x.Dtdevs = make([]DeviceDtdev, numDtdevs) - for i, v := range cDtdevs { - if err := x.Dtdevs[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Dtdevs: %v", err) + x.Dtdevs = nil + if n := int(xc.num_dtdevs); n > 0 { + cDtdevs := (*[1 << 28]C.libxl_device_dtdev)(unsafe.Pointer(xc.dtdevs))[:n:n] + x.Dtdevs = make([]DeviceDtdev, n) + for i, v := range cDtdevs { + if err := x.Dtdevs[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Dtdevs: %v", err) + } } } - numVfbs := int(xc.num_vfbs) - cVfbs := (*[1 << 28]C.libxl_device_vfb)(unsafe.Pointer(xc.vfbs))[:numVfbs:numVfbs] - x.Vfbs = make([]DeviceVfb, numVfbs) - for i, v := range cVfbs { - if err := x.Vfbs[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Vfbs: %v", err) + x.Vfbs = nil + if n := int(xc.num_vfbs); n > 0 { + cVfbs := (*[1 << 28]C.libxl_device_vfb)(unsafe.Pointer(xc.vfbs))[:n:n] + x.Vfbs = make([]DeviceVfb, n) + for i, v := range cVfbs { + if err := x.Vfbs[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Vfbs: %v", err) + } } } - numVkbs := int(xc.num_vkbs) - cVkbs := (*[1 << 28]C.libxl_device_vkb)(unsafe.Pointer(xc.vkbs))[:numVkbs:numVkbs] - x.Vkbs = make([]DeviceVkb, numVkbs) - for i, v := range cVkbs { - if err := x.Vkbs[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Vkbs: %v", err) + x.Vkbs = nil + if n := int(xc.num_vkbs); n > 0 { + cVkbs := (*[1 << 28]C.libxl_device_vkb)(unsafe.Pointer(xc.vkbs))[:n:n] + x.Vkbs = make([]DeviceVkb, n) + for i, v := range cVkbs { + if err := x.Vkbs[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Vkbs: %v", err) + } } } - numVtpms := int(xc.num_vtpms) - cVtpms := (*[1 << 28]C.libxl_device_vtpm)(unsafe.Pointer(xc.vtpms))[:numVtpms:numVtpms] - x.Vtpms = make([]DeviceVtpm, numVtpms) - for i, v := range cVtpms { - if err := x.Vtpms[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Vtpms: %v", err) + x.Vtpms = nil + if n := int(xc.num_vtpms); n > 0 { + cVtpms := (*[1 << 28]C.libxl_device_vtpm)(unsafe.Pointer(xc.vtpms))[:n:n] + x.Vtpms = make([]DeviceVtpm, n) + for i, v := range cVtpms { + if err := x.Vtpms[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Vtpms: %v", err) + } } } - numP9S := int(xc.num_p9s) - cP9S := (*[1 << 28]C.libxl_device_p9)(unsafe.Pointer(xc.p9s))[:numP9S:numP9S] - x.P9S = make([]DeviceP9, numP9S) - for i, v := range cP9S { - if err := x.P9S[i].fromC(&v); err != nil { - return fmt.Errorf("converting field P9S: %v", err) + x.P9S = nil + if n := int(xc.num_p9s); n > 0 { + cP9S := (*[1 << 28]C.libxl_device_p9)(unsafe.Pointer(xc.p9s))[:n:n] + x.P9S = make([]DeviceP9, n) + for i, v := range cP9S { + if err := x.P9S[i].fromC(&v); err != nil { + return fmt.Errorf("converting field P9S: %v", err) + } } } - numPvcallsifs := int(xc.num_pvcallsifs) - cPvcallsifs := (*[1 << 28]C.libxl_device_pvcallsif)(unsafe.Pointer(xc.pvcallsifs))[:numPvcallsifs:numPvcallsifs] - x.Pvcallsifs = make([]DevicePvcallsif, numPvcallsifs) - for i, v := range cPvcallsifs { - if err := x.Pvcallsifs[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Pvcallsifs: %v", err) + x.Pvcallsifs = nil + if n := int(xc.num_pvcallsifs); n > 0 { + cPvcallsifs := (*[1 << 28]C.libxl_device_pvcallsif)(unsafe.Pointer(xc.pvcallsifs))[:n:n] + x.Pvcallsifs = make([]DevicePvcallsif, n) + for i, v := range cPvcallsifs { + if err := x.Pvcallsifs[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Pvcallsifs: %v", err) + } } } - numVdispls := int(xc.num_vdispls) - cVdispls := (*[1 << 28]C.libxl_device_vdispl)(unsafe.Pointer(xc.vdispls))[:numVdispls:numVdispls] - x.Vdispls = make([]DeviceVdispl, numVdispls) - for i, v := range cVdispls { - if err := x.Vdispls[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Vdispls: %v", err) + x.Vdispls = nil + if n := int(xc.num_vdispls); n > 0 { + cVdispls := (*[1 << 28]C.libxl_device_vdispl)(unsafe.Pointer(xc.vdispls))[:n:n] + x.Vdispls = make([]DeviceVdispl, n) + for i, v := range cVdispls { + if err := x.Vdispls[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Vdispls: %v", err) + } } } - numVsnds := int(xc.num_vsnds) - cVsnds := (*[1 << 28]C.libxl_device_vsnd)(unsafe.Pointer(xc.vsnds))[:numVsnds:numVsnds] - x.Vsnds = make([]DeviceVsnd, numVsnds) - for i, v := range cVsnds { - if err := x.Vsnds[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Vsnds: %v", err) + x.Vsnds = nil + if n := int(xc.num_vsnds); n > 0 { + cVsnds := (*[1 << 28]C.libxl_device_vsnd)(unsafe.Pointer(xc.vsnds))[:n:n] + x.Vsnds = make([]DeviceVsnd, n) + for i, v := range cVsnds { + if err := x.Vsnds[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Vsnds: %v", err) + } } } - numChannels := int(xc.num_channels) - cChannels := (*[1 << 28]C.libxl_device_channel)(unsafe.Pointer(xc.channels))[:numChannels:numChannels] - x.Channels = make([]DeviceChannel, numChannels) - for i, v := range cChannels { - if err := x.Channels[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Channels: %v", err) + x.Channels = nil + if n := int(xc.num_channels); n > 0 { + cChannels := (*[1 << 28]C.libxl_device_channel)(unsafe.Pointer(xc.channels))[:n:n] + x.Channels = make([]DeviceChannel, n) + for i, v := range cChannels { + if err := x.Channels[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Channels: %v", err) + } } } - numUsbctrls := int(xc.num_usbctrls) - cUsbctrls := (*[1 << 28]C.libxl_device_usbctrl)(unsafe.Pointer(xc.usbctrls))[:numUsbctrls:numUsbctrls] - x.Usbctrls = make([]DeviceUsbctrl, numUsbctrls) - for i, v := range cUsbctrls { - if err := x.Usbctrls[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Usbctrls: %v", err) + x.Usbctrls = nil + if n := int(xc.num_usbctrls); n > 0 { + cUsbctrls := (*[1 << 28]C.libxl_device_usbctrl)(unsafe.Pointer(xc.usbctrls))[:n:n] + x.Usbctrls = make([]DeviceUsbctrl, n) + for i, v := range cUsbctrls { + if err := x.Usbctrls[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Usbctrls: %v", err) + } } } - numUsbdevs := int(xc.num_usbdevs) - cUsbdevs := (*[1 << 28]C.libxl_device_usbdev)(unsafe.Pointer(xc.usbdevs))[:numUsbdevs:numUsbdevs] - x.Usbdevs = make([]DeviceUsbdev, numUsbdevs) - for i, v := range cUsbdevs { - if err := x.Usbdevs[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Usbdevs: %v", err) + x.Usbdevs = nil + if n := int(xc.num_usbdevs); n > 0 { + cUsbdevs := (*[1 << 28]C.libxl_device_usbdev)(unsafe.Pointer(xc.usbdevs))[:n:n] + x.Usbdevs = make([]DeviceUsbdev, n) + for i, v := range cUsbdevs { + if err := x.Usbdevs[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Usbdevs: %v", err) + } } } x.OnPoweroff = ActionOnShutdown(xc.on_poweroff) @@ -3837,12 +3893,14 @@ func (x *Vdisplinfo) fromC(xc *C.libxl_vdisplinfo) error { x.Devid = Devid(xc.devid) x.State = int(xc.state) x.BeAlloc = bool(xc.be_alloc) - numConnectors := int(xc.num_connectors) - cConnectors := (*[1 << 28]C.libxl_connectorinfo)(unsafe.Pointer(xc.connectors))[:numConnectors:numConnectors] - x.Connectors = make([]Connectorinfo, numConnectors) - for i, v := range cConnectors { - if err := x.Connectors[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Connectors: %v", err) + x.Connectors = nil + if n := int(xc.num_connectors); n > 0 { + cConnectors := (*[1 << 28]C.libxl_connectorinfo)(unsafe.Pointer(xc.connectors))[:n:n] + x.Connectors = make([]Connectorinfo, n) + for i, v := range cConnectors { + if err := x.Connectors[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Connectors: %v", err) + } } } @@ -3936,12 +3994,14 @@ func NewPcminfo() (*Pcminfo, error) { } func (x *Pcminfo) fromC(xc *C.libxl_pcminfo) error { - numVsndStreams := int(xc.num_vsnd_streams) - cStreams := (*[1 << 28]C.libxl_streaminfo)(unsafe.Pointer(xc.streams))[:numVsndStreams:numVsndStreams] - x.Streams = make([]Streaminfo, numVsndStreams) - for i, v := range cStreams { - if err := x.Streams[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Streams: %v", err) + x.Streams = nil + if n := int(xc.num_vsnd_streams); n > 0 { + cStreams := (*[1 << 28]C.libxl_streaminfo)(unsafe.Pointer(xc.streams))[:n:n] + x.Streams = make([]Streaminfo, n) + for i, v := range cStreams { + if err := x.Streams[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Streams: %v", err) + } } } @@ -3993,12 +4053,14 @@ func (x *Vsndinfo) fromC(xc *C.libxl_vsndinfo) error { x.FrontendId = uint32(xc.frontend_id) x.Devid = Devid(xc.devid) x.State = int(xc.state) - numVsndPcms := int(xc.num_vsnd_pcms) - cPcms := (*[1 << 28]C.libxl_pcminfo)(unsafe.Pointer(xc.pcms))[:numVsndPcms:numVsndPcms] - x.Pcms = make([]Pcminfo, numVsndPcms) - for i, v := range cPcms { - if err := x.Pcms[i].fromC(&v); err != nil { - return fmt.Errorf("converting field Pcms: %v", err) + x.Pcms = nil + if n := int(xc.num_vsnd_pcms); n > 0 { + cPcms := (*[1 << 28]C.libxl_pcminfo)(unsafe.Pointer(xc.pcms))[:n:n] + x.Pcms = make([]Pcminfo, n) + for i, v := range cPcms { + if err := x.Pcms[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Pcms: %v", err) + } } } @@ -4109,11 +4171,13 @@ func NewNumainfo() (*Numainfo, error) { func (x *Numainfo) fromC(xc *C.libxl_numainfo) error { x.Size = uint64(xc.size) x.Free = uint64(xc.free) - numDists := int(xc.num_dists) - cDists := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.dists))[:numDists:numDists] - x.Dists = make([]uint32, numDists) - for i, v := range cDists { - x.Dists[i] = uint32(v) + x.Dists = nil + if n := int(xc.num_dists); n > 0 { + cDists := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.dists))[:n:n] + x.Dists = make([]uint32, n) + for i, v := range cDists { + x.Dists[i] = uint32(v) + } } return nil