diff options
| author | Mike Pall <mike> | 2017-04-07 12:12:03 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2017-04-07 12:12:03 +0200 |
| commit | 9c685f7003388725c91ef38627113015676b6d65 (patch) | |
| tree | 6f7538b8073a9c74ae8d2846e1c3c6f20a68523a | |
| parent | 22dfa63283276d5dc13205680bda961ec671aef6 (diff) | |
| download | luajit-9c685f7003388725c91ef38627113015676b6d65.tar.gz luajit-9c685f7003388725c91ef38627113015676b6d65.tar.bz2 luajit-9c685f7003388725c91ef38627113015676b6d65.zip | |
Refactor with LUA_OK.
Contributed by François Perrad.
| -rw-r--r-- | src/lib_base.c | 8 | ||||
| -rw-r--r-- | src/lj_api.c | 8 | ||||
| -rw-r--r-- | src/lj_err.c | 2 | ||||
| -rw-r--r-- | src/lj_state.c | 8 | ||||
| -rw-r--r-- | src/lua.h | 3 | ||||
| -rw-r--r-- | src/luajit.c | 18 |
6 files changed, 24 insertions, 23 deletions
diff --git a/src/lib_base.c b/src/lib_base.c index 44014f9b..3a757870 100644 --- a/src/lib_base.c +++ b/src/lib_base.c | |||
| @@ -346,7 +346,7 @@ LJLIB_ASM_(xpcall) LJLIB_REC(.) | |||
| 346 | 346 | ||
| 347 | static int load_aux(lua_State *L, int status, int envarg) | 347 | static int load_aux(lua_State *L, int status, int envarg) |
| 348 | { | 348 | { |
| 349 | if (status == 0) { | 349 | if (status == LUA_OK) { |
| 350 | if (tvistab(L->base+envarg-1)) { | 350 | if (tvistab(L->base+envarg-1)) { |
| 351 | GCfunc *fn = funcV(L->top-1); | 351 | GCfunc *fn = funcV(L->top-1); |
| 352 | GCtab *t = tabV(L->base+envarg-1); | 352 | GCtab *t = tabV(L->base+envarg-1); |
| @@ -419,7 +419,7 @@ LJLIB_CF(dofile) | |||
| 419 | GCstr *fname = lj_lib_optstr(L, 1); | 419 | GCstr *fname = lj_lib_optstr(L, 1); |
| 420 | setnilV(L->top); | 420 | setnilV(L->top); |
| 421 | L->top = L->base+1; | 421 | L->top = L->base+1; |
| 422 | if (luaL_loadfile(L, fname ? strdata(fname) : NULL) != 0) | 422 | if (luaL_loadfile(L, fname ? strdata(fname) : NULL) != LUA_OK) |
| 423 | lua_error(L); | 423 | lua_error(L); |
| 424 | lua_call(L, 0, LUA_MULTRET); | 424 | lua_call(L, 0, LUA_MULTRET); |
| 425 | return (int)(L->top - L->base) - 1; | 425 | return (int)(L->top - L->base) - 1; |
| @@ -537,7 +537,7 @@ LJLIB_CF(coroutine_status) | |||
| 537 | co = threadV(L->base); | 537 | co = threadV(L->base); |
| 538 | if (co == L) s = "running"; | 538 | if (co == L) s = "running"; |
| 539 | else if (co->status == LUA_YIELD) s = "suspended"; | 539 | else if (co->status == LUA_YIELD) s = "suspended"; |
| 540 | else if (co->status != 0) s = "dead"; | 540 | else if (co->status != LUA_OK) s = "dead"; |
| 541 | else if (co->base > tvref(co->stack)+1+LJ_FR2) s = "normal"; | 541 | else if (co->base > tvref(co->stack)+1+LJ_FR2) s = "normal"; |
| 542 | else if (co->top == co->base) s = "dead"; | 542 | else if (co->top == co->base) s = "dead"; |
| 543 | else s = "suspended"; | 543 | else s = "suspended"; |
| @@ -583,7 +583,7 @@ LJLIB_ASM(coroutine_yield) | |||
| 583 | static int ffh_resume(lua_State *L, lua_State *co, int wrap) | 583 | static int ffh_resume(lua_State *L, lua_State *co, int wrap) |
| 584 | { | 584 | { |
| 585 | if (co->cframe != NULL || co->status > LUA_YIELD || | 585 | if (co->cframe != NULL || co->status > LUA_YIELD || |
| 586 | (co->status == 0 && co->top == co->base)) { | 586 | (co->status == LUA_OK && co->top == co->base)) { |
| 587 | ErrMsg em = co->cframe ? LJ_ERR_CORUN : LJ_ERR_CODEAD; | 587 | ErrMsg em = co->cframe ? LJ_ERR_CORUN : LJ_ERR_CODEAD; |
| 588 | if (wrap) lj_err_caller(L, em); | 588 | if (wrap) lj_err_caller(L, em); |
| 589 | setboolV(L->base-1-LJ_FR2, 0); | 589 | setboolV(L->base-1-LJ_FR2, 0); |
diff --git a/src/lj_api.c b/src/lj_api.c index d1be3abf..711c7e9d 100644 --- a/src/lj_api.c +++ b/src/lj_api.c | |||
| @@ -1032,7 +1032,7 @@ static TValue *api_call_base(lua_State *L, int nargs) | |||
| 1032 | 1032 | ||
| 1033 | LUA_API void lua_call(lua_State *L, int nargs, int nresults) | 1033 | LUA_API void lua_call(lua_State *L, int nargs, int nresults) |
| 1034 | { | 1034 | { |
| 1035 | api_check(L, L->status == 0 || L->status == LUA_ERRERR); | 1035 | api_check(L, L->status == LUA_OK || L->status == LUA_ERRERR); |
| 1036 | api_checknelems(L, nargs+1); | 1036 | api_checknelems(L, nargs+1); |
| 1037 | lj_vm_call(L, api_call_base(L, nargs), nresults+1); | 1037 | lj_vm_call(L, api_call_base(L, nargs), nresults+1); |
| 1038 | } | 1038 | } |
| @@ -1043,7 +1043,7 @@ LUA_API int lua_pcall(lua_State *L, int nargs, int nresults, int errfunc) | |||
| 1043 | uint8_t oldh = hook_save(g); | 1043 | uint8_t oldh = hook_save(g); |
| 1044 | ptrdiff_t ef; | 1044 | ptrdiff_t ef; |
| 1045 | int status; | 1045 | int status; |
| 1046 | api_check(L, L->status == 0 || L->status == LUA_ERRERR); | 1046 | api_check(L, L->status == LUA_OK || L->status == LUA_ERRERR); |
| 1047 | api_checknelems(L, nargs+1); | 1047 | api_checknelems(L, nargs+1); |
| 1048 | if (errfunc == 0) { | 1048 | if (errfunc == 0) { |
| 1049 | ef = 0; | 1049 | ef = 0; |
| @@ -1075,7 +1075,7 @@ LUA_API int lua_cpcall(lua_State *L, lua_CFunction func, void *ud) | |||
| 1075 | global_State *g = G(L); | 1075 | global_State *g = G(L); |
| 1076 | uint8_t oldh = hook_save(g); | 1076 | uint8_t oldh = hook_save(g); |
| 1077 | int status; | 1077 | int status; |
| 1078 | api_check(L, L->status == 0 || L->status == LUA_ERRERR); | 1078 | api_check(L, L->status == LUA_OK || L->status == LUA_ERRERR); |
| 1079 | status = lj_vm_cpcall(L, func, ud, cpcall); | 1079 | status = lj_vm_cpcall(L, func, ud, cpcall); |
| 1080 | if (status) hook_restore(g, oldh); | 1080 | if (status) hook_restore(g, oldh); |
| 1081 | return status; | 1081 | return status; |
| @@ -1140,7 +1140,7 @@ LUA_API int lua_resume(lua_State *L, int nargs) | |||
| 1140 | { | 1140 | { |
| 1141 | if (L->cframe == NULL && L->status <= LUA_YIELD) | 1141 | if (L->cframe == NULL && L->status <= LUA_YIELD) |
| 1142 | return lj_vm_resume(L, | 1142 | return lj_vm_resume(L, |
| 1143 | L->status == 0 ? api_call_base(L, nargs) : L->top - nargs, | 1143 | L->status == LUA_OK ? api_call_base(L, nargs) : L->top - nargs, |
| 1144 | 0, 0); | 1144 | 0, 0); |
| 1145 | L->top = L->base; | 1145 | L->top = L->base; |
| 1146 | setstrV(L, L->top, lj_err_str(L, LJ_ERR_COSUSP)); | 1146 | setstrV(L, L->top, lj_err_str(L, LJ_ERR_COSUSP)); |
diff --git a/src/lj_err.c b/src/lj_err.c index 049294ea..b6be357e 100644 --- a/src/lj_err.c +++ b/src/lj_err.c | |||
| @@ -509,7 +509,7 @@ LJ_NOINLINE void LJ_FASTCALL lj_err_throw(lua_State *L, int errcode) | |||
| 509 | global_State *g = G(L); | 509 | global_State *g = G(L); |
| 510 | lj_trace_abort(g); | 510 | lj_trace_abort(g); |
| 511 | setmref(g->jit_base, NULL); | 511 | setmref(g->jit_base, NULL); |
| 512 | L->status = 0; | 512 | L->status = LUA_OK; |
| 513 | #if LJ_UNWIND_EXT | 513 | #if LJ_UNWIND_EXT |
| 514 | err_raise_ext(errcode); | 514 | err_raise_ext(errcode); |
| 515 | /* | 515 | /* |
diff --git a/src/lj_state.c b/src/lj_state.c index 3cc0fea5..632dd07e 100644 --- a/src/lj_state.c +++ b/src/lj_state.c | |||
| @@ -224,7 +224,7 @@ LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud) | |||
| 224 | close_state(L); | 224 | close_state(L); |
| 225 | return NULL; | 225 | return NULL; |
| 226 | } | 226 | } |
| 227 | L->status = 0; | 227 | L->status = LUA_OK; |
| 228 | return L; | 228 | return L; |
| 229 | } | 229 | } |
| 230 | 230 | ||
| @@ -256,10 +256,10 @@ LUA_API void lua_close(lua_State *L) | |||
| 256 | #endif | 256 | #endif |
| 257 | for (i = 0;;) { | 257 | for (i = 0;;) { |
| 258 | hook_enter(g); | 258 | hook_enter(g); |
| 259 | L->status = 0; | 259 | L->status = LUA_OK; |
| 260 | L->base = L->top = tvref(L->stack) + 1 + LJ_FR2; | 260 | L->base = L->top = tvref(L->stack) + 1 + LJ_FR2; |
| 261 | L->cframe = NULL; | 261 | L->cframe = NULL; |
| 262 | if (lj_vm_cpcall(L, NULL, NULL, cpfinalize) == 0) { | 262 | if (lj_vm_cpcall(L, NULL, NULL, cpfinalize) == LUA_OK) { |
| 263 | if (++i >= 10) break; | 263 | if (++i >= 10) break; |
| 264 | lj_gc_separateudata(g, 1); /* Separate udata again. */ | 264 | lj_gc_separateudata(g, 1); /* Separate udata again. */ |
| 265 | if (gcref(g->gc.mmudata) == NULL) /* Until nothing is left to do. */ | 265 | if (gcref(g->gc.mmudata) == NULL) /* Until nothing is left to do. */ |
| @@ -274,7 +274,7 @@ lua_State *lj_state_new(lua_State *L) | |||
| 274 | lua_State *L1 = lj_mem_newobj(L, lua_State); | 274 | lua_State *L1 = lj_mem_newobj(L, lua_State); |
| 275 | L1->gct = ~LJ_TTHREAD; | 275 | L1->gct = ~LJ_TTHREAD; |
| 276 | L1->dummy_ffid = FF_C; | 276 | L1->dummy_ffid = FF_C; |
| 277 | L1->status = 0; | 277 | L1->status = LUA_OK; |
| 278 | L1->stacksize = 0; | 278 | L1->stacksize = 0; |
| 279 | setmref(L1->stack, NULL); | 279 | setmref(L1->stack, NULL); |
| 280 | L1->cframe = NULL; | 280 | L1->cframe = NULL; |
| @@ -39,7 +39,8 @@ | |||
| 39 | #define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) | 39 | #define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) |
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | /* thread status; 0 is OK */ | 42 | /* thread status */ |
| 43 | #define LUA_OK 0 | ||
| 43 | #define LUA_YIELD 1 | 44 | #define LUA_YIELD 1 |
| 44 | #define LUA_ERRRUN 2 | 45 | #define LUA_ERRRUN 2 |
| 45 | #define LUA_ERRSYNTAX 3 | 46 | #define LUA_ERRSYNTAX 3 |
diff --git a/src/luajit.c b/src/luajit.c index 8c8cf9e6..1ca24301 100644 --- a/src/luajit.c +++ b/src/luajit.c | |||
| @@ -124,7 +124,7 @@ static int docall(lua_State *L, int narg, int clear) | |||
| 124 | #endif | 124 | #endif |
| 125 | lua_remove(L, base); /* remove traceback function */ | 125 | lua_remove(L, base); /* remove traceback function */ |
| 126 | /* force a complete garbage collection in case of errors */ | 126 | /* force a complete garbage collection in case of errors */ |
| 127 | if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0); | 127 | if (status != LUA_OK) lua_gc(L, LUA_GCCOLLECT, 0); |
| 128 | return status; | 128 | return status; |
| 129 | } | 129 | } |
| 130 | 130 | ||
| @@ -249,9 +249,9 @@ static void dotty(lua_State *L) | |||
| 249 | const char *oldprogname = progname; | 249 | const char *oldprogname = progname; |
| 250 | progname = NULL; | 250 | progname = NULL; |
| 251 | while ((status = loadline(L)) != -1) { | 251 | while ((status = loadline(L)) != -1) { |
| 252 | if (status == 0) status = docall(L, 0, 0); | 252 | if (status == LUA_OK) status = docall(L, 0, 0); |
| 253 | report(L, status); | 253 | report(L, status); |
| 254 | if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */ | 254 | if (status == LUA_OK && lua_gettop(L) > 0) { /* any result to print? */ |
| 255 | lua_getglobal(L, "print"); | 255 | lua_getglobal(L, "print"); |
| 256 | lua_insert(L, 1); | 256 | lua_insert(L, 1); |
| 257 | if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) | 257 | if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) |
| @@ -273,7 +273,7 @@ static int handle_script(lua_State *L, char **argx) | |||
| 273 | if (strcmp(fname, "-") == 0 && strcmp(argx[-1], "--") != 0) | 273 | if (strcmp(fname, "-") == 0 && strcmp(argx[-1], "--") != 0) |
| 274 | fname = NULL; /* stdin */ | 274 | fname = NULL; /* stdin */ |
| 275 | status = luaL_loadfile(L, fname); | 275 | status = luaL_loadfile(L, fname); |
| 276 | if (status == 0) { | 276 | if (status == LUA_OK) { |
| 277 | /* Fetch args from arg table. LUA_INIT or -e might have changed them. */ | 277 | /* Fetch args from arg table. LUA_INIT or -e might have changed them. */ |
| 278 | int narg = 0; | 278 | int narg = 0; |
| 279 | lua_getglobal(L, "arg"); | 279 | lua_getglobal(L, "arg"); |
| @@ -483,7 +483,7 @@ static int runargs(lua_State *L, char **argv, int argn) | |||
| 483 | default: break; | 483 | default: break; |
| 484 | } | 484 | } |
| 485 | } | 485 | } |
| 486 | return 0; | 486 | return LUA_OK; |
| 487 | } | 487 | } |
| 488 | 488 | ||
| 489 | static int handle_luainit(lua_State *L) | 489 | static int handle_luainit(lua_State *L) |
| @@ -494,7 +494,7 @@ static int handle_luainit(lua_State *L) | |||
| 494 | const char *init = getenv(LUA_INIT); | 494 | const char *init = getenv(LUA_INIT); |
| 495 | #endif | 495 | #endif |
| 496 | if (init == NULL) | 496 | if (init == NULL) |
| 497 | return 0; /* status OK */ | 497 | return LUA_OK; |
| 498 | else if (init[0] == '@') | 498 | else if (init[0] == '@') |
| 499 | return dofile(L, init+1); | 499 | return dofile(L, init+1); |
| 500 | else | 500 | else |
| @@ -539,17 +539,17 @@ static int pmain(lua_State *L) | |||
| 539 | 539 | ||
| 540 | if (!(flags & FLAGS_NOENV)) { | 540 | if (!(flags & FLAGS_NOENV)) { |
| 541 | s->status = handle_luainit(L); | 541 | s->status = handle_luainit(L); |
| 542 | if (s->status != 0) return 0; | 542 | if (s->status != LUA_OK) return 0; |
| 543 | } | 543 | } |
| 544 | 544 | ||
| 545 | if ((flags & FLAGS_VERSION)) print_version(); | 545 | if ((flags & FLAGS_VERSION)) print_version(); |
| 546 | 546 | ||
| 547 | s->status = runargs(L, argv, argn); | 547 | s->status = runargs(L, argv, argn); |
| 548 | if (s->status != 0) return 0; | 548 | if (s->status != LUA_OK) return 0; |
| 549 | 549 | ||
| 550 | if (s->argc > argn) { | 550 | if (s->argc > argn) { |
| 551 | s->status = handle_script(L, argv + argn); | 551 | s->status = handle_script(L, argv + argn); |
| 552 | if (s->status != 0) return 0; | 552 | if (s->status != LUA_OK) return 0; |
| 553 | } | 553 | } |
| 554 | 554 | ||
| 555 | if ((flags & FLAGS_INTERACTIVE)) { | 555 | if ((flags & FLAGS_INTERACTIVE)) { |
