Skip to content

Commit

Permalink
convert uses of interface{} to any
Browse files Browse the repository at this point in the history
Done via:
  find . -name "*.go" | xargs sed -i -E 's/interface\{\}/any/g'

PiperOrigin-RevId: 487033228
  • Loading branch information
kevinGC authored and gvisor-bot committed Nov 8, 2022
1 parent c82b700 commit d8aa09e
Show file tree
Hide file tree
Showing 220 changed files with 509 additions and 509 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module gvisor.dev/gvisor

go 1.17
go 1.18

require (
github.com/BurntSushi/toml v0.3.1
Expand Down
2 changes: 1 addition & 1 deletion pkg/abi/linux/netfilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

func TestSizes(t *testing.T) {
testCases := []struct {
typ interface{}
typ any
defined uintptr
}{
{IPTEntry{}, SizeOfIPTEntry},
Expand Down
6 changes: 3 additions & 3 deletions pkg/binary/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func AppendUint64(buf []byte, order binary.ByteOrder, num uint64) []byte {
// data must only contain fixed-length signed and unsigned ints, arrays,
// slices, structs and compositions of said types. data may be a pointer,
// but cannot contain pointers.
func Marshal(buf []byte, order binary.ByteOrder, data interface{}) []byte {
func Marshal(buf []byte, order binary.ByteOrder, data any) []byte {
return marshal(buf, order, reflect.Indirect(reflect.ValueOf(data)))
}

Expand Down Expand Up @@ -104,7 +104,7 @@ func marshal(buf []byte, order binary.ByteOrder, data reflect.Value) []byte {
// data must be a slice or a pointer and buf must have a length of exactly
// Size(data). data must only contain fixed-length signed and unsigned ints,
// arrays, slices, structs and compositions of said types.
func Unmarshal(buf []byte, order binary.ByteOrder, data interface{}) {
func Unmarshal(buf []byte, order binary.ByteOrder, data any) {
value := reflect.ValueOf(data)
switch value.Kind() {
case reflect.Ptr:
Expand Down Expand Up @@ -170,7 +170,7 @@ func unmarshal(buf []byte, order binary.ByteOrder, data reflect.Value) []byte {
// Size calculates the buffer sized needed by Marshal or Unmarshal.
//
// Size only support the types supported by Marshal.
func Size(v interface{}) uintptr {
func Size(v any) uintptr {
return sizeof(reflect.Indirect(reflect.ValueOf(v)))
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/binary/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ func TestSize(t *testing.T) {
func TestPanic(t *testing.T) {
tests := []struct {
name string
f func([]byte, binary.ByteOrder, interface{})
data interface{}
f func([]byte, binary.ByteOrder, any)
data any
want string
}{
{"Unmarshal int", Unmarshal, 5, "invalid type: int"},
{"Unmarshal []int", Unmarshal, []int{5}, "invalid type: int"},
{"Marshal int", func(_ []byte, bo binary.ByteOrder, d interface{}) { Marshal(nil, bo, d) }, 5, "invalid type: int"},
{"Marshal int[]", func(_ []byte, bo binary.ByteOrder, d interface{}) { Marshal(nil, bo, d) }, []int{5}, "invalid type: int"},
{"Marshal int", func(_ []byte, bo binary.ByteOrder, d any) { Marshal(nil, bo, d) }, 5, "invalid type: int"},
{"Marshal int[]", func(_ []byte, bo binary.ByteOrder, d any) { Marshal(nil, bo, d) }, []int{5}, "invalid type: int"},
{"Unmarshal short buffer", Unmarshal, newInt32(5), "runtime error: index out of range"},
{"Unmarshal long buffer", func(_ []byte, bo binary.ByteOrder, d interface{}) { Unmarshal(make([]byte, 50), bo, d) }, newInt32(5), "buffer too long by 46 bytes"},
{"marshal int", func(_ []byte, bo binary.ByteOrder, d interface{}) { marshal(nil, bo, reflect.ValueOf(d)) }, 5, "invalid type: int"},
{"Size int", func(_ []byte, _ binary.ByteOrder, d interface{}) { Size(d) }, 5, "invalid type: int"},
{"Unmarshal long buffer", func(_ []byte, bo binary.ByteOrder, d any) { Unmarshal(make([]byte, 50), bo, d) }, newInt32(5), "buffer too long by 46 bytes"},
{"marshal int", func(_ []byte, bo binary.ByteOrder, d any) { marshal(nil, bo, reflect.ValueOf(d)) }, 5, "invalid type: int"},
{"Size int", func(_ []byte, _ binary.ByteOrder, d any) { Size(d) }, 5, "invalid type: int"},
}

for _, test := range tests {
Expand Down
2 changes: 1 addition & 1 deletion pkg/bufferv2/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var chunkPools [numPools]sync.Pool
func init() {
for i := 0; i < numPools; i++ {
chunkSize := baseChunkSize * (1 << i)
chunkPools[i].New = func() interface{} {
chunkPools[i].New = func() any {
return &chunk{
data: make([]byte, chunkSize),
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/bufferv2/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
const ReadSize = 512

var viewPool = sync.Pool{
New: func() interface{} {
New: func() any {
return &View{}
},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/compressio/compressio.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ import (
)

var bufPool = sync.Pool{
New: func() interface{} {
New: func() any {
return bytes.NewBuffer(nil)
},
}

var chunkPool = sync.Pool{
New: func() interface{} {
New: func() any {
return new(chunk)
},
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/compressio/compressio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
)

type harness interface {
Errorf(format string, v ...interface{})
Fatalf(format string, v ...interface{})
Logf(format string, v ...interface{})
Errorf(format string, v ...any)
Fatalf(format string, v ...any)
Logf(format string, v ...any)
}

func initTest(t harness, size int) []byte {
Expand Down
8 changes: 4 additions & 4 deletions pkg/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func Background() Context {

// WithValue returns a copy of parent in which the value associated with key is
// val.
func WithValue(parent Context, key, val interface{}) Context {
func WithValue(parent Context, key, val any) Context {
return &withValue{
Context: parent,
key: key,
Expand All @@ -196,12 +196,12 @@ func WithValue(parent Context, key, val interface{}) Context {

type withValue struct {
Context
key interface{}
val interface{}
key any
val any
}

// Value implements Context.Value.
func (ctx *withValue) Value(key interface{}) interface{} {
func (ctx *withValue) Value(key any) any {
if key == ctx.key {
return ctx.val
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/control/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (s *Server) serve() {
}

// Register registers a specific control interface with the server.
func (s *Server) Register(obj interface{}) {
func (s *Server) Register(obj any) {
s.server.Register(obj)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/coverage/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func ClearCoverageData() {
}

var coveragePool = sync.Pool{
New: func() interface{} {
New: func() any {
return make([]byte, 0)
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cpuid/cpuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (

// context represents context.Context.
type context interface {
Value(key interface{}) interface{}
Value(key any) any
}

// FromContext returns the FeatureSet from the context, if available.
Expand Down
2 changes: 1 addition & 1 deletion pkg/lisafs/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import (
//
// String() implementations must ensure that the message struct doesn't escape.
// For instance, directly passing the struct to fmt.Sprintf() escapes it
// because of the implicit conversion to interface{}.
// because of the implicit conversion to any.

type marshalFunc func([]byte) []byte
type unmarshalFunc func([]byte) ([]byte, bool)
Expand Down
2 changes: 1 addition & 1 deletion pkg/log/glog.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var pid = os.Getpid()
// file The file name
// line The line number
// msg The user-supplied message
func (g GoogleEmitter) Emit(depth int, level Level, timestamp time.Time, format string, args ...interface{}) {
func (g GoogleEmitter) Emit(depth int, level Level, timestamp time.Time, format string, args ...any) {
// Log level.
prefix := byte('?')
switch level {
Expand Down
2 changes: 1 addition & 1 deletion pkg/log/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type JSONEmitter struct {
}

// Emit implements Emitter.Emit.
func (e JSONEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...interface{}) {
func (e JSONEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...any) {
j := jsonLog{
Msg: fmt.Sprintf(format, v...),
Level: level,
Expand Down
2 changes: 1 addition & 1 deletion pkg/log/json_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type K8sJSONEmitter struct {
}

// Emit implements Emitter.Emit.
func (e K8sJSONEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...interface{}) {
func (e K8sJSONEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...any) {
j := k8sJSONLog{
Log: fmt.Sprintf(format, v...),
Level: level,
Expand Down
46 changes: 23 additions & 23 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (l Level) String() string {
type Emitter interface {
// Emit emits the given log statement. This allows for control over the
// timestamp used for logging.
Emit(depth int, level Level, timestamp time.Time, format string, v ...interface{})
Emit(depth int, level Level, timestamp time.Time, format string, v ...any)
}

// Writer writes the output to the given writer.
Expand Down Expand Up @@ -144,23 +144,23 @@ func (l *Writer) Write(data []byte) (int, error) {
}

// Emit emits the message.
func (l *Writer) Emit(_ int, _ Level, _ time.Time, format string, args ...interface{}) {
func (l *Writer) Emit(_ int, _ Level, _ time.Time, format string, args ...any) {
fmt.Fprintf(l, format, args...)
}

// MultiEmitter is an emitter that emits to multiple Emitters.
type MultiEmitter []Emitter

// Emit emits to all emitters.
func (m *MultiEmitter) Emit(depth int, level Level, timestamp time.Time, format string, v ...interface{}) {
func (m *MultiEmitter) Emit(depth int, level Level, timestamp time.Time, format string, v ...any) {
for _, e := range *m {
e.Emit(1+depth, level, timestamp, format, v...)
}
}

// TestLogger is implemented by testing.T and testing.B.
type TestLogger interface {
Logf(format string, v ...interface{})
Logf(format string, v ...any)
}

// TestEmitter may be used for wrapping tests.
Expand All @@ -169,7 +169,7 @@ type TestEmitter struct {
}

// Emit emits to the TestLogger.
func (t *TestEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...interface{}) {
func (t *TestEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...any) {
t.Logf(format, v...)
}

Expand All @@ -179,13 +179,13 @@ func (t *TestEmitter) Emit(_ int, level Level, timestamp time.Time, format strin
// satisfies this interface, and may be passed around as a Logger.
type Logger interface {
// Debugf logs a debug statement.
Debugf(format string, v ...interface{})
Debugf(format string, v ...any)

// Infof logs at an info level.
Infof(format string, v ...interface{})
Infof(format string, v ...any)

// Warningf logs at a warning level.
Warningf(format string, v ...interface{})
Warningf(format string, v ...any)

// IsLogging returns true iff this level is being logged. This may be
// used to short-circuit expensive operations for debugging calls.
Expand All @@ -199,36 +199,36 @@ type BasicLogger struct {
}

// Debugf implements logger.Debugf.
func (l *BasicLogger) Debugf(format string, v ...interface{}) {
func (l *BasicLogger) Debugf(format string, v ...any) {
l.DebugfAtDepth(1, format, v...)
}

// Infof implements logger.Infof.
func (l *BasicLogger) Infof(format string, v ...interface{}) {
func (l *BasicLogger) Infof(format string, v ...any) {
l.InfofAtDepth(1, format, v...)
}

// Warningf implements logger.Warningf.
func (l *BasicLogger) Warningf(format string, v ...interface{}) {
func (l *BasicLogger) Warningf(format string, v ...any) {
l.WarningfAtDepth(1, format, v...)
}

// DebugfAtDepth logs at a specific depth.
func (l *BasicLogger) DebugfAtDepth(depth int, format string, v ...interface{}) {
func (l *BasicLogger) DebugfAtDepth(depth int, format string, v ...any) {
if l.IsLogging(Debug) {
l.Emit(1+depth, Debug, time.Now(), format, v...)
}
}

// InfofAtDepth logs at a specific depth.
func (l *BasicLogger) InfofAtDepth(depth int, format string, v ...interface{}) {
func (l *BasicLogger) InfofAtDepth(depth int, format string, v ...any) {
if l.IsLogging(Info) {
l.Emit(1+depth, Info, time.Now(), format, v...)
}
}

// WarningfAtDepth logs at a specific depth.
func (l *BasicLogger) WarningfAtDepth(depth int, format string, v ...interface{}) {
func (l *BasicLogger) WarningfAtDepth(depth int, format string, v ...any) {
if l.IsLogging(Warning) {
l.Emit(1+depth, Warning, time.Now(), format, v...)
}
Expand Down Expand Up @@ -275,32 +275,32 @@ func SetLevel(newLevel Level) {
}

// Debugf logs to the global logger.
func Debugf(format string, v ...interface{}) {
func Debugf(format string, v ...any) {
Log().DebugfAtDepth(1, format, v...)
}

// Infof logs to the global logger.
func Infof(format string, v ...interface{}) {
func Infof(format string, v ...any) {
Log().InfofAtDepth(1, format, v...)
}

// Warningf logs to the global logger.
func Warningf(format string, v ...interface{}) {
func Warningf(format string, v ...any) {
Log().WarningfAtDepth(1, format, v...)
}

// DebugfAtDepth logs to the global logger.
func DebugfAtDepth(depth int, format string, v ...interface{}) {
func DebugfAtDepth(depth int, format string, v ...any) {
Log().DebugfAtDepth(1+depth, format, v...)
}

// InfofAtDepth logs to the global logger.
func InfofAtDepth(depth int, format string, v ...interface{}) {
func InfofAtDepth(depth int, format string, v ...any) {
Log().InfofAtDepth(1+depth, format, v...)
}

// WarningfAtDepth logs to the global logger.
func WarningfAtDepth(depth int, format string, v ...interface{}) {
func WarningfAtDepth(depth int, format string, v ...any) {
Log().WarningfAtDepth(1+depth, format, v...)
}

Expand Down Expand Up @@ -329,15 +329,15 @@ func Stacks(all bool) []byte {
// goroutine.
//
// This will be print a traceback, tb, as Warningf(format+":\n%s", v..., tb).
func Traceback(format string, v ...interface{}) {
func Traceback(format string, v ...any) {
v = append(v, Stacks(false))
Warningf(format+":\n%s", v...)
}

// TracebackAll logs the given message and dumps a stacktrace of all goroutines.
//
// This will be print a traceback, tb, as Warningf(format+":\n%s", v..., tb).
func TracebackAll(format string, v ...interface{}) {
func TracebackAll(format string, v ...any) {
v = append(v, Stacks(true))
Warningf(format+":\n%s", v...)
}
Expand All @@ -350,7 +350,7 @@ func IsLogging(level Level) bool {
// CopyStandardLogTo redirects the stdlib log package global output to the global
// logger for the specified level.
func CopyStandardLogTo(l Level) error {
var f func(string, ...interface{})
var f func(string, ...any)

switch l {
case Debug:
Expand Down
6 changes: 3 additions & 3 deletions pkg/log/rate_limited.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ type rateLimitedLogger struct {
limit *rate.Limiter
}

func (rl *rateLimitedLogger) Debugf(format string, v ...interface{}) {
func (rl *rateLimitedLogger) Debugf(format string, v ...any) {
if rl.limit.Allow() {
rl.logger.Debugf(format, v...)
}
}

func (rl *rateLimitedLogger) Infof(format string, v ...interface{}) {
func (rl *rateLimitedLogger) Infof(format string, v ...any) {
if rl.limit.Allow() {
rl.logger.Infof(format, v...)
}
}

func (rl *rateLimitedLogger) Warningf(format string, v ...interface{}) {
func (rl *rateLimitedLogger) Warningf(format string, v ...any) {
if rl.limit.Allow() {
rl.logger.Warningf(format, v...)
}
Expand Down
Loading

0 comments on commit d8aa09e

Please sign in to comment.