Skip to content

Commit ab5758d

Browse files
committed
Reset to v1.1.55
1 parent 6d7fe40 commit ab5758d

File tree

8 files changed

+32
-251
lines changed

8 files changed

+32
-251
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ jobs:
1010
- uses: actions/checkout@v3.5.3
1111
- uses: actions/setup-go@v4.0.1
1212
with:
13-
go-version: '1.20.6'
13+
go-version: '1.20.5'
1414
- run: make test

gen/elem.go

-24
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ func (c *common) SetVarname(s string) { c.vname = s }
165165
func (c *common) Varname() string { return c.vname }
166166
func (c *common) Alias(typ string) { c.alias = typ }
167167
func (c *common) SortInterface() string { return "" }
168-
func (c *common) LessFunction() string { return "" }
169168
func (c *common) SetAllocBound(s string) { c.allocbound = s }
170169
func (c *common) AllocBound() string { return c.allocbound }
171170
func (c *common) SetMaxTotalBytes(s string) { c.maxtotalbytes = s }
@@ -230,9 +229,6 @@ type Elem interface {
230229
// slice of this type.
231230
SortInterface() string
232231

233-
// LessFunction returns the Less implementation for values of this type.
234-
LessFunction() string
235-
236232
// Comparable returns whether the type is comparable, along the lines
237233
// of the Go spec (https://golang.org/ref/spec#Comparison_operators),
238234
// used to determine whether we can compare to a zero value to determine
@@ -799,8 +795,6 @@ func (s *BaseElem) BaseType() string {
799795
return "[]byte"
800796
case Time:
801797
return "time.Time"
802-
case Duration:
803-
return "time.Duration"
804798
case Ext:
805799
return "msgp.Extension"
806800

@@ -915,14 +909,6 @@ func (s *BaseElem) SortInterface() string {
915909
return ""
916910
}
917911

918-
func (s *BaseElem) LessFunction() string {
919-
lessThan, ok := lessFunctions[s.TypeName()]
920-
if ok {
921-
return lessThan
922-
}
923-
return ""
924-
}
925-
926912
func (k Primitive) String() string {
927913
switch k {
928914
case String:
@@ -1004,13 +990,3 @@ func SetSortInterface(sorttype string, sortintf string) {
1004990

1005991
sortInterface[sorttype] = sortintf
1006992
}
1007-
1008-
var lessFunctions map[string]string
1009-
1010-
func SetLessFunction(sorttype string, lessfn string) {
1011-
if lessFunctions == nil {
1012-
lessFunctions = make(map[string]string)
1013-
}
1014-
1015-
lessFunctions[sorttype] = lessfn
1016-
}

gen/maxsize.go

+20-41
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ func maxSizes(w io.Writer, topics *Topics) *maxSizeGen {
3838

3939
type maxSizeGen struct {
4040
passes
41-
p printer
42-
state maxSizeState
43-
ctx *Context
44-
topics *Topics
45-
panicked bool
41+
p printer
42+
state maxSizeState
43+
ctx *Context
44+
topics *Topics
4645
}
4746

4847
func (s *maxSizeGen) Method() Method { return MaxSize }
@@ -54,7 +53,7 @@ func (s *maxSizeGen) Apply(dirs []string) error {
5453
// this lets us chain together addition
5554
// operations where possible
5655
func (s *maxSizeGen) addConstant(sz string) {
57-
if !s.p.ok() || s.panicked {
56+
if !s.p.ok() {
5857
return
5958
}
6059

@@ -83,7 +82,6 @@ func (s *maxSizeGen) Execute(p Elem) ([]string, error) {
8382
if !s.p.ok() {
8483
return nil, s.p.err
8584
}
86-
s.panicked = false
8785
p = s.applyall(p)
8886
if p == nil {
8987
return nil, nil
@@ -111,17 +109,13 @@ func (s *maxSizeGen) Execute(p Elem) ([]string, error) {
111109
s.p.printf("\nfunc %s (s int) {", getMaxSizeMethod(p.TypeName()))
112110
s.state = assignM
113111
next(s, p)
114-
if s.panicked {
115-
s.p.print("\n}\n")
116-
} else {
117-
s.p.nakedReturn()
118-
}
112+
s.p.nakedReturn()
119113
s.topics.Add(p.TypeName(), getMaxSizeMethod(p.TypeName()))
120114
return nil, s.p.err
121115
}
122116

123117
func (s *maxSizeGen) gStruct(st *Struct) {
124-
if !s.p.ok() || s.panicked {
118+
if !s.p.ok() {
125119
return
126120
}
127121

@@ -140,7 +134,7 @@ func (s *maxSizeGen) gStruct(st *Struct) {
140134
continue
141135
}
142136

143-
if !s.p.ok() || s.panicked {
137+
if !s.p.ok() {
144138
return
145139
}
146140
next(s, st.Fields[i].FieldElem)
@@ -162,23 +156,19 @@ func (s *maxSizeGen) gStruct(st *Struct) {
162156
}
163157

164158
func (s *maxSizeGen) gPtr(p *Ptr) {
165-
if s.panicked {
166-
return
167-
}
168159
s.state = addM // inner must use add
169160
next(s, p.Value)
170161
s.state = addM // closing block; reset to add
171162
}
172163

173164
func (s *maxSizeGen) gSlice(sl *Slice) {
174-
if !s.p.ok() || s.panicked {
165+
if !s.p.ok() {
175166
return
176167
}
177168
s.state = addM
178169
s.p.comment("Calculating size of slice: " + sl.Varname())
179170
if (sl.AllocBound() == "" || sl.AllocBound() == "-") && (sl.MaxTotalBytes() == "" || sl.MaxTotalBytes() == "-") {
180171
s.p.printf("\npanic(\"Slice %s is unbounded\")", sl.Varname())
181-
s.panicked = true
182172
s.state = addM // reset the add to prevent further + expressions from being added to the end the panic statement
183173
return
184174
}
@@ -204,14 +194,13 @@ func (s *maxSizeGen) gSlice(sl *Slice) {
204194
s.addConstant(fmt.Sprintf("((%s) * (%s))", topLevelAllocBound, str))
205195
} else {
206196
s.p.printf("\npanic(\"Unable to determine max size: %s\")", err)
207-
s.panicked = true
208197
}
209198
s.state = addM
210199
return
211200
}
212201

213202
func (s *maxSizeGen) gArray(a *Array) {
214-
if !s.p.ok() || s.panicked {
203+
if !s.p.ok() {
215204
return
216205
}
217206
// If this is not the first line where we define s = ... then we need to reset the state
@@ -227,23 +216,19 @@ func (s *maxSizeGen) gArray(a *Array) {
227216
s.addConstant(fmt.Sprintf("((%s) * (%s))", a.Size, str))
228217
} else {
229218
s.p.printf("\npanic(\"Unable to determine max size: %s\")", err)
230-
s.panicked = true
219+
231220
}
232221
s.state = addM
233222
return
234223
}
235224

236225
func (s *maxSizeGen) gMap(m *Map) {
237-
if s.panicked {
238-
return
239-
}
240226
vn := m.Varname()
241227
s.state = addM
242228
s.addConstant(builtinSize(mapHeader))
243229
topLevelAllocBound := m.AllocBound()
244230
if topLevelAllocBound != "" && topLevelAllocBound == "-" {
245231
s.p.printf("\npanic(\"Map %s is unbounded\")", m.Varname())
246-
s.panicked = true
247232
s.state = addM // reset the add to prevent further + expressions from being added to the end the panic statement
248233
return
249234
}
@@ -256,25 +241,21 @@ func (s *maxSizeGen) gMap(m *Map) {
256241
}
257242
}
258243

259-
if !s.panicked {
260-
s.p.comment("Adding size of map keys for " + vn)
261-
s.p.printf("\ns += %s", topLevelAllocBound)
262-
s.state = multM
263-
next(s, m.Key)
264-
}
244+
s.p.comment("Adding size of map keys for " + vn)
245+
s.p.printf("\ns += %s", topLevelAllocBound)
246+
s.state = multM
247+
next(s, m.Key)
265248

266-
if !s.panicked {
267-
s.p.comment("Adding size of map values for " + vn)
268-
s.p.printf("\ns += %s", topLevelAllocBound)
269-
s.state = multM
270-
next(s, m.Value)
271-
}
249+
s.p.comment("Adding size of map values for " + vn)
250+
s.p.printf("\ns += %s", topLevelAllocBound)
251+
s.state = multM
252+
next(s, m.Value)
272253

273254
s.state = addM
274255
}
275256

276257
func (s *maxSizeGen) gBase(b *BaseElem) {
277-
if !s.p.ok() || s.panicked {
258+
if !s.p.ok() {
278259
return
279260
}
280261
if b.MaxTotalBytes() != "" {
@@ -295,7 +276,6 @@ func (s *maxSizeGen) gBase(b *BaseElem) {
295276
value, err := baseMaxSizeExpr(b.Value, vname, b.BaseName(), b.TypeName(), b.common.AllocBound())
296277
if err != nil {
297278
s.p.printf("\npanic(\"Unable to determine max size: %s\")", err)
298-
s.panicked = true
299279
s.state = addM // reset the add to prevent further + expressions from being added to the end the panic statement
300280
return
301281
}
@@ -310,7 +290,6 @@ func (s *maxSizeGen) gBase(b *BaseElem) {
310290
value, err := baseMaxSizeExpr(b.Value, vname, b.BaseName(), b.TypeName(), b.common.AllocBound())
311291
if err != nil {
312292
s.p.printf("\npanic(\"Unable to determine max size: %s\")", err)
313-
s.panicked = true
314293
s.state = addM // reset the add to prevent further + expressions from being added to the end the panic statement
315294
return
316295
}

gen/unmarshal.go

+1-49
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,12 @@ func (u *unmarshalGen) Execute(p Elem) ([]string, error) {
6060
u.p.printf("\n return ((*(%s))(%s)).UnmarshalMsg(bts)", baseType, c)
6161
u.p.printf("\n}")
6262

63-
u.p.printf("\nfunc (%s %s) UnmarshalValidateMsg(bts []byte) ([]byte, error) {", c, methodRecv)
64-
u.p.printf("\n return ((*(%s))(%s)).UnmarshalValidateMsg(bts)", baseType, c)
65-
u.p.printf("\n}")
66-
6763
u.p.printf("\nfunc (_ %[2]s) CanUnmarshalMsg(%[1]s interface{}) bool {", c, methodRecv)
6864
u.p.printf("\n _, ok := (%s).(%s)", c, methodRecv)
6965
u.p.printf("\n return ok")
7066
u.p.printf("\n}")
7167

7268
u.topics.Add(methodRecv, "UnmarshalMsg")
73-
u.topics.Add(methodRecv, "UnmarshalValidateMsg")
7469
u.topics.Add(methodRecv, "CanUnmarshalMsg")
7570

7671
return u.msgs, u.p.err
@@ -80,7 +75,7 @@ func (u *unmarshalGen) Execute(p Elem) ([]string, error) {
8075
c := p.Varname()
8176
methodRecv := methodReceiver(p)
8277

83-
u.p.printf("\nfunc (%s %s) unmarshalMsg(bts []byte, validate bool) (o []byte, err error) {", c, methodRecv)
78+
u.p.printf("\nfunc (%s %s) UnmarshalMsg(bts []byte) (o []byte, err error) {", c, methodRecv)
8479
next(u, p)
8580
u.p.print("\no = bts")
8681

@@ -96,21 +91,12 @@ func (u *unmarshalGen) Execute(p Elem) ([]string, error) {
9691
}
9792
u.p.nakedReturn()
9893

99-
u.p.printf("\nfunc (%s %s) UnmarshalMsg(bts []byte) (o []byte, err error) {", c, methodRecv)
100-
u.p.printf("\n return %s.unmarshalMsg(bts, false)", c)
101-
u.p.printf("\n}")
102-
103-
u.p.printf("\nfunc (%s %s) UnmarshalValidateMsg(bts []byte) (o []byte, err error) {", c, methodRecv)
104-
u.p.printf("\n return %s.unmarshalMsg(bts, true)", c)
105-
u.p.printf("\n}")
106-
10794
u.p.printf("\nfunc (_ %[2]s) CanUnmarshalMsg(%[1]s interface{}) bool {", c, methodRecv)
10895
u.p.printf("\n _, ok := (%s).(%s)", c, methodRecv)
10996
u.p.printf("\n return ok")
11097
u.p.printf("\n}")
11198

11299
u.topics.Add(methodRecv, "UnmarshalMsg")
113-
u.topics.Add(methodRecv, "UnmarshalValidateMsg")
114100
u.topics.Add(methodRecv, "CanUnmarshalMsg")
115101

116102
return u.msgs, u.p.err
@@ -158,13 +144,8 @@ func (u *unmarshalGen) mapstruct(s *Struct) {
158144
u.needsField()
159145
sz := randIdent()
160146
isnil := randIdent()
161-
last := randIdent()
162-
lastIsSet := randIdent()
163147
u.p.declare(sz, "int")
164-
u.p.declare(last, "string")
165-
u.p.declare(lastIsSet, "bool")
166148
u.p.declare(isnil, "bool")
167-
u.p.printf("\n_=%s;\n_=%s", last, lastIsSet) // we might not use these for empty structs
168149

169150
// go-codec compat: decode an array as sequential elements from this struct,
170151
// in the order they are defined in the Go type (as opposed to canonical
@@ -174,11 +155,6 @@ func (u *unmarshalGen) mapstruct(s *Struct) {
174155

175156
u.assignAndCheck(sz, isnil, arrayHeader)
176157

177-
u.p.print("\nif validate {") // map encoded as array => non canonical
178-
u.p.print("\nerr = &msgp.ErrNonCanonical{}")
179-
u.p.print("\nreturn")
180-
u.p.print("\n}")
181-
182158
u.ctx.PushString("struct-from-array")
183159
for i := range s.Fields {
184160
if !ast.IsExported(s.Fields[i].FieldName) {
@@ -219,19 +195,13 @@ func (u *unmarshalGen) mapstruct(s *Struct) {
219195
return
220196
}
221197
u.p.printf("\ncase \"%s\":", s.Fields[i].FieldTag)
222-
u.p.printf("\nif validate && %s && \"%s\" < %s {", lastIsSet, s.Fields[i].FieldTag, last)
223-
u.p.print("\nerr = &msgp.ErrNonCanonical{}")
224-
u.p.printf("\nreturn")
225-
u.p.print("\n}")
226198
u.ctx.PushString(s.Fields[i].FieldName)
227199
next(u, s.Fields[i].FieldElem)
228200
u.ctx.Pop()
229-
u.p.printf("\n%s = \"%s\"", last, s.Fields[i].FieldTag)
230201
}
231202
u.p.print("\ndefault:\nerr = msgp.ErrNoField(string(field))")
232203
u.p.wrapErrCheck(u.ctx.ArgsStr())
233204
u.p.print("\n}") // close switch
234-
u.p.printf("\n%s = true", lastIsSet)
235205
u.p.print("\n}") // close for loop
236206
u.p.print("\n}") // close else statement for array decode
237207
}
@@ -355,27 +325,9 @@ func (u *unmarshalGen) gMap(m *Map) {
355325
u.msgs = append(u.msgs, resizemsgs...)
356326

357327
// loop and get key,value
358-
last := randIdent()
359-
lastSet := randIdent()
360-
u.p.printf("\nvar %s %s; _ = %s", last, m.Key.TypeName(), last) // we might not use the sort if it's not defined
361-
u.p.declare(lastSet, "bool")
362-
u.p.printf("\n_ = %s", lastSet) // we might not use the flag
363328
u.p.printf("\nfor %s > 0 {", sz)
364329
u.p.printf("\nvar %s %s; var %s %s; %s--", m.Keyidx, m.Key.TypeName(), m.Validx, m.Value.TypeName(), sz)
365330
next(u, m.Key)
366-
u.p.printf("\nif validate {")
367-
if m.Key.LessFunction() != "" {
368-
u.p.printf("\nif %s && %s(%s, %s) {", lastSet, m.Key.LessFunction(), m.Keyidx, last)
369-
u.p.printf("\nerr = &msgp.ErrNonCanonical{}")
370-
u.p.printf("\nreturn")
371-
u.p.printf("\n}")
372-
} else {
373-
u.p.printf("\nerr = &msgp.ErrMissingLessFn{}")
374-
u.p.printf("\nreturn")
375-
}
376-
u.p.printf("\n}") // close if validate block
377-
u.p.printf("\n%s=%s", last, m.Keyidx)
378-
u.p.printf("\n%s=true", lastSet)
379331
u.ctx.PushVar(m.Keyidx)
380332
next(u, m.Value)
381333
u.ctx.Pop()

0 commit comments

Comments
 (0)