From nobody Thu Nov 28 07:41:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1678135271; cv=none; d=zohomail.com; s=zohoarc; b=K9a5b7rHyLQ6UiDeAFnxFfvZ+3VDndkq3tyAjsme8DvKGws9oTlV/AXgtBWvnSoGnSsGHUf+DBykrkAuvJOWzW76Tpq2I1G3QHuqvFDaqNsAxtPX5CWnbvfFET3ZV5xANmjOcnhcLWLLQ3Xpa+q5TXKd98MRGc+8pGswjERmrwU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678135271; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y28wWCfzzCCf0En/MTSEqU7UtSyyDPmGt1fjWU1k+QE=; b=UpLCDKxNif90FFaUbAlLfGZ1XKl4Ri+v5lvntNv2vN6eavR8oNz3kcoeuKiI1PMLpOzWo1Fpg15FWpZpwgKoPJaP33TXpDfeb6oc+1osSYaivDuGv7exse2Mt56Zqc0rxmCbOpXmyb6cjxuz8jCqPAnfHzRlrd6b8E/M2qeTeFM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1678135271189878.1641987368376; Mon, 6 Mar 2023 12:41:11 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.507109.780327 (Exim 4.92) (envelope-from ) id 1pZHdR-00011F-95; Mon, 06 Mar 2023 20:40:41 +0000 Received: by outflank-mailman (output) from mailman id 507109.780327; Mon, 06 Mar 2023 20:40:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pZHdR-000118-5p; Mon, 06 Mar 2023 20:40:41 +0000 Received: by outflank-mailman (input) for mailman id 507109; Mon, 06 Mar 2023 20:40:40 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pZHdQ-0000m6-7n for xen-devel@lists.xenproject.org; Mon, 06 Mar 2023 20:40:40 +0000 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [2607:f8b0:4864:20::82b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2783c7fd-bc5f-11ed-96b5-2f268f93b82a; Mon, 06 Mar 2023 21:40:39 +0100 (CET) Received: by mail-qt1-x82b.google.com with SMTP id c3so12081786qtc.8 for ; Mon, 06 Mar 2023 12:40:39 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:2825:cedc:1289:7391]) by smtp.gmail.com with ESMTPSA id j10-20020ac8440a000000b003b82a07c4d6sm8086316qtn.84.2023.03.06.12.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 12:40:37 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2783c7fd-bc5f-11ed-96b5-2f268f93b82a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678135238; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y28wWCfzzCCf0En/MTSEqU7UtSyyDPmGt1fjWU1k+QE=; b=pOS7MOKa3aKm/6gJKPiLUcYhTlP3C4ufRg/Wbl6qeTAFw+ISxiqBfqrE/LxRqBmWPN AyC3PRQAQugtmJbbKnzic9Ct6mHPIu5iwG4jJh3Q4Hhu11x+XsHmcUP0+lNflE7jWZKy Y+oQmYsVSl+7etoAzBMB4hg4lCPuGSnwEOTMo0Fz3yF6g3AkV/mYkZlr894Nd2UZ8Krl 673NrSHdTYtS99eYlduJVrqMS/Bt7VU2Solk8D6Dj2In0TkVq48hje0nTfThb4GHQmSm 7/VO3+UdUUu+oidohm9jcrmnWaRnSbbfXmpUWkryUeAk+AKbFyZjTFwBbLi18VN3gYaL Mong== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678135238; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y28wWCfzzCCf0En/MTSEqU7UtSyyDPmGt1fjWU1k+QE=; b=FYu83frzJM9Rt1+A5+/WFAWIWagundxBmZo+J18ue3wk1vwp2QPsass4Ia6U+o4zOn fTKR2JnOpkcFTQigiGc4re9iQTAoquFcdp1Kse3sliaGOveBA8Ckw+GdVrtcj1HpAYso rg+q7vqRD0TS79FPkABrgk9iMFfIpz0xs2c2i66/7kWmXpy0ensDVT2EMkjx6A+cPWYY bkRnWlxu2d57k7D3010ONJmiP8Vs9Aj+a6RZGBRZ8YFAqBnsg7JfpQtDYNbnO0IhQbBW qkMzECDakW64edbiTJOq17RMuI/6pGy9ZLB1p249LZmK//SkFUFwzzR9q2oDg8u3q7XQ 3pBg== X-Gm-Message-State: AO0yUKUcEc/0IAFLUh7BU9ebD3Vap7XhKVAGtp2Nqh2bQbpl2JKfR4UQ qyK4glbUCM6BSyD6U1cHEMCajh3ZY9g= X-Google-Smtp-Source: AK7set+8EY1clqDGMHutI3NT4TBwSF9qFqitsupVTFFzFDB9+Gyfw1lnf9qnLSfekCSsWCq8ny8RXA== X-Received: by 2002:ac8:4e8f:0:b0:3bf:cea5:9866 with SMTP id 15-20020ac84e8f000000b003bfcea59866mr21102985qtp.24.1678135237738; Mon, 06 Mar 2023 12:40:37 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , George Dunlap , Nick Rosbrook , Wei Liu , Anthony PERARD Subject: [PATCH v4 1/3] golang/xenlight: Extend KeyedUnion to support Arrays Date: Mon, 6 Mar 2023 15:40:22 -0500 Message-Id: <20230306204024.124882-2-jandryuk@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230306204024.124882-1-jandryuk@gmail.com> References: <20230306204024.124882-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1678135271715100001 Content-Type: text/plain; charset="utf-8" Generation for KeyedUnion types doesn't support Arrays. The smbios support will place an smbios array inside the hvm KeyedUnion, and gentotypes doesn't generate buildable Go code. Have KeyedUnion add an idl.Array check and issue the approriate xenlight_golang_array_to_C and xenlight_golang_array_from_C calls when needed. This matches how it is done in xenlight_golang_define_to_C & xenlight_golang_define_from_C xenlight_golang_array_to_C and xenlight_golang_array_from_C need to be extended to set the cvarname and govarname as approriate for the KeyedUnion cases to match the surrounding code. Signed-off-by: Jason Andryuk --- tools/golang/xenlight/gengotypes.py | 41 ++++++++++++++++++----------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/ge= ngotypes.py index 9fec60602d..e4eb7ca1c1 100644 --- a/tools/golang/xenlight/gengotypes.py +++ b/tools/golang/xenlight/gengotypes.py @@ -376,6 +376,10 @@ def xenlight_golang_union_from_C(ty =3D None, union_na= me =3D '', struct_name =3D ''): s +=3D 'tmp :=3D (*C.{0})(unsafe.Pointer(&xc.{1}[0]))\n'.format(ty= pename,union_name) =20 for nf in f.type.fields: + if isinstance(nf.type, idl.Array): + s +=3D xenlight_golang_array_from_C(nf,cvarname=3D'tmp') + continue + s +=3D xenlight_golang_convert_from_C(nf,cvarname=3D'tmp') =20 s +=3D 'return nil\n' @@ -416,7 +420,7 @@ def xenlight_golang_union_from_C(ty =3D None, union_nam= e =3D '', struct_name =3D ''): =20 return (s,extras) =20 -def xenlight_golang_array_from_C(ty =3D None): +def xenlight_golang_array_from_C(ty =3D None, cvarname =3D 'xc'): """ Convert C array to Go slice using the method described here: @@ -433,9 +437,9 @@ def xenlight_golang_array_from_C(ty =3D None): clenvar =3D ty.type.lenvar.name =20 s +=3D 'x.{0} =3D nil\n'.format(goname) - s +=3D 'if n :=3D int(xc.{0}); n > 0 {{\n'.format(clenvar) + s +=3D 'if n :=3D int({0}.{1}); n > 0 {{\n'.format(cvarname,clenvar) s +=3D '{0} :=3D '.format(cslice) - s +=3D'(*[1<<28]C.{0})(unsafe.Pointer(xc.{1}))[:n:n]\n'.format(ctypena= me, cname) + s +=3D'(*[1<<28]C.{0})(unsafe.Pointer({1}.{2}))[:n:n]\n'.format(ctypen= ame, cvarname, cname) s +=3D 'x.{0} =3D make([]{1}, n)\n'.format(goname, gotypename) s +=3D 'for i, v :=3D range {0} {{\n'.format(cslice) =20 @@ -579,6 +583,11 @@ def xenlight_golang_union_to_C(ty =3D None, union_name= =3D '', =20 s +=3D 'var {0} C.{1}\n'.format(f.name,cgotype) for uf in f.type.fields: + if isinstance(uf.type, idl.Array): + s +=3D xenlight_golang_array_to_C(uf, cvarname=3Df.name, + govarname=3D"tmp") + continue + s +=3D xenlight_golang_convert_to_C(uf,cvarname=3Df.name, govarname=3D'tmp') =20 @@ -596,7 +605,7 @@ def xenlight_golang_union_to_C(ty =3D None, union_name = =3D '', =20 return s =20 -def xenlight_golang_array_to_C(ty =3D None): +def xenlight_golang_array_to_C(ty =3D None, cvarname=3D"xc", govarname=3D"= x"): s =3D '' =20 gotypename =3D xenlight_golang_fmt_name(ty.type.elem_type.typename) @@ -608,27 +617,27 @@ def xenlight_golang_array_to_C(ty =3D None): =20 is_enum =3D isinstance(ty.type.elem_type,idl.Enumeration) if gotypename in go_builtin_types or is_enum: - s +=3D 'if {0} :=3D len(x.{1}); {2} > 0 {{\n'.format(golenvar,gona= me,golenvar) - s +=3D 'xc.{0} =3D (*C.{1})(C.malloc(C.size_t({2}*{3})))\n'.format= (cname,ctypename, + s +=3D 'if {0} :=3D len({1}.{2}); {3} > 0 {{\n'.format(golenvar,go= varname,goname,golenvar) + s +=3D '{0}.{1} =3D (*C.{2})(C.malloc(C.size_t({3}*{4})))\n'.forma= t(cvarname,cname,ctypename, golenva= r,golenvar) - s +=3D 'xc.{0} =3D C.int({1})\n'.format(clenvar,golenvar) - s +=3D 'c{0} :=3D (*[1<<28]C.{1})(unsafe.Pointer(xc.{2}))[:{3}:{4}= ]\n'.format(goname, - ctyp= ename,cname, + s +=3D '{0}.{1} =3D C.int({2})\n'.format(cvarname,clenvar,golenvar) + s +=3D 'c{0} :=3D (*[1<<28]C.{1})(unsafe.Pointer({2}.{3}))[:{4}:{5= }]\n'.format(goname, + ctyp= ename,cvarname,cname, gole= nvar,golenvar) - s +=3D 'for i,v :=3D range x.{0} {{\n'.format(goname) + s +=3D 'for i,v :=3D range {0}.{1} {{\n'.format(govarname,goname) s +=3D 'c{0}[i] =3D C.{1}(v)\n'.format(goname,ctypename) s +=3D '}\n}\n' =20 return s =20 - s +=3D 'if {0} :=3D len(x.{1}); {2} > 0 {{\n'.format(golenvar,goname,g= olenvar) - s +=3D 'xc.{0} =3D (*C.{1})(C.malloc(C.ulong({2})*C.sizeof_{3}))\n'.fo= rmat(cname,ctypename, + s +=3D 'if {0} :=3D len({1}.{2}); {3} > 0 {{\n'.format(golenvar,govarn= ame,goname,golenvar) + s +=3D '{0}.{1} =3D (*C.{2})(C.malloc(C.ulong({3})*C.sizeof_{4}))\n'.f= ormat(cvarname,cname,ctypename, golenva= r,ctypename) - s +=3D 'xc.{0} =3D C.int({1})\n'.format(clenvar,golenvar) - s +=3D 'c{0} :=3D (*[1<<28]C.{1})(unsafe.Pointer(xc.{2}))[:{3}:{4}]\n'= .format(goname, - c= typename,cname, + s +=3D '{0}.{1} =3D C.int({2})\n'.format(cvarname,clenvar,golenvar) + s +=3D 'c{0} :=3D (*[1<<28]C.{1})(unsafe.Pointer({2}.{3}))[:{4}:{5}]\n= '.format(goname, + c= typename,cvarname,cname, g= olenvar,golenvar) - s +=3D 'for i,v :=3D range x.{0} {{\n'.format(goname) + s +=3D 'for i,v :=3D range {0}.{1} {{\n'.format(govarname,goname) s +=3D 'if err :=3D v.toC(&c{0}[i]); err !=3D nil {{\n'.format(goname) s +=3D 'return fmt.Errorf("converting field {0}: %v", err)\n'.format(g= oname) s +=3D '}\n}\n}\n' --=20 2.39.2