[QRM] Prevent recursive scan if destination contains circular dependency.

This commit is contained in:
go-jet 2021-12-07 17:16:10 +01:00
parent 7f54036b1a
commit 02123005c1
4 changed files with 389 additions and 17 deletions

40
qrm/type_stack.go Normal file
View file

@ -0,0 +1,40 @@
package qrm
import "reflect"
type typeStack []*reflect.Type
func newTypeStack() *typeStack {
stack := make(typeStack, 0, 20)
return &stack
}
func (s *typeStack) isEmpty() bool {
return len(*s) == 0
}
func (s *typeStack) push(t *reflect.Type) {
*s = append(*s, t)
}
func (s *typeStack) pop() bool {
if s.isEmpty() {
return false
}
*s = (*s)[:len(*s)-1]
return true
}
func (s *typeStack) contains(t *reflect.Type) bool {
if s.isEmpty() {
return false
}
for _, typ := range *s {
if *typ == *t {
return true
}
}
return false
}