diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-01-30 11:41:39 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-01-30 11:41:39 -0300 |
| commit | d1e677c52be3b107a7a29fdc482158f6d9251e79 (patch) | |
| tree | 6b201f229a9dc1f0752f6544b71498a4d528941d | |
| parent | f7439112a5469078ac4f444106242cf1c1d3fe8a (diff) | |
| download | lua-d1e677c52be3b107a7a29fdc482158f6d9251e79.tar.gz lua-d1e677c52be3b107a7a29fdc482158f6d9251e79.tar.bz2 lua-d1e677c52be3b107a7a29fdc482158f6d9251e79.zip | |
New type 'TStatus' for thread status/error codes
| -rw-r--r-- | lapi.c | 10 | ||||
| -rw-r--r-- | ldo.c | 45 | ||||
| -rw-r--r-- | ldo.h | 14 | ||||
| -rw-r--r-- | lfunc.c | 5 | ||||
| -rw-r--r-- | lfunc.h | 4 | ||||
| -rw-r--r-- | lgc.c | 2 | ||||
| -rw-r--r-- | llimits.h | 6 | ||||
| -rw-r--r-- | lstate.c | 6 | ||||
| -rw-r--r-- | lstate.h | 8 | ||||
| -rw-r--r-- | lstring.c | 2 |
10 files changed, 56 insertions, 46 deletions
| @@ -1070,7 +1070,7 @@ static void f_call (lua_State *L, void *ud) { | |||
| 1070 | LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, | 1070 | LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, |
| 1071 | lua_KContext ctx, lua_KFunction k) { | 1071 | lua_KContext ctx, lua_KFunction k) { |
| 1072 | struct CallS c; | 1072 | struct CallS c; |
| 1073 | int status; | 1073 | TStatus status; |
| 1074 | ptrdiff_t func; | 1074 | ptrdiff_t func; |
| 1075 | lua_lock(L); | 1075 | lua_lock(L); |
| 1076 | api_check(L, k == NULL || !isLua(L->ci), | 1076 | api_check(L, k == NULL || !isLua(L->ci), |
| @@ -1107,14 +1107,14 @@ LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, | |||
| 1107 | } | 1107 | } |
| 1108 | adjustresults(L, nresults); | 1108 | adjustresults(L, nresults); |
| 1109 | lua_unlock(L); | 1109 | lua_unlock(L); |
| 1110 | return status; | 1110 | return APIstatus(status); |
| 1111 | } | 1111 | } |
| 1112 | 1112 | ||
| 1113 | 1113 | ||
| 1114 | LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, | 1114 | LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, |
| 1115 | const char *chunkname, const char *mode) { | 1115 | const char *chunkname, const char *mode) { |
| 1116 | ZIO z; | 1116 | ZIO z; |
| 1117 | int status; | 1117 | TStatus status; |
| 1118 | lua_lock(L); | 1118 | lua_lock(L); |
| 1119 | if (!chunkname) chunkname = "?"; | 1119 | if (!chunkname) chunkname = "?"; |
| 1120 | luaZ_init(L, &z, reader, data); | 1120 | luaZ_init(L, &z, reader, data); |
| @@ -1131,7 +1131,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, | |||
| 1131 | } | 1131 | } |
| 1132 | } | 1132 | } |
| 1133 | lua_unlock(L); | 1133 | lua_unlock(L); |
| 1134 | return status; | 1134 | return APIstatus(status); |
| 1135 | } | 1135 | } |
| 1136 | 1136 | ||
| 1137 | 1137 | ||
| @@ -1154,7 +1154,7 @@ LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) { | |||
| 1154 | 1154 | ||
| 1155 | 1155 | ||
| 1156 | LUA_API int lua_status (lua_State *L) { | 1156 | LUA_API int lua_status (lua_State *L) { |
| 1157 | return L->status; | 1157 | return APIstatus(L->status); |
| 1158 | } | 1158 | } |
| 1159 | 1159 | ||
| 1160 | 1160 | ||
| @@ -97,11 +97,11 @@ | |||
| 97 | struct lua_longjmp { | 97 | struct lua_longjmp { |
| 98 | struct lua_longjmp *previous; | 98 | struct lua_longjmp *previous; |
| 99 | luai_jmpbuf b; | 99 | luai_jmpbuf b; |
| 100 | volatile int status; /* error code */ | 100 | volatile TStatus status; /* error code */ |
| 101 | }; | 101 | }; |
| 102 | 102 | ||
| 103 | 103 | ||
| 104 | void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { | 104 | void luaD_seterrorobj (lua_State *L, TStatus errcode, StkId oldtop) { |
| 105 | switch (errcode) { | 105 | switch (errcode) { |
| 106 | case LUA_ERRMEM: { /* memory error? */ | 106 | case LUA_ERRMEM: { /* memory error? */ |
| 107 | setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */ | 107 | setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */ |
| @@ -125,7 +125,7 @@ void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { | |||
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | 127 | ||
| 128 | l_noret luaD_throw (lua_State *L, int errcode) { | 128 | l_noret luaD_throw (lua_State *L, TStatus errcode) { |
| 129 | if (L->errorJmp) { /* thread has an error handler? */ | 129 | if (L->errorJmp) { /* thread has an error handler? */ |
| 130 | L->errorJmp->status = errcode; /* set status */ | 130 | L->errorJmp->status = errcode; /* set status */ |
| 131 | LUAI_THROW(L, L->errorJmp); /* jump to it */ | 131 | LUAI_THROW(L, L->errorJmp); /* jump to it */ |
| @@ -133,7 +133,7 @@ l_noret luaD_throw (lua_State *L, int errcode) { | |||
| 133 | else { /* thread has no error handler */ | 133 | else { /* thread has no error handler */ |
| 134 | global_State *g = G(L); | 134 | global_State *g = G(L); |
| 135 | errcode = luaE_resetthread(L, errcode); /* close all upvalues */ | 135 | errcode = luaE_resetthread(L, errcode); /* close all upvalues */ |
| 136 | L->status = cast_byte(errcode); | 136 | L->status = errcode; |
| 137 | if (g->mainthread->errorJmp) { /* main thread has a handler? */ | 137 | if (g->mainthread->errorJmp) { /* main thread has a handler? */ |
| 138 | setobjs2s(L, g->mainthread->top.p++, L->top.p - 1); /* copy error obj. */ | 138 | setobjs2s(L, g->mainthread->top.p++, L->top.p - 1); /* copy error obj. */ |
| 139 | luaD_throw(g->mainthread, errcode); /* re-throw in main thread */ | 139 | luaD_throw(g->mainthread, errcode); /* re-throw in main thread */ |
| @@ -149,7 +149,7 @@ l_noret luaD_throw (lua_State *L, int errcode) { | |||
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | 151 | ||
| 152 | int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { | 152 | TStatus luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { |
| 153 | l_uint32 oldnCcalls = L->nCcalls; | 153 | l_uint32 oldnCcalls = L->nCcalls; |
| 154 | struct lua_longjmp lj; | 154 | struct lua_longjmp lj; |
| 155 | lj.status = LUA_OK; | 155 | lj.status = LUA_OK; |
| @@ -751,8 +751,8 @@ void luaD_callnoyield (lua_State *L, StkId func, int nResults) { | |||
| 751 | ** particular, field CIST_RECST preserves the error status across these | 751 | ** particular, field CIST_RECST preserves the error status across these |
| 752 | ** multiple runs, changing only if there is a new error. | 752 | ** multiple runs, changing only if there is a new error. |
| 753 | */ | 753 | */ |
| 754 | static int finishpcallk (lua_State *L, CallInfo *ci) { | 754 | static TStatus finishpcallk (lua_State *L, CallInfo *ci) { |
| 755 | int status = getcistrecst(ci); /* get original status */ | 755 | TStatus status = getcistrecst(ci); /* get original status */ |
| 756 | if (l_likely(status == LUA_OK)) /* no error? */ | 756 | if (l_likely(status == LUA_OK)) /* no error? */ |
| 757 | status = LUA_YIELD; /* was interrupted by an yield */ | 757 | status = LUA_YIELD; /* was interrupted by an yield */ |
| 758 | else { /* error */ | 758 | else { /* error */ |
| @@ -792,14 +792,15 @@ static void finishCcall (lua_State *L, CallInfo *ci) { | |||
| 792 | /* don't need to reset CIST_CLSRET, as it will be set again anyway */ | 792 | /* don't need to reset CIST_CLSRET, as it will be set again anyway */ |
| 793 | } | 793 | } |
| 794 | else { | 794 | else { |
| 795 | int status = LUA_YIELD; /* default if there were no errors */ | 795 | TStatus status = LUA_YIELD; /* default if there were no errors */ |
| 796 | lua_KFunction kf = ci->u.c.k; /* continuation function */ | ||
| 796 | /* must have a continuation and must be able to call it */ | 797 | /* must have a continuation and must be able to call it */ |
| 797 | lua_assert(ci->u.c.k != NULL && yieldable(L)); | 798 | lua_assert(kf != NULL && yieldable(L)); |
| 798 | if (ci->callstatus & CIST_YPCALL) /* was inside a 'lua_pcallk'? */ | 799 | if (ci->callstatus & CIST_YPCALL) /* was inside a 'lua_pcallk'? */ |
| 799 | status = finishpcallk(L, ci); /* finish it */ | 800 | status = finishpcallk(L, ci); /* finish it */ |
| 800 | adjustresults(L, LUA_MULTRET); /* finish 'lua_callk' */ | 801 | adjustresults(L, LUA_MULTRET); /* finish 'lua_callk' */ |
| 801 | lua_unlock(L); | 802 | lua_unlock(L); |
| 802 | n = (*ci->u.c.k)(L, status, ci->u.c.ctx); /* call continuation */ | 803 | n = (*kf)(L, APIstatus(status), ci->u.c.ctx); /* call continuation */ |
| 803 | lua_lock(L); | 804 | lua_lock(L); |
| 804 | api_checknelems(L, n); | 805 | api_checknelems(L, n); |
| 805 | } | 806 | } |
| @@ -901,7 +902,7 @@ static void resume (lua_State *L, void *ud) { | |||
| 901 | ** (status == LUA_YIELD), or an unprotected error ('findpcall' doesn't | 902 | ** (status == LUA_YIELD), or an unprotected error ('findpcall' doesn't |
| 902 | ** find a recover point). | 903 | ** find a recover point). |
| 903 | */ | 904 | */ |
| 904 | static int precover (lua_State *L, int status) { | 905 | static TStatus precover (lua_State *L, TStatus status) { |
| 905 | CallInfo *ci; | 906 | CallInfo *ci; |
| 906 | while (errorstatus(status) && (ci = findpcall(L)) != NULL) { | 907 | while (errorstatus(status) && (ci = findpcall(L)) != NULL) { |
| 907 | L->ci = ci; /* go down to recovery functions */ | 908 | L->ci = ci; /* go down to recovery functions */ |
| @@ -914,7 +915,7 @@ static int precover (lua_State *L, int status) { | |||
| 914 | 915 | ||
| 915 | LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, | 916 | LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, |
| 916 | int *nresults) { | 917 | int *nresults) { |
| 917 | int status; | 918 | TStatus status; |
| 918 | lua_lock(L); | 919 | lua_lock(L); |
| 919 | if (L->status == LUA_OK) { /* may be starting a coroutine */ | 920 | if (L->status == LUA_OK) { /* may be starting a coroutine */ |
| 920 | if (L->ci != &L->base_ci) /* not in base level? */ | 921 | if (L->ci != &L->base_ci) /* not in base level? */ |
| @@ -936,14 +937,14 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, | |||
| 936 | if (l_likely(!errorstatus(status))) | 937 | if (l_likely(!errorstatus(status))) |
| 937 | lua_assert(status == L->status); /* normal end or yield */ | 938 | lua_assert(status == L->status); /* normal end or yield */ |
| 938 | else { /* unrecoverable error */ | 939 | else { /* unrecoverable error */ |
| 939 | L->status = cast_byte(status); /* mark thread as 'dead' */ | 940 | L->status = status; /* mark thread as 'dead' */ |
| 940 | luaD_seterrorobj(L, status, L->top.p); /* push error message */ | 941 | luaD_seterrorobj(L, status, L->top.p); /* push error message */ |
| 941 | L->ci->top.p = L->top.p; | 942 | L->ci->top.p = L->top.p; |
| 942 | } | 943 | } |
| 943 | *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield | 944 | *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield |
| 944 | : cast_int(L->top.p - (L->ci->func.p + 1)); | 945 | : cast_int(L->top.p - (L->ci->func.p + 1)); |
| 945 | lua_unlock(L); | 946 | lua_unlock(L); |
| 946 | return status; | 947 | return APIstatus(status); |
| 947 | } | 948 | } |
| 948 | 949 | ||
| 949 | 950 | ||
| @@ -988,7 +989,7 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx, | |||
| 988 | */ | 989 | */ |
| 989 | struct CloseP { | 990 | struct CloseP { |
| 990 | StkId level; | 991 | StkId level; |
| 991 | int status; | 992 | TStatus status; |
| 992 | }; | 993 | }; |
| 993 | 994 | ||
| 994 | 995 | ||
| @@ -1005,7 +1006,7 @@ static void closepaux (lua_State *L, void *ud) { | |||
| 1005 | ** Calls 'luaF_close' in protected mode. Return the original status | 1006 | ** Calls 'luaF_close' in protected mode. Return the original status |
| 1006 | ** or, in case of errors, the new status. | 1007 | ** or, in case of errors, the new status. |
| 1007 | */ | 1008 | */ |
| 1008 | int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status) { | 1009 | TStatus luaD_closeprotected (lua_State *L, ptrdiff_t level, TStatus status) { |
| 1009 | CallInfo *old_ci = L->ci; | 1010 | CallInfo *old_ci = L->ci; |
| 1010 | lu_byte old_allowhooks = L->allowhook; | 1011 | lu_byte old_allowhooks = L->allowhook; |
| 1011 | for (;;) { /* keep closing upvalues until no more errors */ | 1012 | for (;;) { /* keep closing upvalues until no more errors */ |
| @@ -1027,9 +1028,9 @@ int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status) { | |||
| 1027 | ** thread information ('allowhook', etc.) and in particular | 1028 | ** thread information ('allowhook', etc.) and in particular |
| 1028 | ** its stack level in case of errors. | 1029 | ** its stack level in case of errors. |
| 1029 | */ | 1030 | */ |
| 1030 | int luaD_pcall (lua_State *L, Pfunc func, void *u, | 1031 | TStatus luaD_pcall (lua_State *L, Pfunc func, void *u, ptrdiff_t old_top, |
| 1031 | ptrdiff_t old_top, ptrdiff_t ef) { | 1032 | ptrdiff_t ef) { |
| 1032 | int status; | 1033 | TStatus status; |
| 1033 | CallInfo *old_ci = L->ci; | 1034 | CallInfo *old_ci = L->ci; |
| 1034 | lu_byte old_allowhooks = L->allowhook; | 1035 | lu_byte old_allowhooks = L->allowhook; |
| 1035 | ptrdiff_t old_errfunc = L->errfunc; | 1036 | ptrdiff_t old_errfunc = L->errfunc; |
| @@ -1091,10 +1092,10 @@ static void f_parser (lua_State *L, void *ud) { | |||
| 1091 | } | 1092 | } |
| 1092 | 1093 | ||
| 1093 | 1094 | ||
| 1094 | int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, | 1095 | TStatus luaD_protectedparser (lua_State *L, ZIO *z, const char *name, |
| 1095 | const char *mode) { | 1096 | const char *mode) { |
| 1096 | struct SParser p; | 1097 | struct SParser p; |
| 1097 | int status; | 1098 | TStatus status; |
| 1098 | incnny(L); /* cannot yield during parsing */ | 1099 | incnny(L); /* cannot yield during parsing */ |
| 1099 | p.z = z; p.name = name; p.mode = mode; | 1100 | p.z = z; p.name = name; p.mode = mode; |
| 1100 | p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0; | 1101 | p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0; |
| @@ -67,8 +67,9 @@ | |||
| 67 | /* type of protected functions, to be ran by 'runprotected' */ | 67 | /* type of protected functions, to be ran by 'runprotected' */ |
| 68 | typedef void (*Pfunc) (lua_State *L, void *ud); | 68 | typedef void (*Pfunc) (lua_State *L, void *ud); |
| 69 | 69 | ||
| 70 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); | 70 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, TStatus errcode, StkId oldtop); |
| 71 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, | 71 | LUAI_FUNC TStatus luaD_protectedparser (lua_State *L, ZIO *z, |
| 72 | const char *name, | ||
| 72 | const char *mode); | 73 | const char *mode); |
| 73 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line, | 74 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line, |
| 74 | int fTransfer, int nTransfer); | 75 | int fTransfer, int nTransfer); |
| @@ -78,8 +79,9 @@ LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, | |||
| 78 | LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults); | 79 | LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults); |
| 79 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); | 80 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); |
| 80 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); | 81 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); |
| 81 | LUAI_FUNC int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status); | 82 | LUAI_FUNC TStatus luaD_closeprotected (lua_State *L, ptrdiff_t level, |
| 82 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, | 83 | TStatus status); |
| 84 | LUAI_FUNC TStatus luaD_pcall (lua_State *L, Pfunc func, void *u, | ||
| 83 | ptrdiff_t oldtop, ptrdiff_t ef); | 85 | ptrdiff_t oldtop, ptrdiff_t ef); |
| 84 | LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres); | 86 | LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres); |
| 85 | LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror); | 87 | LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror); |
| @@ -87,8 +89,8 @@ LUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror); | |||
| 87 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); | 89 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); |
| 88 | LUAI_FUNC void luaD_inctop (lua_State *L); | 90 | LUAI_FUNC void luaD_inctop (lua_State *L); |
| 89 | 91 | ||
| 90 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); | 92 | LUAI_FUNC l_noret luaD_throw (lua_State *L, TStatus errcode); |
| 91 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); | 93 | LUAI_FUNC TStatus luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); |
| 92 | 94 | ||
| 93 | #endif | 95 | #endif |
| 94 | 96 | ||
| @@ -140,7 +140,8 @@ static void checkclosemth (lua_State *L, StkId level) { | |||
| 140 | ** the 'level' of the upvalue being closed, as everything after that | 140 | ** the 'level' of the upvalue being closed, as everything after that |
| 141 | ** won't be used again. | 141 | ** won't be used again. |
| 142 | */ | 142 | */ |
| 143 | static void prepcallclosemth (lua_State *L, StkId level, int status, int yy) { | 143 | static void prepcallclosemth (lua_State *L, StkId level, TStatus status, |
| 144 | int yy) { | ||
| 144 | TValue *uv = s2v(level); /* value being closed */ | 145 | TValue *uv = s2v(level); /* value being closed */ |
| 145 | TValue *errobj; | 146 | TValue *errobj; |
| 146 | if (status == CLOSEKTOP) | 147 | if (status == CLOSEKTOP) |
| @@ -224,7 +225,7 @@ static void poptbclist (lua_State *L) { | |||
| 224 | ** Close all upvalues and to-be-closed variables up to the given stack | 225 | ** Close all upvalues and to-be-closed variables up to the given stack |
| 225 | ** level. Return restored 'level'. | 226 | ** level. Return restored 'level'. |
| 226 | */ | 227 | */ |
| 227 | StkId luaF_close (lua_State *L, StkId level, int status, int yy) { | 228 | StkId luaF_close (lua_State *L, StkId level, TStatus status, int yy) { |
| 228 | ptrdiff_t levelrel = savestack(L, level); | 229 | ptrdiff_t levelrel = savestack(L, level); |
| 229 | luaF_closeupval(L, level); /* first, close the upvalues */ | 230 | luaF_closeupval(L, level); /* first, close the upvalues */ |
| 230 | while (L->tbclist.p >= level) { /* traverse tbc's down to that level */ | 231 | while (L->tbclist.p >= level) { /* traverse tbc's down to that level */ |
| @@ -44,7 +44,7 @@ | |||
| 44 | 44 | ||
| 45 | 45 | ||
| 46 | /* special status to close upvalues preserving the top of the stack */ | 46 | /* special status to close upvalues preserving the top of the stack */ |
| 47 | #define CLOSEKTOP (-1) | 47 | #define CLOSEKTOP (LUA_ERRERR + 1) |
| 48 | 48 | ||
| 49 | 49 | ||
| 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); |
| @@ -54,7 +54,7 @@ LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); | |||
| 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); | 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); |
| 55 | LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level); | 55 | LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level); |
| 56 | LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level); | 56 | LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level); |
| 57 | LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy); | 57 | LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, TStatus status, int yy); |
| 58 | LUAI_FUNC void luaF_unlinkupval (UpVal *uv); | 58 | LUAI_FUNC void luaF_unlinkupval (UpVal *uv); |
| 59 | LUAI_FUNC lu_mem luaF_protosize (Proto *p); | 59 | LUAI_FUNC lu_mem luaF_protosize (Proto *p); |
| 60 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); | 60 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); |
| @@ -953,7 +953,7 @@ static void GCTM (lua_State *L) { | |||
| 953 | setgcovalue(L, &v, udata2finalize(g)); | 953 | setgcovalue(L, &v, udata2finalize(g)); |
| 954 | tm = luaT_gettmbyobj(L, &v, TM_GC); | 954 | tm = luaT_gettmbyobj(L, &v, TM_GC); |
| 955 | if (!notm(tm)) { /* is there a finalizer? */ | 955 | if (!notm(tm)) { /* is there a finalizer? */ |
| 956 | int status; | 956 | TStatus status; |
| 957 | lu_byte oldah = L->allowhook; | 957 | lu_byte oldah = L->allowhook; |
| 958 | lu_byte oldgcstp = g->gcstp; | 958 | lu_byte oldgcstp = g->gcstp; |
| 959 | g->gcstp |= GCSTPGC; /* avoid GC steps */ | 959 | g->gcstp |= GCSTPGC; /* avoid GC steps */ |
| @@ -41,6 +41,12 @@ typedef unsigned char lu_byte; | |||
| 41 | typedef signed char ls_byte; | 41 | typedef signed char ls_byte; |
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | /* Type for thread status/error codes */ | ||
| 45 | typedef lu_byte TStatus; | ||
| 46 | |||
| 47 | /* The C API still uses 'int' for status/error codes */ | ||
| 48 | #define APIstatus(st) cast_int(st) | ||
| 49 | |||
| 44 | /* maximum value for size_t */ | 50 | /* maximum value for size_t */ |
| 45 | #define MAX_SIZET ((size_t)(~(size_t)0)) | 51 | #define MAX_SIZET ((size_t)(~(size_t)0)) |
| 46 | 52 | ||
| @@ -320,7 +320,7 @@ void luaE_freethread (lua_State *L, lua_State *L1) { | |||
| 320 | } | 320 | } |
| 321 | 321 | ||
| 322 | 322 | ||
| 323 | int luaE_resetthread (lua_State *L, int status) { | 323 | TStatus luaE_resetthread (lua_State *L, TStatus status) { |
| 324 | CallInfo *ci = L->ci = &L->base_ci; /* unwind CallInfo list */ | 324 | CallInfo *ci = L->ci = &L->base_ci; /* unwind CallInfo list */ |
| 325 | setnilvalue(s2v(L->stack.p)); /* 'function' entry for basic 'ci' */ | 325 | setnilvalue(s2v(L->stack.p)); /* 'function' entry for basic 'ci' */ |
| 326 | ci->func.p = L->stack.p; | 326 | ci->func.p = L->stack.p; |
| @@ -340,12 +340,12 @@ int luaE_resetthread (lua_State *L, int status) { | |||
| 340 | 340 | ||
| 341 | 341 | ||
| 342 | LUA_API int lua_closethread (lua_State *L, lua_State *from) { | 342 | LUA_API int lua_closethread (lua_State *L, lua_State *from) { |
| 343 | int status; | 343 | TStatus status; |
| 344 | lua_lock(L); | 344 | lua_lock(L); |
| 345 | L->nCcalls = (from) ? getCcalls(from) : 0; | 345 | L->nCcalls = (from) ? getCcalls(from) : 0; |
| 346 | status = luaE_resetthread(L, L->status); | 346 | status = luaE_resetthread(L, L->status); |
| 347 | lua_unlock(L); | 347 | lua_unlock(L); |
| 348 | return status; | 348 | return APIstatus(status); |
| 349 | } | 349 | } |
| 350 | 350 | ||
| 351 | 351 | ||
| @@ -339,8 +339,8 @@ typedef struct global_State { | |||
| 339 | */ | 339 | */ |
| 340 | struct lua_State { | 340 | struct lua_State { |
| 341 | CommonHeader; | 341 | CommonHeader; |
| 342 | lu_byte status; | ||
| 343 | lu_byte allowhook; | 342 | lu_byte allowhook; |
| 343 | TStatus status; | ||
| 344 | unsigned short nci; /* number of items in 'ci' list */ | 344 | unsigned short nci; /* number of items in 'ci' list */ |
| 345 | StkIdRel top; /* first free slot in the stack */ | 345 | StkIdRel top; /* first free slot in the stack */ |
| 346 | global_State *l_G; | 346 | global_State *l_G; |
| @@ -352,10 +352,10 @@ struct lua_State { | |||
| 352 | GCObject *gclist; | 352 | GCObject *gclist; |
| 353 | struct lua_State *twups; /* list of threads with open upvalues */ | 353 | struct lua_State *twups; /* list of threads with open upvalues */ |
| 354 | struct lua_longjmp *errorJmp; /* current error recover point */ | 354 | struct lua_longjmp *errorJmp; /* current error recover point */ |
| 355 | CallInfo base_ci; /* CallInfo for first level (C calling Lua) */ | 355 | CallInfo base_ci; /* CallInfo for first level (C host) */ |
| 356 | volatile lua_Hook hook; | 356 | volatile lua_Hook hook; |
| 357 | ptrdiff_t errfunc; /* current error handling function (stack index) */ | 357 | ptrdiff_t errfunc; /* current error handling function (stack index) */ |
| 358 | l_uint32 nCcalls; /* number of nested (non-yieldable | C) calls */ | 358 | l_uint32 nCcalls; /* number of nested non-yieldable or C calls */ |
| 359 | int oldpc; /* last pc traced */ | 359 | int oldpc; /* last pc traced */ |
| 360 | int basehookcount; | 360 | int basehookcount; |
| 361 | int hookcount; | 361 | int hookcount; |
| @@ -438,7 +438,7 @@ LUAI_FUNC void luaE_checkcstack (lua_State *L); | |||
| 438 | LUAI_FUNC void luaE_incCstack (lua_State *L); | 438 | LUAI_FUNC void luaE_incCstack (lua_State *L); |
| 439 | LUAI_FUNC void luaE_warning (lua_State *L, const char *msg, int tocont); | 439 | LUAI_FUNC void luaE_warning (lua_State *L, const char *msg, int tocont); |
| 440 | LUAI_FUNC void luaE_warnerror (lua_State *L, const char *where); | 440 | LUAI_FUNC void luaE_warnerror (lua_State *L, const char *where); |
| 441 | LUAI_FUNC int luaE_resetthread (lua_State *L, int status); | 441 | LUAI_FUNC TStatus luaE_resetthread (lua_State *L, TStatus status); |
| 442 | 442 | ||
| 443 | 443 | ||
| 444 | #endif | 444 | #endif |
| @@ -329,7 +329,7 @@ TString *luaS_newextlstr (lua_State *L, | |||
| 329 | if (!falloc) | 329 | if (!falloc) |
| 330 | f_pintern(L, &ne); /* just internalize string */ | 330 | f_pintern(L, &ne); /* just internalize string */ |
| 331 | else { | 331 | else { |
| 332 | int status = luaD_rawrunprotected(L, f_pintern, &ne); | 332 | TStatus status = luaD_rawrunprotected(L, f_pintern, &ne); |
| 333 | (*falloc)(ud, cast_voidp(s), len + 1, 0); /* free external string */ | 333 | (*falloc)(ud, cast_voidp(s), len + 1, 0); /* free external string */ |
| 334 | if (status != LUA_OK) /* memory error? */ | 334 | if (status != LUA_OK) /* memory error? */ |
| 335 | luaM_error(L); /* re-raise memory error */ | 335 | luaM_error(L); /* re-raise memory error */ |
