xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Nick Rosbrook <rosbrookn@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: Wei Liu <wl@xen.org>,
	paul@xen.org, andrew.cooper3@citrix.com,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	George Dunlap <george.dunlap@citrix.com>,
	Nick Rosbrook <rosbrookn@ainfosec.com>
Subject: [PATCH for-4.14] golang/xenlight: sort cases in switch statement
Date: Mon, 15 Jun 2020 11:39:42 -0400	[thread overview]
Message-ID: <42ba06bc716cf91d25c8bb1d988cb1310219b8fe.1592234663.git.rosbrookn@ainfosec.com> (raw)

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



             reply	other threads:[~2020-06-15 15:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-15 15:39 Nick Rosbrook [this message]
2020-06-15 15:43 ` [PATCH for-4.14] golang/xenlight: sort cases in switch statement Ian Jackson
2020-06-15 16:00   ` Paul Durrant
2020-06-15 16:02   ` George Dunlap

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42ba06bc716cf91d25c8bb1d988cb1310219b8fe.1592234663.git.rosbrookn@ainfosec.com \
    --to=rosbrookn@gmail.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=paul@xen.org \
    --cc=rosbrookn@ainfosec.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).