[QRM] Prevent recursive scan if destination contains circular dependency.
This commit is contained in:
parent
7f54036b1a
commit
02123005c1
4 changed files with 389 additions and 17 deletions
40
qrm/type_stack.go
Normal file
40
qrm/type_stack.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue