Skip to content

Commit

Permalink
C does not necessary allow defining new vars in the middle of the block
Browse files Browse the repository at this point in the history
  • Loading branch information
McIkye committed Apr 23, 2015
1 parent 7aa2e45 commit b62616b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
10 changes: 6 additions & 4 deletions src/lua/lbaselib.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ static int luaB_tonumber (lua_State *L) {
else {
const char *s1 = luaL_checkstring(L, 1);
char *s2;
unsigned long n;
lua_Number n;
luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
n = strtoul(s1, &s2, base);
n = (lua_Number)strtoul(s1, &s2, base);
if (s1 != s2) { /* at least one valid digit? */
while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */
if (*s2 == '\0') { /* no invalid trailing characters? */
Expand Down Expand Up @@ -485,17 +485,19 @@ const LUA_REG_TYPE base_funcs_list[] = {


static int luaB_index(lua_State *L) {
const char *keyname;
void *res;
#if LUA_OPTIMIZE_MEMORY == 2
int fres;
if ((fres = luaR_findfunction(L, base_funcs_list)) != 0)
return fres;
#endif
const char *keyname = luaL_checkstring(L, 2);
keyname = luaL_checkstring(L, 2);
if (!strcmp(keyname, "_VERSION")) {
lua_pushliteral(L, LUA_VERSION);
return 1;
}
void *res = luaR_findglobal(keyname, strlen(keyname));
res = luaR_findglobal(keyname, strlen(keyname));
if (!res)
return 0;
else {
Expand Down
17 changes: 11 additions & 6 deletions src/lua/ldump.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static void MaybeByteSwap(char *number, size_t numbersize, DumpState *D)
int platform_little_endian = *(char*)&x;
if (platform_little_endian != D->target.little_endian)
{
unsigned long i;
int i;
for (i=0; i<numbersize/2; i++)
{
char temp = number[i];
Expand All @@ -78,15 +78,17 @@ static void DumpIntWithSize(int x, int sizeof_int, DumpState* D)
DumpChar(x,D);
} break;
case 2: {
int16_t y;
if (x>0x7FFF || x<(-0x8000)) D->status=LUA_ERR_CC_INTOVERFLOW;
int16_t y=(int16_t)x;
y=(int16_t)x;
MaybeByteSwap((char*)&y,2,D);
DumpVar(y,D);
} break;
case 4: {
int32_t y;
/* Need to reduce bounds by 1 to avoid messing 32-bit compilers up */
if (x>0x7FFFFFFE || x<(-0x7FFFFFFF)) D->status=LUA_ERR_CC_INTOVERFLOW;
int32_t y=(int32_t)x;
y=(int32_t)x;
MaybeByteSwap((char*)&y,4,D);
DumpVar(y,D);
} break;
Expand All @@ -108,15 +110,17 @@ static void DumpSize(uint32_t x, DumpState* D)
DumpChar(x,D);
} break;
case 2: {
uint16_t y;
if (x>0xFFFF) D->status=LUA_ERR_CC_INTOVERFLOW;
uint16_t y=(uint16_t)x;
y=(uint16_t)x;
MaybeByteSwap((char*)&y,2,D);
DumpVar(y,D);
} break;
case 4: {
uint32_t y;
/* Reduce bounds to avoid messing 32-bit compilers up */
if (x>0xFFFFFFFE) D->status=LUA_ERR_CC_INTOVERFLOW;
uint32_t y=x;
y=x;
MaybeByteSwap((char*)&y,4,D);
DumpVar(y,D);
} break;
Expand Down Expand Up @@ -167,9 +171,10 @@ static void DumpNumber(lua_Number x, DumpState* D)

static void DumpCode(const Proto *f, DumpState* D)
{
DumpInt(f->sizecode,D);
char buf[10];
int i;

DumpInt(f->sizecode,D);
Align4(D);
for (i=0; i<f->sizecode; i++)
{
Expand Down
3 changes: 2 additions & 1 deletion src/lua/lgc.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,10 @@ static l_mem singlestep (lua_State *L) {

void luaC_step (lua_State *L) {
global_State *g = G(L);
l_mem lim;
if(is_block_gc(L)) return;
set_block_gc(L);
l_mem lim = (GCSTEPSIZE/100) * g->gcstepmul;
lim = (GCSTEPSIZE/100) * g->gcstepmul;
if (lim == 0)
lim = (MAX_LUMEM-1)/2; /* no limit */
g->gcdept += g->totalbytes - g->GCthreshold;
Expand Down

0 comments on commit b62616b

Please sign in to comment.