Skip to content

Commit

Permalink
Fix atomicwrapper Swap panic
Browse files Browse the repository at this point in the history
  • Loading branch information
eNV25 committed Feb 4, 2023
1 parent 78a3b8e commit 18c2311
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bool.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @generated Code generated by gen-atomicwrapper.

// Copyright (c) 2020-2022 Uber Technologies, Inc.
// Copyright (c) 2020-2023 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion duration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @generated Code generated by gen-atomicwrapper.

// Copyright (c) 2020-2022 Uber Technologies, Inc.
// Copyright (c) 2020-2023 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @generated Code generated by gen-atomicwrapper.

// Copyright (c) 2020-2022 Uber Technologies, Inc.
// Copyright (c) 2020-2023 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion float32.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @generated Code generated by gen-atomicwrapper.

// Copyright (c) 2020-2022 Uber Technologies, Inc.
// Copyright (c) 2020-2023 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion float64.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @generated Code generated by gen-atomicwrapper.

// Copyright (c) 2020-2022 Uber Technologies, Inc.
// Copyright (c) 2020-2023 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion int32.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @generated Code generated by gen-atomicint.

// Copyright (c) 2020-2022 Uber Technologies, Inc.
// Copyright (c) 2020-2023 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion int64.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @generated Code generated by gen-atomicint.

// Copyright (c) 2020-2022 Uber Technologies, Inc.
// Copyright (c) 2020-2023 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 4 additions & 1 deletion internal/gen-atomicwrapper/wrapper.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ func (x *{{ .Name }}) Store(val {{ .Type }}) {
{{ if .Pack -}}
return {{ .Unpack }}(x.v.Swap({{ .Pack }}(val)))
{{- else -}}{{- /* assume go.uber.org/atomic.Value */ -}}
return x.v.Swap(val).({{ .Type }})
if v := x.v.Swap(val); v != nil {
return v.({{ .Type }})
}
return _zero{{ .Name }}
{{- end }}
}
{{- end }}
Expand Down
7 changes: 5 additions & 2 deletions string.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @generated Code generated by gen-atomicwrapper.

// Copyright (c) 2020-2022 Uber Technologies, Inc.
// Copyright (c) 2020-2023 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -61,5 +61,8 @@ func (x *String) CompareAndSwap(old, new string) (swapped bool) {
// Swap atomically stores the given string and returns the old
// value.
func (x *String) Swap(val string) (old string) {
return x.v.Swap(val).(string)
if v := x.v.Swap(val); v != nil {
return v.(string)
}
return _zeroString
}
2 changes: 1 addition & 1 deletion time.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @generated Code generated by gen-atomicwrapper.

// Copyright (c) 2020-2022 Uber Technologies, Inc.
// Copyright (c) 2020-2023 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion uint32.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @generated Code generated by gen-atomicint.

// Copyright (c) 2020-2022 Uber Technologies, Inc.
// Copyright (c) 2020-2023 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion uint64.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @generated Code generated by gen-atomicint.

// Copyright (c) 2020-2022 Uber Technologies, Inc.
// Copyright (c) 2020-2023 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion uintptr.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @generated Code generated by gen-atomicint.

// Copyright (c) 2020-2022 Uber Technologies, Inc.
// Copyright (c) 2020-2023 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down

0 comments on commit 18c2311

Please sign in to comment.