mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 10:37:46 +00:00
reflect: add support for linked lists
Linked lists are usually implemented as follows:
type linkedList struct {
next *linkedList
data int // whatever
}
This caused a stack overflow while writing out the reflect run-time type
information. This has now been fixed by splitting the allocation of a
named type number from setting the underlying type in the sidetable.
This commit is contained in:
committed by
Ron Evans
parent
0818a125c0
commit
ea8e4079bc
@@ -5,10 +5,10 @@ import (
|
||||
)
|
||||
|
||||
// This stores a varint for each named type. Named types are identified by their
|
||||
// name instead of by their type. The named types stored in this struct are the
|
||||
// simpler non-basic types: pointer, struct, and channel.
|
||||
// name instead of by their type. The named types stored in this struct are
|
||||
// non-basic types: pointer, struct, and channel.
|
||||
//go:extern reflect.namedNonBasicTypesSidetable
|
||||
var namedNonBasicTypesSidetable byte
|
||||
var namedNonBasicTypesSidetable uintptr
|
||||
|
||||
//go:extern reflect.structTypesSidetable
|
||||
var structTypesSidetable byte
|
||||
|
||||
+1
-1
@@ -163,7 +163,7 @@ func (t Type) stripPrefix() Type {
|
||||
if (t>>4)%2 != 0 {
|
||||
// This is a named type. The data is stored in a sidetable.
|
||||
namedTypeNum := t >> 5
|
||||
n, _ := readVarint(unsafe.Pointer(uintptr(unsafe.Pointer(&namedNonBasicTypesSidetable)) + uintptr(namedTypeNum)))
|
||||
n := *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&namedNonBasicTypesSidetable)) + uintptr(namedTypeNum)*unsafe.Sizeof(uintptr(0))))
|
||||
return Type(n)
|
||||
}
|
||||
// Not a named type, so the value is stored directly in the type code.
|
||||
|
||||
Reference in New Issue
Block a user