lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, 22 Jul 2020 at 00:26, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
>
> On Tue, 21 Jul 2020 at 19:55, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
> >
> > On Tue, 21 Jul 2020 at 17:58, Roberto Ierusalimschy
> > <roberto@inf.puc-rio.br> wrote:
>
> > > The upvalue is removed from the open list only after the call. If
> > > there is an error, that sequence is interrupted, and the upvalue
> > > is not removed from the list. It would be easy to remove it
> > > before the call, if we preferred not to do the call again.
> > >
> >
> > Thank you - I think you mean this commit:
> > https://github.com/lua/lua/commit/c220b0a5d099372e58e517b9f13eaa7bb0bec45c
> > ?
> >
> > I did try reverting the commit but it caused some failure in the
> > tests. But that was just my initial look - I will look deeper.
> >
>
> If I just move the following lines to where they used to be prior to
> above commit:
>
>     if (uv->tbc && status != NOCLOSINGMETH) {
>       /* must run closing method, which may change the stack */
>       ptrdiff_t levelrel = savestack(L, level);
>       status = callclosemth(L, uplevel(uv), status);
>       level = restorestack(L, levelrel);
>     }
>
> It crashes with memory error when running the tests in local. (I am
> currently testing on Windows 10, but will also test on Linux later).
> The crash occurs in the first test after printing "testing errors in __close".
> So I am unsure what else needs to change...
> I would expect test to fail rather than crash.
>

It seems I also need the other two lines of change in that commit...

But it still crashes on Windows.
So I switched to Linux.

Going back to the original test case:

  local x = 0
  local y = 0
  co = coroutine.wrap(function ()
    local xx <close> = func2close(function () y = y + 1; error("YYY") end)
    local xv <close> = func2close(function () x = x + 1; error("XXX") end)
      coroutine.yield(100)
      return 200
  end)
  assert(co() == 100); assert(x == 0)
  local st, msg = pcall(co)
  print(x)
  print(y)

Now x is 1 and y is 0. Which means that the one of the close methods
wasn't called.

So it seems to me that the commit was to fix this issue - but a
side-effect is that the first __close() method gets called twice. Am I
right?

Regards
Dibyendu