Skip to content

Commit 3699446

Browse files
committed
Removed goto's in 'luaD_precall'
(plus a detail in lauxlib.h.)
1 parent 0e5071b commit 3699446

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

lauxlib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ LUALIB_API lua_State *(luaL_newstate) (void);
102102

103103
LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);
104104

105-
LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s,
105+
LUALIB_API void (luaL_addgsub) (luaL_Buffer *b, const char *s,
106106
const char *p, const char *r);
107107
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s,
108108
const char *p, const char *r);

ldo.c

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,30 @@ l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret,
510510
}
511511

512512

513+
/*
514+
** precall for C functions
515+
*/
516+
l_sinline CallInfo *precallC (lua_State *L, StkId func, int nresults,
517+
lua_CFunction f) {
518+
int n; /* number of returns */
519+
CallInfo *ci;
520+
checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
521+
L->ci = ci = prepCallInfo(L, func, nresults, CIST_C,
522+
L->top + LUA_MINSTACK);
523+
lua_assert(ci->top <= L->stack_last);
524+
if (l_unlikely(L->hookmask & LUA_MASKCALL)) {
525+
int narg = cast_int(L->top - func) - 1;
526+
luaD_hook(L, LUA_HOOKCALL, -1, 1, narg);
527+
}
528+
lua_unlock(L);
529+
n = (*f)(L); /* do the actual call */
530+
lua_lock(L);
531+
api_checknelems(L, n);
532+
luaD_poscall(L, ci, n);
533+
return NULL;
534+
}
535+
536+
513537
/*
514538
** Prepares the call to a function (C or Lua). For C functions, also do
515539
** the call. The function to be called is at '*func'. The arguments
@@ -519,32 +543,11 @@ l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret,
519543
** original function position.
520544
*/
521545
CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
522-
lua_CFunction f;
523-
retry:
524546
switch (ttypetag(s2v(func))) {
525547
case LUA_VCCL: /* C closure */
526-
f = clCvalue(s2v(func))->f;
527-
goto Cfunc;
548+
return precallC(L, func, nresults, clCvalue(s2v(func))->f);
528549
case LUA_VLCF: /* light C function */
529-
f = fvalue(s2v(func));
530-
Cfunc: {
531-
int n; /* number of returns */
532-
CallInfo *ci;
533-
checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
534-
L->ci = ci = prepCallInfo(L, func, nresults, CIST_C,
535-
L->top + LUA_MINSTACK);
536-
lua_assert(ci->top <= L->stack_last);
537-
if (l_unlikely(L->hookmask & LUA_MASKCALL)) {
538-
int narg = cast_int(L->top - func) - 1;
539-
luaD_hook(L, LUA_HOOKCALL, -1, 1, narg);
540-
}
541-
lua_unlock(L);
542-
n = (*f)(L); /* do the actual call */
543-
lua_lock(L);
544-
api_checknelems(L, n);
545-
luaD_poscall(L, ci, n);
546-
return NULL;
547-
}
550+
return precallC(L, func, nresults, fvalue(s2v(func)));
548551
case LUA_VLCL: { /* Lua function */
549552
CallInfo *ci;
550553
Proto *p = clLvalue(s2v(func))->p;
@@ -561,7 +564,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
561564
}
562565
default: { /* not a function */
563566
func = luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */
564-
goto retry; /* try again with metamethod */
567+
return luaD_precall(L, func, nresults); /* try again with metamethod */
565568
}
566569
}
567570
}

0 commit comments

Comments
 (0)