diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-07-25 16:50:44 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-07-25 16:50:44 -0300 |
commit | 1b3f507f620d996ffb69da7476a19251acfb89ca (patch) | |
tree | 71f5a6482d4a33fea53678b411d4837c6450be44 /ldebug.c | |
parent | 6b51133a988587f34ee9581d799ea9913581afd3 (diff) | |
download | lua-1b3f507f620d996ffb69da7476a19251acfb89ca.tar.gz lua-1b3f507f620d996ffb69da7476a19251acfb89ca.tar.bz2 lua-1b3f507f620d996ffb69da7476a19251acfb89ca.zip |
Bug: Call hook may be called twice when count hook yields
Took the opportunity and moved the code that controls call hooks
in 'luaV_execute' into a function.
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -866,6 +866,28 @@ static int changedline (const Proto *p, int oldpc, int newpc) { | |||
866 | 866 | ||
867 | 867 | ||
868 | /* | 868 | /* |
869 | ** Traces Lua calls. If code is running the first instruction of a function, | ||
870 | ** and function is not vararg, and it is not coming from an yield, | ||
871 | ** calls 'luaD_hookcall'. (Vararg functions will call 'luaD_hookcall' | ||
872 | ** after adjusting its variable arguments; otherwise, they could call | ||
873 | ** a line/count hook before the call hook. Functions coming from | ||
874 | ** an yield already called 'luaD_hookcall' before yielding.) | ||
875 | */ | ||
876 | int luaG_tracecall (lua_State *L) { | ||
877 | CallInfo *ci = L->ci; | ||
878 | Proto *p = ci_func(ci)->p; | ||
879 | ci->u.l.trap = 1; /* ensure hooks will be checked */ | ||
880 | if (ci->u.l.savedpc == p->code) { /* first instruction (not resuming)? */ | ||
881 | if (p->is_vararg) | ||
882 | return 0; /* hooks will start at VARARGPREP instruction */ | ||
883 | else if (!(ci->callstatus & CIST_HOOKYIELD)) /* not yieded? */ | ||
884 | luaD_hookcall(L, ci); /* check 'call' hook */ | ||
885 | } | ||
886 | return 1; /* keep 'trap' on */ | ||
887 | } | ||
888 | |||
889 | |||
890 | /* | ||
869 | ** Traces the execution of a Lua function. Called before the execution | 891 | ** Traces the execution of a Lua function. Called before the execution |
870 | ** of each opcode, when debug is on. 'L->oldpc' stores the last | 892 | ** of each opcode, when debug is on. 'L->oldpc' stores the last |
871 | ** instruction traced, to detect line changes. When entering a new | 893 | ** instruction traced, to detect line changes. When entering a new |