From nobody Thu May 2 02:49:10 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=fail; 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=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1595289325; cv=none; d=zohomail.com; s=zohoarc; b=duAyxV5yhrbkh9Ojktx7tJqIHqB5SuVnzBf+TF06mUS8F2G58zKEQ0sysHdYc+e1lkzUL/1mELw1LswHk1ANn8kWHc3rbi1xc8JCvwOYeA7zVz/Q3BcUUnLaLpzHNdN8gB8PRwdziMCyN31BzETFgtQuhRK43iptbiJQMrgs20w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595289325; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=/CbiZ46/++SBcFpdRzL/hrVcnPlp8s/fVui4csswoP4=; b=PYa1LjS0zR76wXSOaJj9qal8uCv5sKuN9oBAyg+hXQUD5PNBDH8FmnKfFsI7OXXWyCS4hW5JhrDaIKjnGSUF0kU9Tk7cHBSDIIsVN1IaGekuW/Zz4UqA/CBMTpPMazJ81AONNLnK6t6cwSbDiUch79Bc7dOFxvsSUkPFEVAnnKs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1595289325400310.0311804085493; Mon, 20 Jul 2020 16:55:25 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jxfcT-0006El-Af; Mon, 20 Jul 2020 23:54:53 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jxfcS-0006Eg-2K for xen-devel@lists.xenproject.org; Mon, 20 Jul 2020 23:54:52 +0000 Received: from mail-io1-xd36.google.com (unknown [2607:f8b0:4864:20::d36]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 65f0f2c0-cae4-11ea-84d4-bc764e2007e4; Mon, 20 Jul 2020 23:54:50 +0000 (UTC) Received: by mail-io1-xd36.google.com with SMTP id z6so1994597iow.6 for ; Mon, 20 Jul 2020 16:54:50 -0700 (PDT) Received: from six.lan (cpe-67-241-56-252.twcny.res.rr.com. [67.241.56.252]) by smtp.gmail.com with ESMTPSA id i11sm10084948iow.19.2020.07.20.16.54.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2020 16:54:47 -0700 (PDT) X-Inumbo-ID: 65f0f2c0-cae4-11ea-84d4-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=/CbiZ46/++SBcFpdRzL/hrVcnPlp8s/fVui4csswoP4=; b=KCMFMr2IyoE+HRFXUxk0XNCr32Vg01XC2mfUZBwpEswMJ/FNODe65pU7IMsUfEIBuQ AsA548XQ6pJcEzEHqrb/1UdOnKfKzbrlxuzG5H8mMUikd9tR3gJlSIz6LG3ujjJyHxyo 7mvsLdy3u6CI+LdRsh84ktcF9sc8aCz5YaWBZOFe4kM4wo39JIYhm85Q9P4ZWEUZmE4D evxvovw3F16Xnp+qh7wA5n2/DIwoSuEW/wt23S1BmbXPVDimErhB2PRYX0UW9DkntK0y v6F38ksrZY0CD8KQ0/7y5Peju9jzsIc9ui8JCPqWEq3CMZsA4NVXFwiee69XxRXnZ6Id FCoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/CbiZ46/++SBcFpdRzL/hrVcnPlp8s/fVui4csswoP4=; b=qm+T3+CuV6OqK0iHsQSPu2jR8Gkorrq73svmaU4hjPLeInv+W28Ekl7eDQYQS/eaI7 rRnzkgNZ5U9woCGpI+Gsq4E8ov3AnG6RDaExGT+Gv8awYYXcnAXKMsriqfJxRHPrKjCH EO0bU96vRCej+BMDUgtZcAvUFlpacXrXg+s5ynHe8nIMOBTh5ewyc/iMIxtsjrlBx2Kj pkP9MNDU7HzIX+DJqaMyF0NbEXmRToTQZihyD2kugJsjqcvCh3uLCNMrrJU6lhyoRU8/ hPd2aIgBQHPwj2isRe1vbgHszwsKzy72aeCjBNqNh/Dhk77ZEqippz87B2E0UBUu5ZtT V7zw== X-Gm-Message-State: AOAM531d9unaAq7kBae+0iCselLmplVnYLzf2PTS4cZidqLvD2hxyAaT +tX7Pm2CnBO+9qI2d5UoxxQKyRkrFjQ= X-Google-Smtp-Source: ABdhPJxx/0aqbTpb9YkrNYwJ4r6ZFV7jR7uR0NR/5Hzg9z6CNHx8vuocDNePjGMtrzZa5+jHkDX0wA== X-Received: by 2002:a02:b714:: with SMTP id g20mr28564006jam.117.1595289288344; Mon, 20 Jul 2020 16:54:48 -0700 (PDT) From: Nick Rosbrook X-Google-Original-From: Nick Rosbrook To: xen-devel@lists.xenproject.org Subject: [PATCH for-4.14] golang/xenlight: fix code generation for python 2.6 Date: Mon, 20 Jul 2020 19:54:40 -0400 Message-Id: X-Mailer: git-send-email 2.17.1 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Nick Rosbrook , Ian Jackson , George Dunlap , Wei Liu , paul@xen.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Before python 2.7, str.format() calls required that the format fields were explicitly enumerated, e.g.: '{0} {1}'.format(foo, bar) vs. '{} {}'.format(foo, bar) Currently, gengotypes.py uses the latter pattern everywhere, which means the Go bindings do not build on python 2.6. Use the 2.6 syntax for format() in order to support python 2.6 for now. Signed-off-by: Nick Rosbrook --- tools/golang/xenlight/gengotypes.py | 204 ++++++++++++++-------------- 1 file changed, 102 insertions(+), 102 deletions(-) diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/ge= ngotypes.py index 557fecd07b..ebec938224 100644 --- a/tools/golang/xenlight/gengotypes.py +++ b/tools/golang/xenlight/gengotypes.py @@ -3,7 +3,7 @@ import os import sys =20 -sys.path.append('{}/tools/libxl'.format(os.environ['XEN_ROOT'])) +sys.path.append('{0}/tools/libxl'.format(os.environ['XEN_ROOT'])) import idl =20 # Go versions of some builtin types. @@ -73,14 +73,14 @@ def xenlight_golang_define_enum(ty =3D None): =20 if ty.typename is not None: typename =3D xenlight_golang_fmt_name(ty.typename) - s +=3D 'type {} int\n'.format(typename) + s +=3D 'type {0} int\n'.format(typename) =20 # Start const block s +=3D 'const(\n' =20 for v in ty.values: name =3D xenlight_golang_fmt_name(v.name) - s +=3D '{} {} =3D {}\n'.format(name, typename, v.value) + s +=3D '{0} {1} =3D {2}\n'.format(name, typename, v.value) =20 # End const block s +=3D ')\n' @@ -99,9 +99,9 @@ def xenlight_golang_define_struct(ty =3D None, typename = =3D None, nested =3D False): =20 # Begin struct definition if nested: - s +=3D '{} struct {{\n'.format(name) + s +=3D '{0} struct {{\n'.format(name) else: - s +=3D 'type {} struct {{\n'.format(name) + s +=3D 'type {0} struct {{\n'.format(name) =20 # Write struct fields for f in ty.fields: @@ -111,13 +111,13 @@ def xenlight_golang_define_struct(ty =3D None, typena= me =3D None, nested =3D False): typename =3D xenlight_golang_fmt_name(typename) name =3D xenlight_golang_fmt_name(f.name) =20 - s +=3D '{} []{}\n'.format(name, typename) + s +=3D '{0} []{1}\n'.format(name, typename) else: typename =3D f.type.typename typename =3D xenlight_golang_fmt_name(typename) name =3D xenlight_golang_fmt_name(f.name) =20 - s +=3D '{} {}\n'.format(name, typename) + s +=3D '{0} {1}\n'.format(name, typename) =20 elif isinstance(f.type, idl.Struct): r =3D xenlight_golang_define_struct(f.type, typename=3Df.name,= nested=3DTrue) @@ -132,7 +132,7 @@ def xenlight_golang_define_struct(ty =3D None, typename= =3D None, nested =3D False): extras.extend(r[1]) =20 else: - raise Exception('type {} not supported'.format(f.type)) + raise Exception('type {0} not supported'.format(f.type)) =20 # End struct definition s +=3D '}\n' @@ -151,11 +151,11 @@ def xenlight_golang_define_union(ty =3D None, struct_= name =3D '', union_name =3D ''): s =3D '' extras =3D [] =20 - interface_name =3D '{}_{}_union'.format(struct_name, ty.keyvar.name) + interface_name =3D '{0}_{1}_union'.format(struct_name, ty.keyvar.name) interface_name =3D xenlight_golang_fmt_name(interface_name, exported= =3DFalse) =20 - s +=3D 'type {} interface {{\n'.format(interface_name) - s +=3D 'is{}()\n'.format(interface_name) + s +=3D 'type {0} interface {{\n'.format(interface_name) + s +=3D 'is{0}()\n'.format(interface_name) s +=3D '}\n' =20 extras.append(s) @@ -165,7 +165,7 @@ def xenlight_golang_define_union(ty =3D None, struct_na= me =3D '', union_name =3D ''): continue =20 # Define struct - name =3D '{}_{}_union_{}'.format(struct_name, ty.keyvar.name, f.na= me) + name =3D '{0}_{1}_union_{2}'.format(struct_name, ty.keyvar.name, f= .name) r =3D xenlight_golang_define_struct(f.type, typename=3Dname) extras.append(r[0]) extras.extend(r[1]) @@ -173,21 +173,21 @@ def xenlight_golang_define_union(ty =3D None, struct_= name =3D '', union_name =3D ''): # This typeof trick ensures that the fields used in the cgo struct # used for marshaling are the same as the fields of the union in t= he # actual C type, and avoids re-defining all of those fields. - s =3D 'typedef typeof(((struct {} *)NULL)->{}.{}){};' + s =3D 'typedef typeof(((struct {0} *)NULL)->{1}.{2}){3};' s =3D s.format(struct_name, union_name, f.name, name) cgo_helpers_preamble.append(s) =20 # Define function to implement 'union' interface name =3D xenlight_golang_fmt_name(name) - s =3D 'func (x {}) is{}(){{}}\n'.format(name, interface_name) + s =3D 'func (x {0}) is{1}(){{}}\n'.format(name, interface_name) extras.append(s) =20 fname =3D xenlight_golang_fmt_name(ty.keyvar.name) ftype =3D xenlight_golang_fmt_name(ty.keyvar.type.typename) - s =3D '{} {}\n'.format(fname, ftype) + s =3D '{0} {1}\n'.format(fname, ftype) =20 - fname =3D xenlight_golang_fmt_name('{}_union'.format(ty.keyvar.name)) - s +=3D '{} {}\n'.format(fname, interface_name) + fname =3D xenlight_golang_fmt_name('{0}_union'.format(ty.keyvar.name)) + s +=3D '{0} {1}\n'.format(fname, interface_name) =20 return (s,extras) =20 @@ -243,7 +243,7 @@ def xenlight_golang_define_from_C(ty =3D None): Define the fromC marshaling function for the type represented by ty. """ - func =3D 'func (x *{}) fromC(xc *C.{}) error {{\n {}\n return nil}}\n' + func =3D 'func (x *{0}) fromC(xc *C.{1}) error {{\n {2}\n return nil}}= \n' =20 goname =3D xenlight_golang_fmt_name(ty.typename) cname =3D ty.typename @@ -271,7 +271,7 @@ def xenlight_golang_define_from_C(ty =3D None): extras.extend(r[1]) =20 else: - raise Exception('type {} not supported'.format(f.type)) + raise Exception('type {0} not supported'.format(f.type)) =20 return (func.format(goname, cname, body), extras) =20 @@ -300,8 +300,8 @@ def xenlight_golang_convert_from_C(ty =3D None, outer_n= ame =3D None, cvarname =3D None =20 # If outer_name is set, treat this as nested. if outer_name is not None: - goname =3D '{}.{}'.format(xenlight_golang_fmt_name(outer_name), go= name) - cname =3D '{}.{}'.format(outer_name, cname) + goname =3D '{0}.{1}'.format(xenlight_golang_fmt_name(outer_name), = goname) + cname =3D '{0}.{1}'.format(outer_name, cname) =20 # Types that satisfy this condition can be easily casted or # converted to a Go builtin type. @@ -312,15 +312,15 @@ def xenlight_golang_convert_from_C(ty =3D None, outer= _name =3D None, cvarname =3D None if not is_castable: # If the type is not castable, we need to call its fromC # function. - s +=3D 'if err :=3D x.{}.fromC(&{}.{});'.format(goname,cvarname,cn= ame) - s +=3D 'err !=3D nil {{\nreturn fmt.Errorf("converting field {}: %= v", err)\n}}\n'.format(goname) + s +=3D 'if err :=3D x.{0}.fromC(&{1}.{2});'.format(goname,cvarname= ,cname) + s +=3D 'err !=3D nil {{\nreturn fmt.Errorf("converting field {0}: = %v", err)\n}}\n'.format(goname) =20 elif gotypename =3D=3D 'string': # Use the cgo helper for converting C strings. - s +=3D 'x.{} =3D C.GoString({}.{})\n'.format(goname,cvarname,cname) + s +=3D 'x.{0} =3D C.GoString({1}.{2})\n'.format(goname,cvarname,cn= ame) =20 else: - s +=3D 'x.{} =3D {}({}.{})\n'.format(goname,gotypename,cvarname,cn= ame) + s +=3D 'x.{0} =3D {1}({2}.{3})\n'.format(goname,gotypename,cvarnam= e,cname) =20 return s =20 @@ -331,9 +331,9 @@ def xenlight_golang_union_from_C(ty =3D None, union_nam= e =3D '', struct_name =3D ''): gokeyname =3D xenlight_golang_fmt_name(keyname) keytype =3D ty.keyvar.type.typename gokeytype =3D xenlight_golang_fmt_name(keytype) - field_name =3D xenlight_golang_fmt_name('{}_union'.format(keyname)) + field_name =3D xenlight_golang_fmt_name('{0}_union'.format(keyname)) =20 - interface_name =3D '{}_{}_union'.format(struct_name, keyname) + interface_name =3D '{0}_{1}_union'.format(struct_name, keyname) interface_name =3D xenlight_golang_fmt_name(interface_name, exported= =3DFalse) =20 cgo_keyname =3D keyname @@ -343,7 +343,7 @@ def xenlight_golang_union_from_C(ty =3D None, union_nam= e =3D '', struct_name =3D ''): cases =3D {} =20 for f in ty.fields: - val =3D '{}_{}'.format(keytype, f.name) + val =3D '{0}_{1}'.format(keytype, f.name) val =3D xenlight_golang_fmt_name(val) =20 # Add to list of cases to make for the switch @@ -354,17 +354,17 @@ def xenlight_golang_union_from_C(ty =3D None, union_n= ame =3D '', struct_name =3D ''): continue =20 # Define fromC func for 'union' struct. - typename =3D '{}_{}_union_{}'.format(struct_name,keyname,f.name) + typename =3D '{0}_{1}_union_{2}'.format(struct_name,keyname,f.na= me) gotypename =3D xenlight_golang_fmt_name(typename) =20 # Define the function here. The cases for keyed unions are a little # different. - s =3D 'func (x *{}) fromC(xc *C.{}) error {{\n'.format(gotypename,= struct_name) - s +=3D 'if {}(xc.{}) !=3D {} {{\n'.format(gokeytype,cgo_keyname,va= l) - err_string =3D '"expected union key {}"'.format(val) - s +=3D 'return errors.New({})\n'.format(err_string) + s =3D 'func (x *{0}) fromC(xc *C.{1}) error {{\n'.format(gotypenam= e,struct_name) + s +=3D 'if {0}(xc.{1}) !=3D {2} {{\n'.format(gokeytype,cgo_keyname= ,val) + err_string =3D '"expected union key {0}"'.format(val) + s +=3D 'return errors.New({0})\n'.format(err_string) s +=3D '}\n\n' - s +=3D 'tmp :=3D (*C.{})(unsafe.Pointer(&xc.{}[0]))\n'.format(type= name,union_name) + s +=3D 'tmp :=3D (*C.{0})(unsafe.Pointer(&xc.{1}[0]))\n'.format(ty= pename,union_name) =20 for nf in f.type.fields: s +=3D xenlight_golang_convert_from_C(nf,cvarname=3D'tmp') @@ -374,35 +374,35 @@ def xenlight_golang_union_from_C(ty =3D None, union_n= ame =3D '', struct_name =3D ''): =20 extras.append(s) =20 - s =3D 'x.{} =3D {}(xc.{})\n'.format(gokeyname,gokeytype,cgo_keyname) - s +=3D 'switch x.{}{{\n'.format(gokeyname) + s =3D 'x.{0} =3D {1}(xc.{2})\n'.format(gokeyname,gokeytype,cgo_keyname) + s +=3D 'switch x.{0}{{\n'.format(gokeyname) =20 # Create switch statement to determine which 'union element' # to populate in the Go struct. for case_name, case_tuple in sorted(cases.items()): (case_val, case_type) =3D case_tuple =20 - s +=3D 'case {}:\n'.format(case_val) + s +=3D 'case {0}:\n'.format(case_val) =20 if case_type is None: - s +=3D "x.{} =3D nil\n".format(field_name) + s +=3D "x.{0} =3D nil\n".format(field_name) continue =20 - gotype =3D '{}_{}_union_{}'.format(struct_name,keyname,case_name) + gotype =3D '{0}_{1}_union_{2}'.format(struct_name,keyname,case_nam= e) gotype =3D xenlight_golang_fmt_name(gotype) - goname =3D '{}_{}'.format(keyname,case_name) + goname =3D '{0}_{1}'.format(keyname,case_name) goname =3D xenlight_golang_fmt_name(goname,exported=3DFalse) =20 - s +=3D 'var {} {}\n'.format(goname, gotype) - s +=3D 'if err :=3D {}.fromC(xc);'.format(goname) - s +=3D 'err !=3D nil {{\n return fmt.Errorf("converting field {}: = %v", err)\n}}\n'.format(goname) + s +=3D 'var {0} {1}\n'.format(goname, gotype) + s +=3D 'if err :=3D {0}.fromC(xc);'.format(goname) + s +=3D 'err !=3D nil {{\n return fmt.Errorf("converting field {0}:= %v", err)\n}}\n'.format(goname) =20 - s +=3D 'x.{} =3D {}\n'.format(field_name, goname) + s +=3D 'x.{0} =3D {1}\n'.format(field_name, goname) =20 # End switch statement s +=3D 'default:\n' - err_string =3D '"invalid union key \'%v\'", x.{}'.format(gokeyname) - s +=3D 'return fmt.Errorf({})'.format(err_string) + err_string =3D '"invalid union key \'%v\'", x.{0}'.format(gokeyname) + s +=3D 'return fmt.Errorf({0})'.format(err_string) s +=3D '}\n' =20 return (s,extras) @@ -420,22 +420,22 @@ def xenlight_golang_array_from_C(ty =3D None): goname =3D xenlight_golang_fmt_name(ty.name) ctypename =3D ty.type.elem_type.typename cname =3D ty.name - cslice =3D 'c{}'.format(goname) + cslice =3D 'c{0}'.format(goname) clenvar =3D ty.type.lenvar.name =20 - s +=3D 'x.{} =3D nil\n'.format(goname) - s +=3D 'if n :=3D int(xc.{}); n > 0 {{\n'.format(clenvar) - s +=3D '{} :=3D '.format(cslice) - s +=3D'(*[1<<28]C.{})(unsafe.Pointer(xc.{}))[:n:n]\n'.format(ctypename= , cname) - s +=3D 'x.{} =3D make([]{}, n)\n'.format(goname, gotypename) - s +=3D 'for i, v :=3D range {} {{\n'.format(cslice) + s +=3D 'x.{0} =3D nil\n'.format(goname) + s +=3D 'if n :=3D int(xc.{0}); n > 0 {{\n'.format(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 'x.{0} =3D make([]{1}, n)\n'.format(goname, gotypename) + s +=3D 'for i, v :=3D range {0} {{\n'.format(cslice) =20 is_enum =3D isinstance(ty.type.elem_type,idl.Enumeration) if gotypename in go_builtin_types or is_enum: - s +=3D 'x.{}[i] =3D {}(v)\n'.format(goname, gotypename) + s +=3D 'x.{0}[i] =3D {1}(v)\n'.format(goname, gotypename) else: - s +=3D 'if err :=3D x.{}[i].fromC(&v); err !=3D nil {{\n'.format(g= oname) - s +=3D 'return fmt.Errorf("converting field {}: %v", err) }}\n'.fo= rmat(goname) + s +=3D 'if err :=3D x.{0}[i].fromC(&v); err !=3D nil {{\n'.format(= goname) + s +=3D 'return fmt.Errorf("converting field {0}: %v", err) }}\n'.f= ormat(goname) =20 s +=3D '}\n}\n' =20 @@ -446,11 +446,11 @@ def xenlight_golang_define_to_C(ty =3D None, typename= =3D None, nested =3D False): Define the toC marshaling function for the type represented by ty. """ - func =3D 'func (x *{}) toC(xc *C.{}) (err error){{{}\n return nil\n }}= \n' + func =3D 'func (x *{0}) toC(xc *C.{1}) (err error){{{2}\n return nil\n= }}\n' body =3D '' =20 if ty.dispose_fn is not None: - body +=3D 'defer func(){{\nif err !=3D nil{{\nC.{}(xc)}}\n}}()\n\n= '.format(ty.dispose_fn) + body +=3D 'defer func(){{\nif err !=3D nil{{\nC.{0}(xc)}}\n}}()\n\= n'.format(ty.dispose_fn) =20 goname =3D xenlight_golang_fmt_name(ty.typename) cname =3D ty.typename @@ -471,7 +471,7 @@ def xenlight_golang_define_to_C(ty =3D None, typename = =3D None, nested =3D False): body +=3D xenlight_golang_union_to_C(f.type, f.name, ty.typena= me) =20 else: - raise Exception('type {} not supported'.format(f.type)) + raise Exception('type {0} not supported'.format(f.type)) =20 return func.format(goname, cname, body) =20 @@ -506,26 +506,26 @@ def xenlight_golang_convert_to_C(ty =3D None, outer_n= ame =3D None, =20 # If outer_name is set, treat this as nested. if outer_name is not None: - goname =3D '{}.{}'.format(xenlight_golang_fmt_name(outer_name), go= name) - cname =3D '{}.{}'.format(outer_name, cname) + goname =3D '{0}.{1}'.format(xenlight_golang_fmt_name(outer_name), = goname) + cname =3D '{0}.{1}'.format(outer_name, cname) =20 is_castable =3D (ty.type.json_parse_type =3D=3D 'JSON_INTEGER' or isinstance(ty.type, idl.Enumeration) or gotypename in go_builtin_types) =20 if not is_castable: - s +=3D 'if err :=3D {}.{}.toC(&{}.{}); err !=3D nil {{\n'.format(g= ovarname,goname, + s +=3D 'if err :=3D {0}.{1}.toC(&{2}.{3}); err !=3D nil {{\n'.form= at(govarname,goname, cvarnam= e,cname) - s +=3D 'return fmt.Errorf("converting field {}: %v", err)\n}}\n'.f= ormat(goname) + s +=3D 'return fmt.Errorf("converting field {0}: %v", err)\n}}\n'.= format(goname) =20 elif gotypename =3D=3D 'string': # Use the cgo helper for converting C strings. - s +=3D 'if {}.{} !=3D "" {{\n'.format(govarname,goname) - s +=3D '{}.{} =3D C.CString({}.{})}}\n'.format(cvarname,cname, + s +=3D 'if {0}.{1} !=3D "" {{\n'.format(govarname,goname) + s +=3D '{0}.{1} =3D C.CString({2}.{3})}}\n'.format(cvarname,cname, govarname,goname) =20 else: - s +=3D '{}.{} =3D C.{}({}.{})\n'.format(cvarname,cname,ctypename, + s +=3D '{0}.{1} =3D C.{2}({3}.{4})\n'.format(cvarname,cname,ctypen= ame, govarname,goname) =20 return s @@ -537,7 +537,7 @@ def xenlight_golang_union_to_C(ty =3D None, union_name = =3D '', keytype =3D ty.keyvar.type.typename gokeytype =3D xenlight_golang_fmt_name(keytype) =20 - interface_name =3D '{}_{}_union'.format(struct_name, keyname) + interface_name =3D '{0}_{1}_union'.format(struct_name, keyname) interface_name =3D xenlight_golang_fmt_name(interface_name, exported= =3DFalse) =20 cgo_keyname =3D keyname @@ -545,44 +545,44 @@ def xenlight_golang_union_to_C(ty =3D None, union_nam= e =3D '', cgo_keyname =3D '_' + cgo_keyname =20 =20 - s =3D 'xc.{} =3D C.{}(x.{})\n'.format(cgo_keyname,keytype,gokeyname) - s +=3D 'switch x.{}{{\n'.format(gokeyname) + s =3D 'xc.{0} =3D C.{1}(x.{2})\n'.format(cgo_keyname,keytype,gokeyname) + s +=3D 'switch x.{0}{{\n'.format(gokeyname) =20 # Create switch statement to determine how to populate the C union. for f in ty.fields: - key_val =3D '{}_{}'.format(keytype, f.name) + key_val =3D '{0}_{1}'.format(keytype, f.name) key_val =3D xenlight_golang_fmt_name(key_val) =20 - s +=3D 'case {}:\n'.format(key_val) + s +=3D 'case {0}:\n'.format(key_val) =20 if f.type is None: s +=3D "break\n" continue =20 - cgotype =3D '{}_{}_union_{}'.format(struct_name,keyname,f.name) + cgotype =3D '{0}_{1}_union_{2}'.format(struct_name,keyname,f.name) gotype =3D xenlight_golang_fmt_name(cgotype) =20 - field_name =3D xenlight_golang_fmt_name('{}_union'.format(keyname)) - s +=3D 'tmp, ok :=3D x.{}.({})\n'.format(field_name,gotype) + field_name =3D xenlight_golang_fmt_name('{0}_union'.format(keyname= )) + s +=3D 'tmp, ok :=3D x.{0}.({1})\n'.format(field_name,gotype) s +=3D 'if !ok {\n' - s +=3D 'return errors.New("wrong type for union key {}")\n'.format= (keyname) + s +=3D 'return errors.New("wrong type for union key {0}")\n'.forma= t(keyname) s +=3D '}\n' =20 - s +=3D 'var {} C.{}\n'.format(f.name,cgotype) + s +=3D 'var {0} C.{1}\n'.format(f.name,cgotype) for uf in f.type.fields: s +=3D xenlight_golang_convert_to_C(uf,cvarname=3Df.name, govarname=3D'tmp') =20 # The union is still represented as Go []byte. - s +=3D '{}Bytes :=3D C.GoBytes(unsafe.Pointer(&{}),C.sizeof_{})\n'= .format(f.name, + s +=3D '{0}Bytes :=3D C.GoBytes(unsafe.Pointer(&{1}),C.sizeof_{2})= \n'.format(f.name, = f.name, = cgotype) - s +=3D 'copy(xc.{}[:],{}Bytes)\n'.format(union_name,f.name) + s +=3D 'copy(xc.{0}[:],{1}Bytes)\n'.format(union_name,f.name) =20 # End switch statement s +=3D 'default:\n' - err_string =3D '"invalid union key \'%v\'", x.{}'.format(gokeyname) - s +=3D 'return fmt.Errorf({})'.format(err_string) + err_string =3D '"invalid union key \'%v\'", x.{0}'.format(gokeyname) + s +=3D 'return fmt.Errorf({0})'.format(err_string) s +=3D '}\n' =20 return s @@ -599,29 +599,29 @@ 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 {} :=3D len(x.{}); {} > 0 {{\n'.format(golenvar,goname,= golenvar) - s +=3D 'xc.{} =3D (*C.{})(C.malloc(C.size_t({}*{})))\n'.format(cna= me,ctypename, + 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, golenva= r,golenvar) - s +=3D 'xc.{} =3D C.int({})\n'.format(clenvar,golenvar) - s +=3D 'c{} :=3D (*[1<<28]C.{})(unsafe.Pointer(xc.{}))[:{}:{}]\n'.= format(goname, + 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, gole= nvar,golenvar) - s +=3D 'for i,v :=3D range x.{} {{\n'.format(goname) - s +=3D 'c{}[i] =3D C.{}(v)\n'.format(goname,ctypename) + s +=3D 'for i,v :=3D range x.{0} {{\n'.format(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 {} :=3D len(x.{}); {} > 0 {{\n'.format(golenvar,goname,gole= nvar) - s +=3D 'xc.{} =3D (*C.{})(C.malloc(C.ulong({})*C.sizeof_{}))\n'.format= (cname,ctypename, + 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, golenva= r,ctypename) - s +=3D 'xc.{} =3D C.int({})\n'.format(clenvar,golenvar) - s +=3D 'c{} :=3D (*[1<<28]C.{})(unsafe.Pointer(xc.{}))[:{}:{}]\n'.form= at(goname, + 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, g= olenvar,golenvar) - s +=3D 'for i,v :=3D range x.{} {{\n'.format(goname) - s +=3D 'if err :=3D v.toC(&c{}[i]); err !=3D nil {{\n'.format(goname) - s +=3D 'return fmt.Errorf("converting field {}: %v", err)\n'.format(go= name) + s +=3D 'for i,v :=3D range x.{0} {{\n'.format(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 return s @@ -633,7 +633,7 @@ def xenlight_golang_define_constructor(ty =3D None): gotypename =3D xenlight_golang_fmt_name(ctypename) =20 # Since this func is exported, add a comment as per Go conventions. - s +=3D '// New{} returns an instance of {}'.format(gotypename,gotypena= me) + s +=3D '// New{0} returns an instance of {1}'.format(gotypename,gotype= name) s +=3D ' initialized with defaults.\n' =20 # If a struct has a keyed union, an extra argument is @@ -643,7 +643,7 @@ def xenlight_golang_define_constructor(ty =3D None): init_fns =3D [] =20 # Add call to parent init_fn first. - init_fns.append('C.{}(&xc)'.format(ty.init_fn)) + init_fns.append('C.{0}(&xc)'.format(ty.init_fn)) =20 for f in ty.fields: if not isinstance(f.type, idl.KeyedUnion): @@ -658,24 +658,24 @@ def xenlight_golang_define_constructor(ty =3D None): # Serveral keyed unions use 'type' as the key variable name. In # that case, prepend the first letter of the Go type name. if param_goname =3D=3D 'type': - param_goname =3D '{}type'.format(param_gotype.lower()[0]) + param_goname =3D '{0}type'.format(param_gotype.lower()[0]) =20 # Add call to keyed union's init_fn. - init_fns.append('C.{}_{}(&xc, C.{}({}))'.format(ty.init_fn, + init_fns.append('C.{0}_{1}(&xc, C.{2}({3}))'.format(ty.init_fn, param.name, param_ctype, param_goname)) =20 # Add to params list. - params.append('{} {}'.format(param_goname, param_gotype)) + params.append('{0} {1}'.format(param_goname, param_gotype)) =20 # Define function - s +=3D 'func New{}({}) (*{}, error) {{\n'.format(gotypename, + s +=3D 'func New{0}({1}) (*{2}, error) {{\n'.format(gotypename, ','.join(params), gotypename) =20 # Declare variables. - s +=3D 'var (\nx {}\nxc C.{})\n\n'.format(gotypename, ctypename) + s +=3D 'var (\nx {0}\nxc C.{1})\n\n'.format(gotypename, ctypename) =20 # Write init_fn calls. s +=3D '\n'.join(init_fns) @@ -684,7 +684,7 @@ def xenlight_golang_define_constructor(ty =3D None): # Make sure dispose_fn get's called when constructor # returns. if ty.dispose_fn is not None: - s +=3D 'defer C.{}(&xc)\n'.format(ty.dispose_fn) + s +=3D 'defer C.{0}(&xc)\n'.format(ty.dispose_fn) =20 s +=3D '\n' =20 @@ -727,7 +727,7 @@ if __name__ =3D=3D '__main__': header_comment=3D"""// DO NOT EDIT. // // This file is generated by: -// {} +// {0} // =20 """.format(' '.join(sys.argv)) --=20 2.17.1