Skip to content

Commit

Permalink
- added cyclic ref check
Browse files Browse the repository at this point in the history
  • Loading branch information
adranwit committed Feb 20, 2025
1 parent fc52466 commit 0880032
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions io/load/reader/csv/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type (
references map[string][]string
pathAccessors map[string]*xunsafe.Field
stringifiers map[reflect.Type]*io2.ObjectStringifier
uniqueTypes map[reflect.Type]bool
config *Config
}

Expand Down Expand Up @@ -87,6 +88,7 @@ func NewMarshaller(rType reflect.Type, config *Config) (*Marshaller, error) {
references: map[string][]string{},
pathAccessors: map[string]*xunsafe.Field{},
xType: xunsafe.NewType(elemType),
uniqueTypes: map[reflect.Type]bool{},
}

if err := marshaller.init(config, excluded); err != nil {
Expand All @@ -106,6 +108,11 @@ func (m *Marshaller) init(config *Config, excluded map[string]bool) error {
}

func (m *Marshaller) indexByPath(parentType reflect.Type, path string, excluded map[string]bool, holder string, parentAccessor *xunsafe.Field) {
if m.uniqueTypes[parentType] { //avoid cyclic reference
return
}
m.uniqueTypes[parentType] = true

elemParentType := Elem(parentType)
numField := elemParentType.NumField()
m.pathAccessors[path] = parentAccessor
Expand Down

0 comments on commit 0880032

Please sign in to comment.