Skip to content

Instantly share code, notes, and snippets.

@dholm
Created April 16, 2018 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dholm/66d5c60014cfc43d527bfc5904648733 to your computer and use it in GitHub Desktop.
Save dholm/66d5c60014cfc43d527bfc5904648733 to your computer and use it in GitHub Desktop.
Bug in greenpack generator
package gpbug
type I64 uint64
type Str1 string
type Struct1 struct {
I I64 // `zid:"0"`
S Str1 // `zid:"1"`
}
type Struct2 struct {
S Struct1
}
--- greenpack-bug_gen.go.1 2018-04-16 16:27:45.681013175 +0200
+++ greenpack-bug_gen.go 2018-04-16 16:27:45.693013210 +0200
@@ -278,7 +278,7 @@
return 1
}
var fieldsInUse uint32 = 1
- isempty[0] = false // struct values are never empty
+ isempty[0] = false
if isempty[0] {
fieldsInUse--
}
@@ -302,24 +302,10 @@
if !empty[0] {
// string "S"
o = append(o, 0xa1, 0x53)
-
- // honor the omitempty tags
- var empty [2]bool
- fieldsInUse := z.S.fieldsNotEmpty(empty[:])
- o = msgp.AppendMapHeader(o, fieldsInUse)
-
- if !empty[0] {
- // string "I"
- o = append(o, 0xa1, 0x49)
- o = msgp.AppendUint64(o, uint64(z.S.I))
- }
-
- if !empty[1] {
- // string "S"
- o = append(o, 0xa1, 0x53)
- o = msgp.AppendString(o, string(z.S.S))
+ o, err = z.S.MarshalMsg(o) // not is.iface, gen/marshal.go:243
+ if err != nil {
+ return
}
-
}
return
@@ -392,89 +378,10 @@
case "S":
found6zgensym_1452b2c984fe1b1a_7[0] = true
- const maxFields8zgensym_1452b2c984fe1b1a_9 = 2
-
- // -- templateUnmarshalMsg starts here--
- var totalEncodedFields8zgensym_1452b2c984fe1b1a_9 uint32
- if !nbs.AlwaysNil {
- totalEncodedFields8zgensym_1452b2c984fe1b1a_9, bts, err = nbs.ReadMapHeaderBytes(bts)
- if err != nil {
- return
- }
- }
- encodedFieldsLeft8zgensym_1452b2c984fe1b1a_9 := totalEncodedFields8zgensym_1452b2c984fe1b1a_9
- missingFieldsLeft8zgensym_1452b2c984fe1b1a_9 := maxFields8zgensym_1452b2c984fe1b1a_9 - totalEncodedFields8zgensym_1452b2c984fe1b1a_9
-
- var nextMiss8zgensym_1452b2c984fe1b1a_9 int32 = -1
- var found8zgensym_1452b2c984fe1b1a_9 [maxFields8zgensym_1452b2c984fe1b1a_9]bool
- var curField8zgensym_1452b2c984fe1b1a_9 string
-
- doneWithStruct8zgensym_1452b2c984fe1b1a_9:
- // First fill all the encoded fields, then
- // treat the remaining, missing fields, as Nil.
- for encodedFieldsLeft8zgensym_1452b2c984fe1b1a_9 > 0 || missingFieldsLeft8zgensym_1452b2c984fe1b1a_9 > 0 {
- //fmt.Printf("encodedFieldsLeft: %v, missingFieldsLeft: %v, found: '%v', fields: '%#v'\n", encodedFieldsLeft8zgensym_1452b2c984fe1b1a_9, missingFieldsLeft8zgensym_1452b2c984fe1b1a_9, msgp.ShowFound(found8zgensym_1452b2c984fe1b1a_9[:]), unmarshalMsgFieldOrder8zgensym_1452b2c984fe1b1a_9)
- if encodedFieldsLeft8zgensym_1452b2c984fe1b1a_9 > 0 {
- encodedFieldsLeft8zgensym_1452b2c984fe1b1a_9--
- field, bts, err = nbs.ReadMapKeyZC(bts)
- if err != nil {
- return
- }
- curField8zgensym_1452b2c984fe1b1a_9 = msgp.UnsafeString(field)
- } else {
- //missing fields need handling
- if nextMiss8zgensym_1452b2c984fe1b1a_9 < 0 {
- // set bts to contain just mnil (0xc0)
- bts = nbs.PushAlwaysNil(bts)
- nextMiss8zgensym_1452b2c984fe1b1a_9 = 0
- }
- for nextMiss8zgensym_1452b2c984fe1b1a_9 < maxFields8zgensym_1452b2c984fe1b1a_9 && (found8zgensym_1452b2c984fe1b1a_9[nextMiss8zgensym_1452b2c984fe1b1a_9] || unmarshalMsgFieldSkip8zgensym_1452b2c984fe1b1a_9[nextMiss8zgensym_1452b2c984fe1b1a_9]) {
- nextMiss8zgensym_1452b2c984fe1b1a_9++
- }
- if nextMiss8zgensym_1452b2c984fe1b1a_9 == maxFields8zgensym_1452b2c984fe1b1a_9 {
- // filled all the empty fields!
- break doneWithStruct8zgensym_1452b2c984fe1b1a_9
- }
- missingFieldsLeft8zgensym_1452b2c984fe1b1a_9--
- curField8zgensym_1452b2c984fe1b1a_9 = unmarshalMsgFieldOrder8zgensym_1452b2c984fe1b1a_9[nextMiss8zgensym_1452b2c984fe1b1a_9]
- }
- //fmt.Printf("switching on curField: '%v'\n", curField8zgensym_1452b2c984fe1b1a_9)
- switch curField8zgensym_1452b2c984fe1b1a_9 {
- // -- templateUnmarshalMsg ends here --
-
- case "I":
- found8zgensym_1452b2c984fe1b1a_9[0] = true
- {
- var zgensym_1452b2c984fe1b1a_10 uint64
- zgensym_1452b2c984fe1b1a_10, bts, err = nbs.ReadUint64Bytes(bts)
-
- if err != nil {
- return
- }
- z.S.I = I64(zgensym_1452b2c984fe1b1a_10)
- }
- case "S":
- found8zgensym_1452b2c984fe1b1a_9[1] = true
- {
- var zgensym_1452b2c984fe1b1a_11 string
- zgensym_1452b2c984fe1b1a_11, bts, err = nbs.ReadStringBytes(bts)
-
- if err != nil {
- return
- }
- z.S.S = Str1(zgensym_1452b2c984fe1b1a_11)
- }
- default:
- bts, err = msgp.Skip(bts)
- if err != nil {
- return
- }
- }
- }
- if nextMiss8zgensym_1452b2c984fe1b1a_9 != -1 {
- bts = nbs.PopAlwaysNil()
+ bts, err = z.S.UnmarshalMsg(bts)
+ if err != nil {
+ return
}
-
default:
bts, err = msgp.Skip(bts)
if err != nil {
@@ -502,13 +409,8 @@
var unmarshalMsgFieldSkip6zgensym_1452b2c984fe1b1a_7 = []bool{false}
-// fields of Struct1
-var unmarshalMsgFieldOrder8zgensym_1452b2c984fe1b1a_9 = []string{"I", "S"}
-
-var unmarshalMsgFieldSkip8zgensym_1452b2c984fe1b1a_9 = []bool{false, false}
-
// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (z *Struct2) Msgsize() (s int) {
- s = 1 + 2 + 1 + 2 + msgp.Uint64Size + 2 + msgp.StringPrefixSize + len(string(z.S.S))
+ s = 1 + 2 + z.S.Msgsize()
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment