Source File
go1_21_unsafe.go
Belonging Package
github.com/traefik/yaegi/internal/unsafe2
//go:build go1.21// +build go1.21// Package unsafe2 provides helpers to generate recursive struct types.package unsafe2import ()type dummy struct{}// DummyType represents a stand-in for a recursive type.var DummyType = reflect.TypeOf(dummy{})// The following type sizes must match their original definition in Go src/internal/abi/type.go.type abiType struct {_ uintptr_ uintptr_ uint32_ uint8_ uint8_ uint8_ uint8_ uintptr_ uintptr_ int32_ int32}type abiName struct {Bytes *byte}type abiStructField struct {Name abiNameTyp *abiTypeOffset uintptr}type abiStructType struct {abiTypePkgPath abiNameFields []abiStructField}type emptyInterface struct {typ *abiType_ unsafe.Pointer}// SetFieldType sets the type of the struct field at the given index, to the given type.//// The struct type must have been created at runtime. This is very unsafe.func ( reflect.Type, int, reflect.Type) {if .Kind() != reflect.Struct || >= .NumField() {return}:= unpackType():= (*abiStructType)(unsafe.Pointer()):= .Fields[].Typ = unpackType().Fields[] =}func unpackType( reflect.Type) *abiType {:= reflect.New().Elem().Interface():= *(*emptyInterface)(unsafe.Pointer(&))return .typ}
![]() |
The pages are generated with Golds v0.8.4. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |