diff options
| author | nikita <nikita@NetBSD.org> | 2023-06-08 21:12:08 +0000 |
|---|---|---|
| committer | nikita <nikita@NetBSD.org> | 2023-06-08 21:12:08 +0000 |
| commit | f13f21abec457e911e5a08259b806132c905bc68 (patch) | |
| tree | 5896f9171c63c0cf57e02958856332daa5beb727 /external/mit/lua/dist/src/lobject.c | |
| parent | f2baa224d27a15d48c42eed301224a90d1004fb6 (diff) | |
lua: resolve import conflicts
Diffstat (limited to 'external/mit/lua/dist/src/lobject.c')
| -rw-r--r-- | external/mit/lua/dist/src/lobject.c | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/external/mit/lua/dist/src/lobject.c b/external/mit/lua/dist/src/lobject.c index 007d4dd37b9..72be7b6d7b2 100644 --- a/external/mit/lua/dist/src/lobject.c +++ b/external/mit/lua/dist/src/lobject.c @@ -1,4 +1,4 @@ -/* $NetBSD: lobject.c,v 1.13 2023/04/16 20:46:17 nikita Exp $ */ +/* $NetBSD: lobject.c,v 1.14 2023/06/08 21:12:08 nikita Exp $ */ /* ** Id: lobject.c @@ -66,7 +66,7 @@ static lua_Integer intarith (lua_State *L, int op, lua_Integer v1, case LUA_OPBOR: return intop(|, v1, v2); case LUA_OPBXOR: return intop(^, v1, v2); case LUA_OPSHL: return luaV_shiftl(v1, v2); - case LUA_OPSHR: return luaV_shiftl(v1, -v2); + case LUA_OPSHR: return luaV_shiftr(v1, v2); case LUA_OPUNM: return intop(-, 0, v1); case LUA_OPBNOT: return intop(^, ~l_castS2U(0), v1); default: lua_assert(0); return 0; @@ -415,29 +415,39 @@ void luaO_tostring (lua_State *L, TValue *obj) { ** =================================================================== */ -/* size for buffer space used by 'luaO_pushvfstring' */ -#define BUFVFS 200 +/* +** Size for buffer space used by 'luaO_pushvfstring'. It should be +** (LUA_IDSIZE + MAXNUMBER2STR) + a minimal space for basic messages, +** so that 'luaG_addinfo' can work directly on the buffer. +*/ +#define BUFVFS (LUA_IDSIZE + MAXNUMBER2STR + 95) /* buffer used by 'luaO_pushvfstring' */ typedef struct BuffFS { lua_State *L; - int pushed; /* number of string pieces already on the stack */ + int pushed; /* true if there is a part of the result on the stack */ int blen; /* length of partial string in 'space' */ char space[BUFVFS]; /* holds last part of the result */ } BuffFS; /* -** Push given string to the stack, as part of the buffer, and -** join the partial strings in the stack into one. +** Push given string to the stack, as part of the result, and +** join it to previous partial result if there is one. +** It may call 'luaV_concat' while using one slot from EXTRA_STACK. +** This call cannot invoke metamethods, as both operands must be +** strings. It can, however, raise an error if the result is too +** long. In that case, 'luaV_concat' frees the extra slot before +** raising the error. */ -static void pushstr (BuffFS *buff, const char *str, size_t l) { +static void pushstr (BuffFS *buff, const char *str, size_t lstr) { lua_State *L = buff->L; - setsvalue2s(L, L->top, luaS_newlstr(L, str, l)); - L->top++; /* may use one extra slot */ - buff->pushed++; - luaV_concat(L, buff->pushed); /* join partial results into one */ - buff->pushed = 1; + setsvalue2s(L, L->top.p, luaS_newlstr(L, str, lstr)); + L->top.p++; /* may use one slot from EXTRA_STACK */ + if (!buff->pushed) /* no previous string on the stack? */ + buff->pushed = 1; /* now there is one */ + else /* join previous string with new one */ + luaV_concat(L, 2); } @@ -483,7 +493,7 @@ static void addstr2buff (BuffFS *buff, const char *str, size_t slen) { /* -** Add a number to the buffer. +** Add a numeral to the buffer. */ static void addnum2buff (BuffFS *buff, TValue *num) { char *numbuff = getbuff(buff, MAXNUMBER2STR); @@ -563,7 +573,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { addstr2buff(&buff, fmt, strlen(fmt)); /* rest of 'fmt' */ clearbuff(&buff); /* empty buffer into the stack */ lua_assert(buff.pushed == 1); - return svalue(s2v(L->top - 1)); + return svalue(s2v(L->top.p - 1)); } |
