@@ -76,14 +76,20 @@ func extractExternalTypesTag(comments []string) ([]string, error) {
76
76
return extractTagValues (externalTypesTagName , comments )
77
77
}
78
78
79
- func isCopyOnly (comments []string ) bool {
80
- values , _ := extractTagValues ("k8s:conversion-fn" , comments )
81
- return len (values ) == 1 && values [0 ] == "copy-only"
79
+ func isCopyOnly (comments []string ) (bool , error ) {
80
+ values , err := extractTagValues ("k8s:conversion-fn" , comments )
81
+ if err != nil {
82
+ return false , err
83
+ }
84
+ return len (values ) == 1 && values [0 ] == "copy-only" , nil
82
85
}
83
86
84
- func isDrop (comments []string ) bool {
85
- values , _ := extractTagValues ("k8s:conversion-fn" , comments )
86
- return len (values ) == 1 && values [0 ] == "drop"
87
+ func isDrop (comments []string ) (bool , error ) {
88
+ values , err := extractTagValues ("k8s:conversion-fn" , comments )
89
+ if err != nil {
90
+ return false , err
91
+ }
92
+ return len (values ) == 1 && values [0 ] == "drop" , nil
87
93
}
88
94
89
95
// TODO: This is created only to reduce number of changes in a single PR.
@@ -360,7 +366,10 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
360
366
// If there is a manual conversion defined between two types, exclude it
361
367
// from being a candidate for unsafe conversion
362
368
for k , v := range manualConversions {
363
- if isCopyOnly (v .CommentLines ) {
369
+ copyOnly , err := isCopyOnly (v .CommentLines )
370
+ if err != nil {
371
+ klog .Errorf ("error extracting tags: %v" , err )
372
+ } else if copyOnly {
364
373
klog .V (4 ).Infof ("Conversion function %s will not block memory copy because it is copy-only" , v .Name )
365
374
continue
366
375
}
@@ -954,15 +963,23 @@ func (g *genConversion) doStruct(inType, outType *types.Type, sw *generator.Snip
954
963
955
964
// check based on the top level name, not the underlying names
956
965
if function , ok := g .preexists (inMember .Type , outMember .Type ); ok {
957
- if isDrop (function .CommentLines ) {
966
+ dropFn , err := isDrop (function .CommentLines )
967
+ if err != nil {
968
+ klog .Errorf ("Error extracting drop tag for function %s: %v" , function .Name , err )
969
+ } else if dropFn {
958
970
continue
959
971
}
960
972
// copy-only functions that are directly assignable can be inlined instead of invoked.
961
973
// As an example, conversion functions exist that allow types with private fields to be
962
974
// correctly copied between types. These functions are equivalent to a memory assignment,
963
975
// and are necessary for the reflection path, but should not block memory conversion.
964
976
// Convert_unversioned_Time_to_unversioned_Time is an example of this logic.
965
- if ! isCopyOnly (function .CommentLines ) || ! g .isFastConversion (inMemberType , outMemberType ) {
977
+ copyOnly , copyErr := isCopyOnly (function .CommentLines )
978
+ if copyErr != nil {
979
+ klog .Errorf ("Error extracting copy-only tag for function %s: %v" , function .Name , copyErr )
980
+ copyOnly = false
981
+ }
982
+ if ! copyOnly || ! g .isFastConversion (inMemberType , outMemberType ) {
966
983
args ["function" ] = function
967
984
sw .Do ("if err := $.function|raw$(&in.$.name$, &out.$.name$, s); err != nil {\n " , args )
968
985
sw .Do ("return err\n " , nil )
0 commit comments