mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Revert "Ensure empty serialized slices are zero-length, not null"
This commit is contained in:
parent
5f805a5e66
commit
1bb19dfcc5
@ -29,8 +29,6 @@ import (
|
|||||||
"k8s.io/gengo/namer"
|
"k8s.io/gengo/namer"
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -792,15 +790,6 @@ func (g *genConversion) doStruct(inType, outType *types.Type, sw *generator.Snip
|
|||||||
outMemberType = &copied
|
outMemberType = &copied
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine if our destination field is a slice that should be output when empty.
|
|
||||||
// If it is, ensure a nil source slice converts to a zero-length destination slice.
|
|
||||||
// See http://issue.k8s.io/43203
|
|
||||||
persistEmptySlice := false
|
|
||||||
if outMemberType.Kind == types.Slice {
|
|
||||||
jsonTag := reflect.StructTag(outMember.Tags).Get("json")
|
|
||||||
persistEmptySlice = len(jsonTag) > 0 && !strings.Contains(jsonTag, ",omitempty")
|
|
||||||
}
|
|
||||||
|
|
||||||
args := argsFromType(inMemberType, outMemberType).With("name", inMember.Name)
|
args := argsFromType(inMemberType, outMemberType).With("name", inMember.Name)
|
||||||
|
|
||||||
// try a direct memory copy for any type that has exactly equivalent values
|
// try a direct memory copy for any type that has exactly equivalent values
|
||||||
@ -816,15 +805,7 @@ func (g *genConversion) doStruct(inType, outType *types.Type, sw *generator.Snip
|
|||||||
sw.Do("out.$.name$ = *(*$.outType|raw$)($.Pointer|raw$(&in.$.name$))\n", args)
|
sw.Do("out.$.name$ = *(*$.outType|raw$)($.Pointer|raw$(&in.$.name$))\n", args)
|
||||||
continue
|
continue
|
||||||
case types.Slice:
|
case types.Slice:
|
||||||
if persistEmptySlice {
|
|
||||||
sw.Do("if in.$.name$ == nil {\n", args)
|
|
||||||
sw.Do("out.$.name$ = make($.outType|raw$, 0)\n", args)
|
|
||||||
sw.Do("} else {\n", nil)
|
|
||||||
sw.Do("out.$.name$ = *(*$.outType|raw$)($.Pointer|raw$(&in.$.name$))\n", args)
|
sw.Do("out.$.name$ = *(*$.outType|raw$)($.Pointer|raw$(&in.$.name$))\n", args)
|
||||||
sw.Do("}\n", nil)
|
|
||||||
} else {
|
|
||||||
sw.Do("out.$.name$ = *(*$.outType|raw$)($.Pointer|raw$(&in.$.name$))\n", args)
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -874,11 +855,7 @@ func (g *genConversion) doStruct(inType, outType *types.Type, sw *generator.Snip
|
|||||||
sw.Do("in, out := &in.$.name$, &out.$.name$\n", args)
|
sw.Do("in, out := &in.$.name$, &out.$.name$\n", args)
|
||||||
g.generateFor(inMemberType, outMemberType, sw)
|
g.generateFor(inMemberType, outMemberType, sw)
|
||||||
sw.Do("} else {\n", nil)
|
sw.Do("} else {\n", nil)
|
||||||
if persistEmptySlice {
|
|
||||||
sw.Do("out.$.name$ = make($.outType|raw$, 0)\n", args)
|
|
||||||
} else {
|
|
||||||
sw.Do("out.$.name$ = nil\n", args)
|
sw.Do("out.$.name$ = nil\n", args)
|
||||||
}
|
|
||||||
sw.Do("}\n", nil)
|
sw.Do("}\n", nil)
|
||||||
case types.Struct:
|
case types.Struct:
|
||||||
if g.isDirectlyAssignable(inMemberType, outMemberType) {
|
if g.isDirectlyAssignable(inMemberType, outMemberType) {
|
||||||
|
Loading…
Reference in New Issue
Block a user