tools/golang/xenlight/gengotypes.py | 2 +- tools/golang/xenlight/helpers.gen.go | 32 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 17 deletions(-)
The xenlight_golang_union_from_C function iterates over a dict to
construct a switch statement that marshals a C keyed union into a Go
type. Because python does not guarantee dict ordering across all
versions, this can result in the switch statement being generated in a
different order depending on the version of python used. For example,
running gengotypes.py with python2.7 and python3.6 will yield different
orderings.
Iterate over sorted(cases.items()) rather than cases.items() to fix
this.
This patch changes the ordering from what was previously checked-in, but
running gengotypes.py with different versions of python will now yield
the same result.
Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com>
---
Andrew reported this in [1], so I intend this as a build fix for 4.14.
[1] https://lists.xenproject.org/archives/html/xen-devel/2020-06/msg00881.html
---
tools/golang/xenlight/gengotypes.py | 2 +-
tools/golang/xenlight/helpers.gen.go | 32 ++++++++++++++--------------
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/gengotypes.py
index ecca59745f..557fecd07b 100644
--- a/tools/golang/xenlight/gengotypes.py
+++ b/tools/golang/xenlight/gengotypes.py
@@ -379,7 +379,7 @@ def xenlight_golang_union_from_C(ty = None, union_name = '', struct_name = ''):
# Create switch statement to determine which 'union element'
# to populate in the Go struct.
- for case_name, case_tuple in cases.items():
+ for case_name, case_tuple in sorted(cases.items()):
(case_val, case_type) = case_tuple
s += 'case {}:\n'.format(case_val)
diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/helpers.gen.go
index 935d3bc50a..152c7e8e6b 100644
--- a/tools/golang/xenlight/helpers.gen.go
+++ b/tools/golang/xenlight/helpers.gen.go
@@ -431,8 +431,6 @@ x.Evtch = int(xc.evtch)
x.Rref = int(xc.rref)
x.Connection = ChannelConnection(xc.connection)
switch x.Connection{
-case ChannelConnectionUnknown:
-x.ConnectionUnion = nil
case ChannelConnectionPty:
var connectionPty ChannelinfoConnectionUnionPty
if err := connectionPty.fromC(xc);err != nil {
@@ -441,6 +439,8 @@ if err := connectionPty.fromC(xc);err != nil {
x.ConnectionUnion = connectionPty
case ChannelConnectionSocket:
x.ConnectionUnion = nil
+case ChannelConnectionUnknown:
+x.ConnectionUnion = nil
default:
return fmt.Errorf("invalid union key '%v'", x.Connection)}
@@ -1098,6 +1098,8 @@ if err := typeHvm.fromC(xc);err != nil {
return fmt.Errorf("converting field typeHvm: %v", err)
}
x.TypeUnion = typeHvm
+case DomainTypeInvalid:
+x.TypeUnion = nil
case DomainTypePv:
var typePv DomainBuildInfoTypeUnionPv
if err := typePv.fromC(xc);err != nil {
@@ -1110,8 +1112,6 @@ if err := typePvh.fromC(xc);err != nil {
return fmt.Errorf("converting field typePvh: %v", err)
}
x.TypeUnion = typePvh
-case DomainTypeInvalid:
-x.TypeUnion = nil
default:
return fmt.Errorf("invalid union key '%v'", x.Type)}
x.ArchArm.GicVersion = GicVersion(xc.arch_arm.gic_version)
@@ -2360,8 +2360,6 @@ x.Devid = Devid(xc.devid)
x.Name = C.GoString(xc.name)
x.Connection = ChannelConnection(xc.connection)
switch x.Connection{
-case ChannelConnectionUnknown:
-x.ConnectionUnion = nil
case ChannelConnectionPty:
x.ConnectionUnion = nil
case ChannelConnectionSocket:
@@ -2370,6 +2368,8 @@ if err := connectionSocket.fromC(xc);err != nil {
return fmt.Errorf("converting field connectionSocket: %v", err)
}
x.ConnectionUnion = connectionSocket
+case ChannelConnectionUnknown:
+x.ConnectionUnion = nil
default:
return fmt.Errorf("invalid union key '%v'", x.Connection)}
@@ -3933,28 +3933,28 @@ return fmt.Errorf("converting field Domuuid: %v", err)
x.ForUser = uint64(xc.for_user)
x.Type = EventType(xc._type)
switch x.Type{
-case EventTypeDomainShutdown:
-var typeDomainShutdown EventTypeUnionDomainShutdown
-if err := typeDomainShutdown.fromC(xc);err != nil {
- return fmt.Errorf("converting field typeDomainShutdown: %v", err)
-}
-x.TypeUnion = typeDomainShutdown
-case EventTypeDomainDeath:
-x.TypeUnion = nil
case EventTypeDiskEject:
var typeDiskEject EventTypeUnionDiskEject
if err := typeDiskEject.fromC(xc);err != nil {
return fmt.Errorf("converting field typeDiskEject: %v", err)
}
x.TypeUnion = typeDiskEject
+case EventTypeDomainCreateConsoleAvailable:
+x.TypeUnion = nil
+case EventTypeDomainDeath:
+x.TypeUnion = nil
+case EventTypeDomainShutdown:
+var typeDomainShutdown EventTypeUnionDomainShutdown
+if err := typeDomainShutdown.fromC(xc);err != nil {
+ return fmt.Errorf("converting field typeDomainShutdown: %v", err)
+}
+x.TypeUnion = typeDomainShutdown
case EventTypeOperationComplete:
var typeOperationComplete EventTypeUnionOperationComplete
if err := typeOperationComplete.fromC(xc);err != nil {
return fmt.Errorf("converting field typeOperationComplete: %v", err)
}
x.TypeUnion = typeOperationComplete
-case EventTypeDomainCreateConsoleAvailable:
-x.TypeUnion = nil
default:
return fmt.Errorf("invalid union key '%v'", x.Type)}
--
2.17.1
Nick Rosbrook writes ("[PATCH for-4.14] golang/xenlight: sort cases in switch statement"): > The xenlight_golang_union_from_C function iterates over a dict to > construct a switch statement that marshals a C keyed union into a Go > type. Because python does not guarantee dict ordering across all > versions, this can result in the switch statement being generated in a > different order depending on the version of python used. For example, > running gengotypes.py with python2.7 and python3.6 will yield different > orderings. > > Iterate over sorted(cases.items()) rather than cases.items() to fix > this. > > This patch changes the ordering from what was previously checked-in, but > running gengotypes.py with different versions of python will now yield > the same result. > > Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com> > --- > Andrew reported this in [1], so I intend this as a build fix for 4.14. > > [1] https://lists.xenproject.org/archives/html/xen-devel/2020-06/msg00881.html > --- > tools/golang/xenlight/gengotypes.py | 2 +- > tools/golang/xenlight/helpers.gen.go | 32 ++++++++++++++-------------- > 2 files changed, 17 insertions(+), 17 deletions(-) > > diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/gengotypes.py > index ecca59745f..557fecd07b 100644 > --- a/tools/golang/xenlight/gengotypes.py > +++ b/tools/golang/xenlight/gengotypes.py > @@ -379,7 +379,7 @@ def xenlight_golang_union_from_C(ty = None, union_name = '', struct_name = ''): > > # Create switch statement to determine which 'union element' > # to populate in the Go struct. > - for case_name, case_tuple in cases.items(): > + for case_name, case_tuple in sorted(cases.items()): > (case_val, case_type) = case_tuple This part Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> But I don't think I have the right golang tools to verify the autogenerated code. George, can you check that this patch is right, and/or do the commit and rerun the generation ? Obviously that needs to wait for a release ack. Ian.
> On Jun 15, 2020, at 4:43 PM, Ian Jackson <ian.jackson@citrix.com> wrote: > > Nick Rosbrook writes ("[PATCH for-4.14] golang/xenlight: sort cases in switch statement"): >> The xenlight_golang_union_from_C function iterates over a dict to >> construct a switch statement that marshals a C keyed union into a Go >> type. Because python does not guarantee dict ordering across all >> versions, this can result in the switch statement being generated in a >> different order depending on the version of python used. For example, >> running gengotypes.py with python2.7 and python3.6 will yield different >> orderings. >> >> Iterate over sorted(cases.items()) rather than cases.items() to fix >> this. >> >> This patch changes the ordering from what was previously checked-in, but >> running gengotypes.py with different versions of python will now yield >> the same result. >> >> Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com> >> --- >> Andrew reported this in [1], so I intend this as a build fix for 4.14. >> >> [1] https://lists.xenproject.org/archives/html/xen-devel/2020-06/msg00881.html >> --- >> tools/golang/xenlight/gengotypes.py | 2 +- >> tools/golang/xenlight/helpers.gen.go | 32 ++++++++++++++-------------- >> 2 files changed, 17 insertions(+), 17 deletions(-) >> >> diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/gengotypes.py >> index ecca59745f..557fecd07b 100644 >> --- a/tools/golang/xenlight/gengotypes.py >> +++ b/tools/golang/xenlight/gengotypes.py >> @@ -379,7 +379,7 @@ def xenlight_golang_union_from_C(ty = None, union_name = '', struct_name = ''): >> >> # Create switch statement to determine which 'union element' >> # to populate in the Go struct. >> - for case_name, case_tuple in cases.items(): >> + for case_name, case_tuple in sorted(cases.items()): >> (case_val, case_type) = case_tuple > > This part > > Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> > > But I don't think I have the right golang tools to verify the > autogenerated code. George, can you check that this patch is right, > and/or do the commit and rerun the generation ? I can confirm that 1) rerunning this doesn’t cause any changes 2) the resulting code compiles. Acked-by: George Dunlap <george.dunlap@citrix.com> Since I’ve got it in my tree I’ll push it.
> -----Original Message----- > From: Ian Jackson <ian.jackson@citrix.com> > Sent: 15 June 2020 16:43 > To: Nick Rosbrook <rosbrookn@gmail.com> > Cc: xen-devel@lists.xenproject.org; paul@xen.org; Andrew Cooper <Andrew.Cooper3@citrix.com>; Nick > Rosbrook <rosbrookn@ainfosec.com>; George Dunlap <George.Dunlap@citrix.com>; Wei Liu <wl@xen.org> > Subject: Re: [PATCH for-4.14] golang/xenlight: sort cases in switch statement > > Nick Rosbrook writes ("[PATCH for-4.14] golang/xenlight: sort cases in switch statement"): > > The xenlight_golang_union_from_C function iterates over a dict to > > construct a switch statement that marshals a C keyed union into a Go > > type. Because python does not guarantee dict ordering across all > > versions, this can result in the switch statement being generated in a > > different order depending on the version of python used. For example, > > running gengotypes.py with python2.7 and python3.6 will yield different > > orderings. > > > > Iterate over sorted(cases.items()) rather than cases.items() to fix > > this. > > > > This patch changes the ordering from what was previously checked-in, but > > running gengotypes.py with different versions of python will now yield > > the same result. > > > > Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com> > > --- > > Andrew reported this in [1], so I intend this as a build fix for 4.14. > > > > [1] https://lists.xenproject.org/archives/html/xen-devel/2020-06/msg00881.html > > --- > > tools/golang/xenlight/gengotypes.py | 2 +- > > tools/golang/xenlight/helpers.gen.go | 32 ++++++++++++++-------------- > > 2 files changed, 17 insertions(+), 17 deletions(-) > > > > diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/gengotypes.py > > index ecca59745f..557fecd07b 100644 > > --- a/tools/golang/xenlight/gengotypes.py > > +++ b/tools/golang/xenlight/gengotypes.py > > @@ -379,7 +379,7 @@ def xenlight_golang_union_from_C(ty = None, union_name = '', struct_name = ''): > > > > # Create switch statement to determine which 'union element' > > # to populate in the Go struct. > > - for case_name, case_tuple in cases.items(): > > + for case_name, case_tuple in sorted(cases.items()): > > (case_val, case_type) = case_tuple > > This part > > Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> > > But I don't think I have the right golang tools to verify the > autogenerated code. George, can you check that this patch is right, > and/or do the commit and rerun the generation ? > > Obviously that needs to wait for a release ack. > Assuming George is happy... Release-acked-by: Paul Durrant <paul@xen.org> > Ian.
© 2016 - 2024 Red Hat, Inc.