]> xenbits.xensource.com Git - people/jgross/xen.git/commitdiff
golang/xenlight: sort cases in switch statement
authorNick Rosbrook <rosbrookn@gmail.com>
Mon, 15 Jun 2020 15:39:42 +0000 (11:39 -0400)
committerGeorge Dunlap <george.dunlap@citrix.com>
Mon, 15 Jun 2020 15:47:59 +0000 (16:47 +0100)
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>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: George Dunlap <george.dunlap@citrix.com>
Release-acked-by: Paul Durrant <paul@xen.org>
tools/golang/xenlight/gengotypes.py
tools/golang/xenlight/helpers.gen.go

index ecca59745f0f6e9695b6e8fa2911303fd5ff485d..557fecd07bbf570b377b9ef8ccaa17c0a1791298 100644 (file)
@@ -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)
index 935d3bc50ac6bb649d4a427f67ba679dd7a3b392..152c7e8e6b2a3bc939f4f5be5fde59dcb3baaebc 100644 (file)
@@ -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)}