Skip to content
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

Merged
merged 2 commits into from Nov 29, 2021

Conversation

andydotxyz
Copy link
Member

Fixes #2643

Checklist:

  • Tests included. <- was a race, so not unit-testable
  • Lint and formatter run with no errors.
  • Tests all pass.

Comment on lines 1073 to 1285
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
}

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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 :)

Copy link
Member

@Jacalz Jacalz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Looks good 👍

@andydotxyz andydotxyz merged commit 5526d02 into fyne-io:release/v2.1.x Nov 29, 2021
@andydotxyz andydotxyz deleted the fix/2643 branch November 29, 2021 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants