Skip to content

Commit d892e0f

Browse files
committed
Applied latest Lua patches (up to 5.1.4-8)
1 parent fcb633e commit d892e0f

File tree

12 files changed

+44
-21
lines changed

12 files changed

+44
-21
lines changed

src/lapi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) {
334334
}
335335

336336

337+
// MTA Specific
337338
LUA_API lua_Integer lua_tointegerW (lua_State *L, int idx) {
338339
TValue n;
339340
const TValue *o = index2adr(L, idx);

src/lcode.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $
2+
** $Id: lcode.c,v 2.25.1.4 2009/06/15 14:12:25 roberto Exp $
33
** Code generator for Lua
44
** See Copyright Notice in lua.h
55
*/
@@ -544,15 +544,18 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) {
544544
pc = NO_JUMP; /* always true; do nothing */
545545
break;
546546
}
547-
case VFALSE: {
548-
pc = luaK_jump(fs); /* always jump */
549-
break;
550-
}
551547
case VJMP: {
552548
invertjump(fs, e);
553549
pc = e->u.s.info;
554550
break;
555551
}
552+
case VFALSE: {
553+
if (!hasjumps(e)) {
554+
pc = luaK_jump(fs); /* always jump */
555+
break;
556+
}
557+
/* else go through */
558+
}
556559
default: {
557560
pc = jumponcond(fs, e, 0);
558561
break;
@@ -572,14 +575,17 @@ static void luaK_goiffalse (FuncState *fs, expdesc *e) {
572575
pc = NO_JUMP; /* always false; do nothing */
573576
break;
574577
}
575-
case VTRUE: {
576-
pc = luaK_jump(fs); /* always jump */
577-
break;
578-
}
579578
case VJMP: {
580579
pc = e->u.s.info;
581580
break;
582581
}
582+
case VTRUE: {
583+
if (!hasjumps(e)) {
584+
pc = luaK_jump(fs); /* always jump */
585+
break;
586+
}
587+
/* else go through */
588+
}
583589
default: {
584590
pc = jumponcond(fs, e, 1);
585591
break;

src/ldblib.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: ldblib.c,v 1.104.1.3 2008/01/21 13:11:21 roberto Exp $
2+
** $Id: ldblib.c,v 1.104.1.4 2009/08/04 18:50:18 roberto Exp $
33
** Interface from Lua to its debug API
44
** See Copyright Notice in lua.h
55
*/
@@ -44,6 +44,7 @@ static int db_setmetatable (lua_State *L) {
4444

4545

4646
static int db_getfenv (lua_State *L) {
47+
luaL_checkany(L, 1);
4748
lua_getfenv(L, 1);
4849
return 1;
4950
}

src/ldo.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "lvm.h"
3131
#include "lzio.h"
3232

33+
// MTA Specific
3334
lua_PreCallHook pPreCallHook = NULL;
3435
void lua_registerPreCallHook ( lua_PreCallHook f )
3536
{
@@ -308,6 +309,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
308309
}
309310
else { /* if is a C function, call it */
310311
CallInfo *ci;
312+
// MTA Specific
311313
int allowed = 1;
312314
int n = 0;
313315
luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
@@ -320,6 +322,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
320322
if (L->hookmask & LUA_MASKCALL)
321323
luaD_callhook(L, LUA_HOOKCALL, -1);
322324
lua_unlock(L);
325+
// MTA Specific
323326
if ( pPreCallHook )
324327
allowed = pPreCallHook ( *curr_func(L)->c.f, L );
325328
if ( allowed )

src/liolib.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: liolib.c,v 2.73.1.3 2008/01/18 17:47:43 roberto Exp $
2+
** $Id: liolib.c,v 2.73.1.4 2010/05/14 15:33:51 roberto Exp $
33
** Standard I/O (and system) library
44
** See Copyright Notice in lua.h
55
*/
@@ -275,7 +275,10 @@ static int read_number (lua_State *L, FILE *f) {
275275
lua_pushnumber(L, d);
276276
return 1;
277277
}
278-
else return 0; /* read fails */
278+
else {
279+
lua_pushnil(L); /* "result" to be removed */
280+
return 0; /* read fails */
281+
}
279282
}
280283

281284

src/llex.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $
2+
** $Id: llex.c,v 2.20.1.2 2009/11/23 14:58:22 roberto Exp $
33
** Lexical Analyzer
44
** See Copyright Notice in lua.h
55
*/
@@ -118,8 +118,10 @@ TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
118118
lua_State *L = ls->L;
119119
TString *ts = luaS_newlstr(L, str, l);
120120
TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */
121-
if (ttisnil(o))
121+
if (ttisnil(o)) {
122122
setbvalue(o, 1); /* make sure `str' will not be collected */
123+
luaC_checkGC(L);
124+
}
123125
return ts;
124126
}
125127

src/lmathlib.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ static int math_random (lua_State *L) {
206206

207207

208208
static int math_randomseed (lua_State *L) {
209+
// MTA Specific
209210
// lua_tointegerW wraps out of range numbers (luaL_checkint clips values below -1^32 and above 1^32)
210211
srand(lua_tointegerW(L, 1));
211212
// Do some rands here, as the first few results bear a close relationship to the seed number

src/loadlib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: loadlib.c,v 1.52.1.3 2008/08/06 13:29:28 roberto Exp $
2+
** $Id: loadlib.c,v 1.52.1.4 2009/09/09 13:17:16 roberto Exp $
33
** Dynamic library loader for Lua
44
** See Copyright Notice in lua.h
55
**
@@ -638,7 +638,7 @@ LUALIB_API int luaopen_package (lua_State *L) {
638638
lua_pushvalue(L, -1);
639639
lua_replace(L, LUA_ENVIRONINDEX);
640640
/* create `loaders' table */
641-
lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1);
641+
lua_createtable(L, sizeof(loaders)/sizeof(loaders[0]) - 1, 0);
642642
/* fill it with pre-defined loaders */
643643
for (i=0; loaders[i] != NULL; i++) {
644644
lua_pushcfunction(L, loaders[i]);

src/lstate.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ LUA_API void lua_close (lua_State *L) {
212212
close_state(L);
213213
}
214214

215+
// MTA specific
215216
LUA_API lua_State* lua_getmainstate (lua_State *L) {
216217
return G(L)->mainthread;
217218
}

src/lstrlib.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lstrlib.c,v 1.132.1.4 2008/07/11 17:27:21 roberto Exp $
2+
** $Id: lstrlib.c,v 1.132.1.5 2010/05/14 15:34:19 roberto Exp $
33
** Standard library for string operations and pattern-matching
44
** See Copyright Notice in lua.h
55
*/
@@ -753,6 +753,7 @@ static void addintlen (char *form) {
753753

754754

755755
static int str_format (lua_State *L) {
756+
int top = lua_gettop(L);
756757
int arg = 1;
757758
size_t sfl;
758759
const char *strfrmt = luaL_checklstring(L, arg, &sfl);
@@ -767,7 +768,8 @@ static int str_format (lua_State *L) {
767768
else { /* format item */
768769
char form[MAX_FORMAT]; /* to store the format (`%...') */
769770
char buff[MAX_ITEM]; /* to store the formatted item */
770-
arg++;
771+
if (++arg > top)
772+
luaL_argerror(L, arg, "no value");
771773
strfrmt = scanformat(L, strfrmt, form);
772774
switch (*strfrmt++) {
773775
case 'c': {

0 commit comments

Comments
 (0)