New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve panics in list binding indexes #2666
Conversation
data/binding/bindlists.go
Outdated
for i := oldLen; i < newLen; i++ { | ||
l.appendItem(bindUntypedListItem(l.val, i, l.updateExternal)) | ||
} | ||
l.trigger() | ||
} | ||
|
||
for i, item := range l.items { | ||
if i > oldLen || i > newLen { | ||
break | ||
} | ||
|
||
var err error | ||
if l.updateExternal { | ||
item.(*boundExternalUntypedListItem).lock.Lock() | ||
err = item.(*boundExternalUntypedListItem).setIfChanged((*l.val)[i]) | ||
item.(*boundExternalUntypedListItem).lock.Unlock() | ||
} else { | ||
item.(*boundUntypedListItem).lock.Lock() | ||
err = item.(*boundUntypedListItem).doSet((*l.val)[i]) | ||
item.(*boundUntypedListItem).lock.Unlock() | ||
} | ||
if err != nil { | ||
retErr = err | ||
} | ||
} | ||
return | ||
} | ||
|
||
func (l *boundUntypedList) SetValue(i int, v interface{}) error { | ||
if i < 0 || i >= l.Length() { | ||
return errOutOfBounds | ||
} | ||
|
||
l.lock.Lock() | ||
(*l.val)[i] = v | ||
l.lock.Unlock() | ||
|
||
item, err := l.GetItem(i) | ||
if err != nil { | ||
return err | ||
} | ||
return item.(Untyped).Set(v) | ||
} | ||
|
||
func bindUntypedListItem(v *[]interface{}, i int, external bool) Untyped { | ||
if external { | ||
ret := &boundExternalUntypedListItem{old: (*v)[i]} | ||
ret.val = v | ||
ret.index = i | ||
return ret | ||
} | ||
|
||
return &boundUntypedListItem{val: v, index: i} | ||
} | ||
|
||
type boundUntypedListItem struct { | ||
base | ||
|
||
val *[]interface{} | ||
index int | ||
} | ||
|
||
func (b *boundUntypedListItem) Get() (interface{}, error) { | ||
b.lock.Lock() | ||
defer b.lock.Unlock() | ||
|
||
return (*b.val)[b.index], nil | ||
} | ||
|
||
func (b *boundUntypedListItem) Set(val interface{}) error { | ||
b.lock.Lock() | ||
defer b.lock.Unlock() | ||
|
||
return b.doSet(val) | ||
} | ||
|
||
func (b *boundUntypedListItem) doSet(val interface{}) error { | ||
(*b.val)[b.index] = val | ||
|
||
b.trigger() | ||
return nil | ||
} | ||
|
||
type boundExternalUntypedListItem struct { | ||
boundUntypedListItem | ||
|
||
old interface{} | ||
} | ||
|
||
func (b *boundExternalUntypedListItem) setIfChanged(val interface{}) error { | ||
if val == b.old { | ||
return nil | ||
} | ||
(*b.val)[b.index] = val | ||
b.old = val | ||
|
||
b.trigger() | ||
return nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this supposed to be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I wonder why the automated scripts are doing that. Will revert and then investigate later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like somehow that item was never added to the generator script. Fixed :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Looks good 👍
Fixes #2643
Checklist: