From patchwork Thu Sep 8 19:51:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12970616 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 58D8DC54EE9 for ; Thu, 8 Sep 2022 19:52:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.403574.645717 (Exim 4.92) (envelope-from ) id 1oWNYx-0005yh-Ih; Thu, 08 Sep 2022 19:51:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 403574.645717; Thu, 08 Sep 2022 19:51:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oWNYx-0005ya-G0; Thu, 08 Sep 2022 19:51:47 +0000 Received: by outflank-mailman (input) for mailman id 403574; Thu, 08 Sep 2022 19:51:46 +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 1oWNYw-0005iM-QY for xen-devel@lists.xenproject.org; Thu, 08 Sep 2022 19:51:46 +0000 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [2607:f8b0:4864:20::731]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id aafc992a-2faf-11ed-a31c-8f8a9ae3403f; Thu, 08 Sep 2022 21:51:46 +0200 (CEST) Received: by mail-qk1-x731.google.com with SMTP id b2so13748179qkh.12 for ; Thu, 08 Sep 2022 12:51:45 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id bp33-20020a05620a45a100b006b8e049cf08sm17095814qkb.2.2022.09.08.12.51.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Sep 2022 12:51:43 -0700 (PDT) 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: aafc992a-2faf-11ed-a31c-8f8a9ae3403f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=0c9AKXalp2sKJ7cfJ+vPBAUxcJIApFm3DGF7p3Liepw=; b=NmcUFcM+lVkVNUbqSzGu6sFBj8Aqd7hR7bofQeP9Ij67wwU6oR8m8t6MAAh2Wi146y bJPfHVAH3QxkK9XKl3NERqQCa3GjxsAl+lijaROmdO4H7+Ei+1iBM6vsROt0BL0WRtXQ AIRfsHPinOB5EsQroBIPJ01/Bf6Oi3hWEXqimrJgXx6ymF0s0+Bdgym2+wAzRsxZ98B2 HoyQhP9B2OkmKGh/PP+LGoBukh95uTo6OjyVAvwPP4x9VAs5beROKOZKdYsdt4sDM8An LbFLzARycUrsV/YWStpeZbIwFBlDg7cpBRY5eE3rvzE1HfxCmAHyN6tRywhCEzmxEtLJ Rwiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=0c9AKXalp2sKJ7cfJ+vPBAUxcJIApFm3DGF7p3Liepw=; b=TLYGJ96p1CrMlmaR1Kd28UasElX+Bzjoa3pK+l5EGbLH8SgguxvxgfG8O3Isa6b+ZK OAkkVjNkgWpdVN1tGx+PTWjJU54/mj2a8HLUFE1PEuNLGKKJ8H9myXemApyCeRDasgSW RRkv23uoHywpfUTiVOYmrtOcZO06mh8X4JFu+CUDNPu17muRTa8rebqCvkdIl0LpvSa9 t5bWlBp4FCOnuullgC+hXe0vnVXsjVEFTb4moqIcSIfvJf4Pb3ogtWo4RhyS9Xcl6KoI DcuVD5B73XoXVQ1SNA8gQv/BXh8AJzM37m1s23rHG383gaYsur5/caWsFuwFqNWuF63W Jk8A== X-Gm-Message-State: ACgBeo16u+cY+nNkzqZqVLArF2a9WsLCpFEbjgBKqsCIn/W4aMPJOnnB oTfQygU32MJRgs7a32+tpUEb4Gulmhk= X-Google-Smtp-Source: AA6agR6SpiKWtaXs0OLwuOa+Jy7q2Kcg3zyzl/nufIOhOBz8EMcZ4AM/eL8t77DDPGMHDGgtBe6sPA== X-Received: by 2002:a37:91c3:0:b0:6bc:5322:d49e with SMTP id t186-20020a3791c3000000b006bc5322d49emr7781474qkd.583.1662666704527; Thu, 08 Sep 2022 12:51:44 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , George Dunlap , Nick Rosbrook , Wei Liu , Anthony PERARD Subject: [PATCH v2 1/3] golang/xenlight: Extend KeyedUnion to support Arrays Date: Thu, 8 Sep 2022 15:51:11 -0400 Message-Id: <20220908195113.218201-2-jandryuk@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220908195113.218201-1-jandryuk@gmail.com> References: <20220908195113.218201-1-jandryuk@gmail.com> MIME-Version: 1.0 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/gengotypes.py index ac1cf060dd..745a3cb466 100644 --- a/tools/golang/xenlight/gengotypes.py +++ b/tools/golang/xenlight/gengotypes.py @@ -374,6 +374,10 @@ def xenlight_golang_union_from_C(ty = None, union_name = '', struct_name = ''): s += 'tmp := (*C.{0})(unsafe.Pointer(&xc.{1}[0]))\n'.format(typename,union_name) for nf in f.type.fields: + if isinstance(nf.type, idl.Array): + s += xenlight_golang_array_from_C(nf,cvarname='tmp') + continue + s += xenlight_golang_convert_from_C(nf,cvarname='tmp') s += 'return nil\n' @@ -414,7 +418,7 @@ def xenlight_golang_union_from_C(ty = None, union_name = '', struct_name = ''): return (s,extras) -def xenlight_golang_array_from_C(ty = None): +def xenlight_golang_array_from_C(ty = None, cvarname = 'xc'): """ Convert C array to Go slice using the method described here: @@ -431,9 +435,9 @@ def xenlight_golang_array_from_C(ty = None): clenvar = ty.type.lenvar.name s += 'x.{0} = nil\n'.format(goname) - s += 'if n := int(xc.{0}); n > 0 {{\n'.format(clenvar) + s += 'if n := int({0}.{1}); n > 0 {{\n'.format(cvarname,clenvar) s += '{0} := '.format(cslice) - s +='(*[1<<28]C.{0})(unsafe.Pointer(xc.{1}))[:n:n]\n'.format(ctypename, cname) + s +='(*[1<<28]C.{0})(unsafe.Pointer({1}.{2}))[:n:n]\n'.format(ctypename, cvarname, cname) s += 'x.{0} = make([]{1}, n)\n'.format(goname, gotypename) s += 'for i, v := range {0} {{\n'.format(cslice) @@ -577,6 +581,11 @@ def xenlight_golang_union_to_C(ty = None, union_name = '', s += 'var {0} C.{1}\n'.format(f.name,cgotype) for uf in f.type.fields: + if isinstance(uf.type, idl.Array): + s += xenlight_golang_array_to_C(uf, cvarname=f.name, + govarname="tmp") + continue + s += xenlight_golang_convert_to_C(uf,cvarname=f.name, govarname='tmp') @@ -594,7 +603,7 @@ def xenlight_golang_union_to_C(ty = None, union_name = '', return s -def xenlight_golang_array_to_C(ty = None): +def xenlight_golang_array_to_C(ty = None, cvarname="xc", govarname="x"): s = '' gotypename = xenlight_golang_fmt_name(ty.type.elem_type.typename) @@ -606,27 +615,27 @@ def xenlight_golang_array_to_C(ty = None): is_enum = isinstance(ty.type.elem_type,idl.Enumeration) if gotypename in go_builtin_types or is_enum: - s += 'if {0} := len(x.{1}); {2} > 0 {{\n'.format(golenvar,goname,golenvar) - s += 'xc.{0} = (*C.{1})(C.malloc(C.size_t({2}*{3})))\n'.format(cname,ctypename, + s += 'if {0} := len({1}.{2}); {3} > 0 {{\n'.format(golenvar,govarname,goname,golenvar) + s += '{0}.{1} = (*C.{2})(C.malloc(C.size_t({3}*{4})))\n'.format(cvarname,cname,ctypename, golenvar,golenvar) - s += 'xc.{0} = C.int({1})\n'.format(clenvar,golenvar) - s += 'c{0} := (*[1<<28]C.{1})(unsafe.Pointer(xc.{2}))[:{3}:{4}]\n'.format(goname, - ctypename,cname, + s += '{0}.{1} = C.int({2})\n'.format(cvarname,clenvar,golenvar) + s += 'c{0} := (*[1<<28]C.{1})(unsafe.Pointer({2}.{3}))[:{4}:{5}]\n'.format(goname, + ctypename,cvarname,cname, golenvar,golenvar) - s += 'for i,v := range x.{0} {{\n'.format(goname) + s += 'for i,v := range {0}.{1} {{\n'.format(govarname,goname) s += 'c{0}[i] = C.{1}(v)\n'.format(goname,ctypename) s += '}\n}\n' return s - s += 'if {0} := len(x.{1}); {2} > 0 {{\n'.format(golenvar,goname,golenvar) - s += 'xc.{0} = (*C.{1})(C.malloc(C.ulong({2})*C.sizeof_{3}))\n'.format(cname,ctypename, + s += 'if {0} := len({1}.{2}); {3} > 0 {{\n'.format(golenvar,govarname,goname,golenvar) + s += '{0}.{1} = (*C.{2})(C.malloc(C.ulong({3})*C.sizeof_{4}))\n'.format(cvarname,cname,ctypename, golenvar,ctypename) - s += 'xc.{0} = C.int({1})\n'.format(clenvar,golenvar) - s += 'c{0} := (*[1<<28]C.{1})(unsafe.Pointer(xc.{2}))[:{3}:{4}]\n'.format(goname, - ctypename,cname, + s += '{0}.{1} = C.int({2})\n'.format(cvarname,clenvar,golenvar) + s += 'c{0} := (*[1<<28]C.{1})(unsafe.Pointer({2}.{3}))[:{4}:{5}]\n'.format(goname, + ctypename,cvarname,cname, golenvar,golenvar) - s += 'for i,v := range x.{0} {{\n'.format(goname) + s += 'for i,v := range {0}.{1} {{\n'.format(govarname,goname) s += 'if err := v.toC(&c{0}[i]); err != nil {{\n'.format(goname) s += 'return fmt.Errorf("converting field {0}: %v", err)\n'.format(goname) s += '}\n}\n}\n'