Loading ...
Sorry, an error occurred while loading the content.
 

Re: bug/crash with lists and echo

Expand Messages
  • Bram Moolenaar
    ... Thanks for fixing this! -- Spam seems to be something useful to novices. Later you realize that it s a bunch of indigestable junk that only clogs your
    Message 1 of 5 , Apr 1, 2008
      Dominique Pelle wrote:

      > On Sun, Mar 30, 2008 at 7:17 PM, Dominique Pelle
      > <dominique.pelle@...> wrote:
      > >
      > > On Sun, Mar 30, 2008 at 2:17 PM, Bram Moolenaar <Bram@...> wrote:
      > >
      > > > Andy Wokula wrote:
      > > >
      > > > > Strange bug and crash with :echo and lists,
      > > > > observed on gVim 7.1.283 (also gVim 7.0):
      > > > >
      > > > >
      > > > > let list = []
      > > > > call add(list, "abc")
      > > > > call add(list, "def")
      > > > > echo list[0]
      > > > > " ^ important
      > > > > let list = reverse(list)
      > > > > call add(list, "ghi")
      > > > > let left = list[: 1]
      > > > > let right = []
      > > > >
      > > > > " echo list[0] list[1] list[2]
      > > > > " " ^ crash, when uncommented!
      > > > >
      > > > > echo left list[2] right
      > > > > " ['abc', 'ghi'] ghi [] wrong
      > > > >
      > > > > let left = list[: 1]
      > > > >
      > > > > echo left list[2] right
      > > > > " ['def', 'abc'] ghi [] ok
      > > >
      > > > I can reproduce it. Also when it's shorter:
      > > >
      > > > let list = []
      > > > call add(list, "abc")
      > > > call add(list, "def")
      > > > echo list[0]
      > > > let list = reverse(list)
      > > > call add(list, "ghi")
      > > > echo list[0] list[1] list[2]
      > > >
      > > > I suspect the reference counter is wrong somewhere, possibly for the
      > > > first "echo" line.
      > >
      > >
      > > I found the root cause of that bug. The list contains a
      > > cache (index in list + value) and that cache should be
      > > invalidated when doing some operations on the list
      > > such as:
      > > - sorting the list
      > > - inserting element in list
      > > - removing element from list.
      > >
      > > Also, when reversing the list, the cache index needed
      > > to be updated.
      > >
      > > Appending to the list does not need to invalidate cache.
      > >
      > > Attached patch fixes all this.
      > >
      > > Possible improvement: inserting or deleting element from
      > > the list could get away with not invalidating the cache when
      > > cached entry is before inserted/deleted element. But it's
      > > simpler and less risky to invalidate cache unconditionally
      > > I think.
      > >
      > > Cheers
      > > -- Dominique
      >
      >
      > Ooop. There were 2 places where my patch invalidated the
      > cache and it was not needed. Also, my cache index update
      > in f_reverse() was incorrect.
      >
      > So I attach my patch again with updates.

      Thanks for fixing this!

      --
      Spam seems to be something useful to novices. Later you realize that
      it's a bunch of indigestable junk that only clogs your system.
      Applies to both the food and the e-mail!

      /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
      /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
      \\\ download, build and distribute -- http://www.A-A-P.org ///
      \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    Your message has been successfully submitted and would be delivered to recipients shortly.