[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen staging] golang/xenlight: sort cases in switch statement
commit 1251402caf8685f45d9d580f01583370f7e2d272 Author: Nick Rosbrook <rosbrookn@xxxxxxxxx> AuthorDate: Mon Jun 15 11:39:42 2020 -0400 Commit: George Dunlap <george.dunlap@xxxxxxxxxx> CommitDate: Mon Jun 15 16:47:59 2020 +0100 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@xxxxxxxxxxxx> Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Acked-by: George Dunlap <george.dunlap@xxxxxxxxxx> Release-acked-by: Paul Durrant <paul@xxxxxxx> --- 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)} -- generated by git-patchbot for /home/xen/git/xen.git#staging
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |