lua-users home
lua-l archive

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


> >I've found (and fixed) a small bug in lvm.c
> >The line
> >lvm.c:69 >  if (mask > LUA_MASKLINE) {  /* instruction-hook set? */
> >in traceexec caused the HOOKCOUNT to be triggered if i.e. both
> >the LINE and RETURN hooks are set (and count has reached zero) even
> >though it was not present in the mask.
>
> Can you please send us a minimal program that exhibits this problem?
>
> >minimal change to the line:
> >  if (mask >= LUA_MASKCOUNT) {  /* instruction-hook set? */
>
> Won't this change call the count hook to be triggered even more often?

No, since LUA_MASKCOUNT > LUA_MASKLINE, a mask-value that would evaluate
to true in the first case (> MASKLINE) can still evaluate to false in the
latter.

Short example:

void my_hook( lua_State * L, lua_Debug * ar )
{
	printf( "in hook, event: %d\r\n", ar->event );
}

void main(void)
{
	lua_State * L = lua_open();
	lua_sethook( L, my_hook, LUA_MASKLINE | LUA_MASKRET, 1 ); // See note below

	// load and execute some lua code here

	lua_close( L );
}


Note
The event set in my_hook will be 3 (HOOK COUNT), although that flag has not
been chosen. This is on the quite rare occasion when the count value reaches
zero before the line-hook is checked, but when set to 1, it is bound to
happen
every time.
There are a few workarounds available to solve the problem, besides
modifying the lua source (as to set the count to 0). But as the manual
states,
the count-value should only be meaningful when the hook-bit is set, but in
the
current form, it is always meaningful, although if set to 0, it is almost
safe
to say it woldn't matter.

In my application it would be preferable to be able to specify any value for
count
when not used.. (as I do now, since it was such an easy fix ;)

I hope this makes sense.. :o)