commit 72d675aba78d59e22ebfadbe447f4f51ddab5a5c
parent ba57f7d946bc0b600996f7a982b2fb644df76a98
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Fri, 26 Feb 1999 12:48:33 -0300
macros "growvector" and "reallocvector" more compact
Diffstat:
6 files changed, 24 insertions(+), 30 deletions(-)
diff --git a/lbuffer.c b/lbuffer.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbuffer.c,v 1.7 1999/02/25 19:13:56 roberto Exp roberto $
+** $Id: lbuffer.c,v 1.8 1999/02/25 19:20:40 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -26,8 +26,7 @@ static void Openspace (int size) {
lua_State *l = L; /* to optimize */
size += EXTRABUFF;
l->Mbuffsize = l->Mbuffnext+size;
- l->Mbuffer = luaM_growvector(l->Mbuffer, l->Mbuffnext, size, char,
- memEM, MAX_INT);
+ luaM_growvector(l->Mbuffer, l->Mbuffnext, size, char, arrEM, MAX_INT);
}
diff --git a/ldo.c b/ldo.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldo.c,v 1.34 1999/02/22 14:17:24 roberto Exp roberto $
+** $Id: ldo.c,v 1.35 1999/02/22 19:23:36 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -43,13 +43,12 @@ void luaD_init (void) {
}
-void luaD_checkstack (int n)
-{
+void luaD_checkstack (int n) {
struct Stack *S = &L->stack;
if (S->last-S->top <= n) {
StkId top = S->top-S->stack;
- int stacksize = (S->last-S->stack)+1+STACK_UNIT+n;
- S->stack = luaM_reallocvector(S->stack, stacksize, TObject);
+ int stacksize = (S->last-S->stack)+STACK_UNIT+n;
+ luaM_reallocvector(S->stack, stacksize, TObject);
S->last = S->stack+(stacksize-1);
S->top = S->stack + top;
if (stacksize >= STACK_LIMIT) { /* stack overflow? */
@@ -65,8 +64,7 @@ void luaD_checkstack (int n)
/*
** Adjust stack. Set top to the given value, pushing NILs if needed.
*/
-void luaD_adjusttop (StkId newtop)
-{
+void luaD_adjusttop (StkId newtop) {
int diff = newtop-(L->stack.top-L->stack.stack);
if (diff <= 0)
L->stack.top += diff;
diff --git a/lgc.c b/lgc.c
@@ -1,5 +1,5 @@
/*
-** $Id: lgc.c,v 1.20 1999/01/22 18:08:03 roberto Exp roberto $
+** $Id: lgc.c,v 1.21 1999/02/25 15:16:26 roberto Exp roberto $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@@ -38,8 +38,7 @@ int luaC_ref (TObject *o, int lock) {
if (L->refArray[ref].status == FREE)
break;
if (ref == L->refSize) { /* no more empty spaces? */
- L->refArray = luaM_growvector(L->refArray, L->refSize, 1, struct ref,
- refEM, MAX_INT);
+ luaM_growvector(L->refArray, L->refSize, 1, struct ref, refEM, MAX_INT);
L->refSize++;
}
L->refArray[ref].o = *o;
diff --git a/lmem.h b/lmem.h
@@ -1,5 +1,5 @@
/*
-** $Id: lmem.h,v 1.6 1998/12/15 14:59:43 roberto Exp roberto $
+** $Id: lmem.h,v 1.7 1999/02/25 15:16:26 roberto Exp roberto $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
@@ -16,6 +16,7 @@
#define refEM "reference table overflow"
#define tableEM "table overflow"
#define memEM "not enough memory"
+#define arrEM "internal array bigger than `int' limit"
void *luaM_realloc (void *oldblock, unsigned long size);
void *luaM_growaux (void *block, unsigned long nelems, int inc, int size,
@@ -25,9 +26,9 @@ void *luaM_growaux (void *block, unsigned long nelems, int inc, int size,
#define luaM_malloc(t) luaM_realloc(NULL, (t))
#define luaM_new(t) ((t *)luaM_malloc(sizeof(t)))
#define luaM_newvector(n,t) ((t *)luaM_malloc((n)*sizeof(t)))
-#define luaM_growvector(old,nelems,inc,t,e,l) \
- ((t *)luaM_growaux(old,nelems,inc,sizeof(t),e,l))
-#define luaM_reallocvector(v,n,t) ((t *)luaM_realloc(v,(n)*sizeof(t)))
+#define luaM_growvector(v,nelems,inc,t,e,l) \
+ ((v)=(t *)luaM_growaux(v,nelems,inc,sizeof(t),e,l))
+#define luaM_reallocvector(v,n,t) ((v)=(t *)luaM_realloc(v,(n)*sizeof(t)))
#ifdef DEBUG
diff --git a/lparser.c b/lparser.c
@@ -1,5 +1,5 @@
/*
-** $Id: lparser.c,v 1.23 1999/02/25 15:16:26 roberto Exp roberto $
+** $Id: lparser.c,v 1.24 1999/02/25 19:13:56 roberto Exp roberto $
** LL(1) Parser and code generator for Lua
** See Copyright Notice in lua.h
*/
@@ -131,7 +131,7 @@ static void var_or_func_tail (LexState *ls, vardesc *v);
static void check_pc (FuncState *fs, int n) {
- fs->f->code = luaM_growvector(fs->f->code, fs->pc, n, Byte, codeEM, MAX_INT);
+ luaM_growvector(fs->f->code, fs->pc, n, Byte, codeEM, MAX_INT);
}
@@ -216,8 +216,7 @@ static void code_constant (LexState *ls, int c) {
static int next_constant (FuncState *fs) {
TProtoFunc *f = fs->f;
- f->consts = luaM_growvector(f->consts, f->nconsts, 1, TObject,
- constantEM, MAX_ARG);
+ luaM_growvector(f->consts, f->nconsts, 1, TObject, constantEM, MAX_ARG);
return f->nconsts++;
}
@@ -289,7 +288,7 @@ static void luaI_registerlocalvar (FuncState *fs, TaggedString *varname,
int line) {
if (fs->nvars != -1) { /* debug information? */
TProtoFunc *f = fs->f;
- f->locvars = luaM_growvector(f->locvars, fs->nvars, 1, LocVar, "", MAX_INT);
+ luaM_growvector(f->locvars, fs->nvars, 1, LocVar, "", MAX_INT);
f->locvars[fs->nvars].varname = varname;
f->locvars[fs->nvars].line = line;
fs->nvars++;
@@ -562,11 +561,11 @@ static void close_func (LexState *ls) {
TProtoFunc *f = fs->f;
code_opcode(ls, ENDCODE, 0);
f->code[0] = (Byte)fs->maxstacksize;
- f->code = luaM_reallocvector(f->code, fs->pc, Byte);
- f->consts = luaM_reallocvector(f->consts, f->nconsts, TObject);
+ luaM_reallocvector(f->code, fs->pc, Byte);
+ luaM_reallocvector(f->consts, f->nconsts, TObject);
if (fs->nvars != -1) { /* debug information? */
luaI_registerlocalvar(fs, NULL, -1); /* flag end of vector */
- f->locvars = luaM_reallocvector(f->locvars, fs->nvars, LocVar);
+ luaM_reallocvector(f->locvars, fs->nvars, LocVar);
}
ls->fs = fs->prev;
L->stack.top--; /* pop function */
diff --git a/ltm.c b/ltm.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltm.c,v 1.22 1999/02/25 15:16:26 roberto Exp roberto $
+** $Id: ltm.c,v 1.23 1999/02/25 19:13:56 roberto Exp roberto $
** Tag methods
** See Copyright Notice in lua.h
*/
@@ -59,8 +59,7 @@ static void init_entry (int tag) {
void luaT_init (void) {
int t;
L->last_tag = -(NUM_TAGS-1);
- L->IMtable = luaM_growvector(L->IMtable, 0, NUM_TAGS,
- struct IM, memEM, MAX_INT);
+ luaM_growvector(L->IMtable, 0, NUM_TAGS, struct IM, arrEM, MAX_INT);
for (t=L->last_tag; t<=0; t++)
init_entry(t);
}
@@ -68,8 +67,7 @@ void luaT_init (void) {
int lua_newtag (void) {
--L->last_tag;
- L->IMtable = luaM_growvector(L->IMtable, -(L->last_tag), 1,
- struct IM, memEM, MAX_INT);
+ luaM_growvector(L->IMtable, -(L->last_tag), 1, struct IM, arrEM, MAX_INT);
init_entry(L->last_tag);
return L->last_tag;
}