internal/reflectlite, reflect: move StringHeader and SliceHeader back to package reflect

This commit is contained in:
Randy Reddig
2025-03-08 20:35:36 -08:00
committed by Ron Evans
parent bf88cdea90
commit 417aa4312e
5 changed files with 24 additions and 16 deletions
+8
View File
@@ -0,0 +1,8 @@
//go:build !avr
package reflect
// intw is an integer type, used in places where an int is typically required,
// except architectures where the size of an int != word size.
// See https://github.com/tinygo-org/tinygo/issues/1284.
type intw = int
+8
View File
@@ -0,0 +1,8 @@
//go:build avr
package reflect
// intw is an integer type, used in places where an int is typically required,
// except architectures where the size of an int != word size.
// See https://github.com/tinygo-org/tinygo/issues/1284.
type intw = uintptr
+30
View File
@@ -0,0 +1,30 @@
//go:build !avr
package reflect_test
import (
"reflect"
"testing"
"unsafe"
)
// Verify that SliceHeader is the same size as a slice.
var _ [unsafe.Sizeof([]byte{})]byte = [unsafe.Sizeof(reflect.SliceHeader{})]byte{}
// TestSliceHeaderIntegerSize verifies that SliceHeader.Len and Cap are type int on non-AVR platforms.
// See https://github.com/tinygo-org/tinygo/issues/1284.
func TestSliceHeaderIntegerSize(t *testing.T) {
var h reflect.SliceHeader
h.Len = int(0)
h.Cap = int(0)
}
// Verify that StringHeader is the same size as a string.
var _ [unsafe.Sizeof("hello")]byte = [unsafe.Sizeof(reflect.StringHeader{})]byte{}
// TestStringHeaderIntegerSize verifies that StringHeader.Len and Cap are type int on non-AVR platforms.
// See https://github.com/tinygo-org/tinygo/issues/1284.
func TestStringHeaderIntegerSize(t *testing.T) {
var h reflect.StringHeader
h.Len = int(0)
}
+21
View File
@@ -226,3 +226,24 @@ func (v Value) Recv() (x Value, ok bool) {
func NewAt(typ Type, p unsafe.Pointer) Value {
panic("unimplemented: reflect.New()")
}
// Deprecated: Use unsafe.Slice or unsafe.SliceData instead.
type SliceHeader struct {
Data uintptr
Len intw
Cap intw
}
// Deprecated: Use unsafe.String or unsafe.StringData instead.
type StringHeader struct {
Data uintptr
Len intw
}
// Verify SliceHeader and StringHeader sizes.
// See https://github.com/tinygo-org/tinygo/pull/4156
// and https://github.com/tinygo-org/tinygo/issues/1284.
var (
_ [unsafe.Sizeof([]byte{})]byte = [unsafe.Sizeof(SliceHeader{})]byte{}
_ [unsafe.Sizeof("")]byte = [unsafe.Sizeof(StringHeader{})]byte{}
)