[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [Patch] Finalization of function objects
- From: "Thomas Harning Jr." <harningt@...>
- Date: Mon, 3 Aug 2009 12:05:26 -0400
On Mon, Aug 3, 2009 at 9:43 AM, Thomas Harning Jr.<harningt@gmail.com> wrote:
> On Fri, Jul 31, 2009 at 10:09 PM, Thomas Harning Jr.<harningt@gmail.com> wrote:
>> Basically, it looks like the on-error-condition patch is not getting
>> called in the co-routine case. I don't recall what was required to
>> get that working...
>> Also.. it looks like it's printing the success case rather than the
>> failure case. I'll see if I can figure out what is going on... will
>> need to first digest how your patch does the condition tracking.
> Checking through this and writing up a quick test (at:
> http://pastebin.com/m40f2d12b),
> I found that if there is an error inside a coroutine, the failure is
> 'absorbed' and when the coroutine is collected, the success
> 'finalizers' get executed.
>
> Running this test set on the old version yield no errors, besides the
> valgrind-detect access to freed memory.
>
> Hopefully this test can be massaged into a more clean test for
> correctness of the patch, but for now, it should work effectively to
> root out incorrect behavior.
The following patch to TNHarris's code makes the code pass the current
test-set. I think it is correct and may have been a little typo in
the original code:
diff --git a/src/ldo.c b/src/ldo.c
index db52477..320aa1c 100644
--- a/src/ldo.c
+++ b/src/ldo.c
@@ -525,7 +525,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) {
if (status != 0) { /* error? */
L->status = cast_byte(status); /* mark thread as `dead' */
luaD_seterrorobj(L, status, L->top);
- if (L->fin_top >= L->fin_stack) luaD_finalize(L, L->fin_top, 1);
+ if (L->fin_top >= L->fin_stack) luaD_finalize(L, L->fin_stack, 1);
L->ci->top = L->top;
}
else {
Basically... the code to handle coroutine errors was originally doing
nothing because it was finalizing from L->fin_top to L->fin_top ...
quite an empty set. Since this is freeing everything in that thread,
it needs to free from L->fin_top to L->fin_stack (the base)
--
Thomas Harning Jr.