code cleaner for 16 bits.

This commit is contained in:
Roberto Ierusalimschy 2000-05-24 10:54:49 -03:00
parent 5c2dd7a9e0
commit ef62b340e0
31 changed files with 247 additions and 199 deletions

6
lapi.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 1.79 2000/05/08 19:32:53 roberto Exp roberto $
** $Id: lapi.c,v 1.80 2000/05/08 20:49:05 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@ -250,7 +250,7 @@ const char *lua_getstring (lua_State *L, lua_Object obj) {
else return (svalue(obj));
}
long lua_strlen (lua_State *L, lua_Object obj) {
size_t lua_strlen (lua_State *L, lua_Object obj) {
if (obj == LUA_NOOBJECT || tostring(L, obj))
return 0L;
else return (tsvalue(obj)->u.s.len);
@ -281,7 +281,7 @@ void lua_pushnumber (lua_State *L, double n) {
incr_top;
}
void lua_pushlstring (lua_State *L, const char *s, long len) {
void lua_pushlstring (lua_State *L, const char *s, size_t len) {
tsvalue(L->top) = luaS_newlstr(L, s, len);
ttype(L->top) = TAG_STRING;
incr_top;

View File

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.26 2000/02/08 16:34:31 roberto Exp roberto $
** $Id: lauxlib.c,v 1.27 2000/03/30 17:19:48 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -51,18 +51,20 @@ static void type_error (lua_State *L, int narg, const char *type_name,
}
static const char *checkstr (lua_State *L, lua_Object o, int narg, long *len) {
static const char *checkstr (lua_State *L, lua_Object o, int narg,
size_t *len) {
const char *s = lua_getstring(L, o);
if (!s) type_error(L, narg, "string", o);
if (len) *len = lua_strlen(L, o);
return s;
}
const char *luaL_check_lstr (lua_State *L, int narg, long *len) {
const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) {
return checkstr(L, lua_getparam(L, narg), narg, len);
}
const char *luaL_opt_lstr (lua_State *L, int narg, const char *def, long *len) {
const char *luaL_opt_lstr (lua_State *L, int narg, const char *def,
size_t *len) {
lua_Object o = lua_getparam(L, narg);
if (o == LUA_NOOBJECT) {
if (len) *len = def ? strlen(def) : 0;

View File

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.h,v 1.16 1999/12/03 11:26:23 roberto Exp roberto $
** $Id: lauxlib.h,v 1.17 1999/12/29 16:24:03 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -9,6 +9,8 @@
#define lauxlib_h
#include <stddef.h>
#include "lua.h"
@ -20,26 +22,28 @@ struct luaL_reg {
void luaL_openlib (lua_State *L, const struct luaL_reg *l, int n);
void luaL_argerror (lua_State *L, int numarg, const char *extramsg);
const char *luaL_check_lstr (lua_State *L, int numArg, long *len);
const char *luaL_opt_lstr (lua_State *L, int numArg, const char *def, long *len);
const char *luaL_check_lstr (lua_State *L, int numArg, size_t *len);
const char *luaL_opt_lstr (lua_State *L, int numArg, const char *def,
size_t *len);
double luaL_check_number (lua_State *L, int numArg);
double luaL_opt_number (lua_State *L, int numArg, double def);
lua_Object luaL_functionarg (lua_State *L, int arg);
lua_Object luaL_tablearg (lua_State *L, int arg);
lua_Object luaL_nonnullarg (lua_State *L, int numArg);
void luaL_verror (lua_State *L, const char *fmt, ...);
char *luaL_openspace (lua_State *L, int size);
void luaL_resetbuffer (lua_State *L);
void luaL_addchar (lua_State *L, int c);
int luaL_getsize (lua_State *L);
void luaL_addsize (lua_State *L, int n);
int luaL_newbuffer (lua_State *L, int size);
void luaL_oldbuffer (lua_State *L, int old);
char *luaL_buffer (lua_State *L);
int luaL_findstring (const char *name, const char *const list[]);
void luaL_chunkid (char *out, const char *source, int len);
void luaL_filesource (char *out, const char *filename, int len);
char *luaL_openspace (lua_State *L, size_t size);
void luaL_resetbuffer (lua_State *L);
void luaL_addchar (lua_State *L, int c);
size_t luaL_getsize (lua_State *L);
void luaL_addsize (lua_State *L, size_t n);
size_t luaL_newbuffer (lua_State *L, size_t size);
void luaL_oldbuffer (lua_State *L, size_t old);
char *luaL_buffer (lua_State *L);
#ifdef LUA_REENTRANT

View File

@ -1,5 +1,5 @@
/*
** $Id: lbuffer.c,v 1.11 1999/11/22 13:12:07 roberto Exp roberto $
** $Id: lbuffer.c,v 1.12 2000/03/03 14:58:26 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -25,16 +25,17 @@
#define EXTRABUFF 32
#define openspace(L, size) if (L->Mbuffnext+(size) > L->Mbuffsize) \
#define openspace(L, size) if ((size_t)(size) > L->Mbuffsize-L->Mbuffnext) \
Openspace(L, size)
static void Openspace (lua_State *L, int size) {
L->Mbuffsize = (L->Mbuffnext+size+EXTRABUFF)*2;
luaM_reallocvector(L, L->Mbuffer, L->Mbuffsize, char);
static void Openspace (lua_State *L, size_t size) {
lint32 newsize = ((lint32)L->Mbuffnext+size+EXTRABUFF)*2;
luaM_reallocvector(L, L->Mbuffer, newsize, char);
L->Mbuffsize = newsize;
}
char *luaL_openspace (lua_State *L, int size) {
char *luaL_openspace (lua_State *L, size_t size) {
openspace(L, size);
return L->Mbuffer+L->Mbuffnext;
}
@ -51,23 +52,23 @@ void luaL_resetbuffer (lua_State *L) {
}
void luaL_addsize (lua_State *L, int n) {
void luaL_addsize (lua_State *L, size_t n) {
L->Mbuffnext += n;
}
int luaL_getsize (lua_State *L) {
size_t luaL_getsize (lua_State *L) {
return L->Mbuffnext-L->Mbuffbase;
}
int luaL_newbuffer (lua_State *L, int size) {
int old = L->Mbuffbase;
size_t luaL_newbuffer (lua_State *L, size_t size) {
size_t old = L->Mbuffbase;
openspace(L, size);
L->Mbuffbase = L->Mbuffnext;
return old;
}
void luaL_oldbuffer (lua_State *L, int old) {
void luaL_oldbuffer (lua_State *L, size_t old) {
L->Mbuffnext = L->Mbuffbase;
L->Mbuffbase = old;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lbuiltin.c,v 1.108 2000/05/08 19:32:53 roberto Exp roberto $
** $Id: lbuiltin.c,v 1.109 2000/05/09 14:50:16 roberto Exp roberto $
** Built-in functions
** See Copyright Notice in lua.h
*/
@ -273,7 +273,7 @@ static void passresults (lua_State *L) {
}
void luaB_dostring (lua_State *L) {
long l;
size_t l;
const char *s = luaL_check_lstr(L, 1, &l);
if (*s == ID_CHUNK)
lua_error(L, "`dostring' cannot run pre-compiled code");
@ -633,7 +633,6 @@ static const struct luaL_reg builtin_funcs[] = {
void luaB_predefine (lua_State *L) {
/* pre-register mem error messages, to avoid loop when error arises */
luaS_newfixed(L, tableEM);
luaS_newfixed(L, memEM);
luaL_openl(L, builtin_funcs);
#ifdef DEBUG

View File

@ -1,5 +1,5 @@
/*
** $Id: lcode.c,v 1.30 2000/05/15 19:48:04 roberto Exp roberto $
** $Id: lcode.c,v 1.31 2000/05/22 18:44:46 roberto Exp roberto $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@ -107,7 +107,8 @@ static int real_constant (FuncState *fs, Number r) {
while (--c >= lim)
if (f->knum[c] == r) return c;
/* not found; create a new entry */
luaM_growvector(fs->L, f->knum, f->nknum, 1, Number, constantEM, MAXARG_U);
luaM_growvector(fs->L, f->knum, f->nknum, 1, Number,
"constant table overflow", MAXARG_U);
c = f->nknum++;
f->knum[c] = r;
return c;
@ -567,7 +568,8 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
case iAB: i = CREATE_AB(o, arg1, arg2); break;
}
/* actually create the new instruction */
luaM_growvector(fs->L, fs->f->code, fs->pc, 1, Instruction, codeEM, MAX_INT);
luaM_growvector(fs->L, fs->f->code, fs->pc, 1, Instruction,
"code size overflow", MAX_INT);
fs->f->code[fs->pc] = i;
return fs->pc++;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: ldblib.c,v 1.14 2000/05/08 13:21:35 roberto Exp roberto $
** $Id: ldblib.c,v 1.15 2000/05/12 19:49:18 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@ -49,7 +49,7 @@ static void getinfo (lua_State *L) {
const char *options = luaL_opt_string(L, 2, "flnSu");
char buff[20];
if (lua_isnumber(L, func)) {
if (!lua_getstack(L, lua_getnumber(L, func), &ar)) {
if (!lua_getstack(L, (int)lua_getnumber(L, func), &ar)) {
lua_pushnil(L); /* level out of range */
return;
}

9
ldo.c
View File

@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 1.74 2000/05/08 19:32:53 roberto Exp roberto $
** $Id: ldo.c,v 1.75 2000/05/09 14:50:16 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@ -311,7 +311,9 @@ static int do_main (lua_State *L, ZIO *z, int bin) {
int status;
int debug = L->debug; /* save debug status */
do {
long old_blocks = (luaC_checkGC(L), L->nblocks);
unsigned long old_blocks;
luaC_checkGC(L);
old_blocks = L->nblocks;
status = protectedparser(L, z, bin);
if (status == 1) return 1; /* error */
else if (status == 2) return 0; /* `natural' end */
@ -358,7 +360,8 @@ int lua_dostring (lua_State *L, const char *str) {
}
int lua_dobuffer (lua_State *L, const char *buff, int size, const char *name) {
int lua_dobuffer (lua_State *L, const char *buff, size_t size,
const char *name) {
ZIO z;
if (!name) name = "?";
luaZ_mopen(&z, buff, size, name);

View File

@ -1,5 +1,5 @@
/*
** $Id: lfunc.c,v 1.20 2000/03/10 18:37:44 roberto Exp roberto $
** $Id: lfunc.c,v 1.21 2000/03/29 20:19:20 roberto Exp roberto $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/
@ -20,7 +20,7 @@
Closure *luaF_newclosure (lua_State *L, int nelems) {
Closure *c = (Closure *)luaM_malloc(L, sizeof(Closure) +
sizeof(TObject)*(nelems-1));
(lint32)sizeof(TObject)*(nelems-1));
c->next = L->rootcl;
L->rootcl = c;
c->marked = 0;

4
lgc.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lgc.c,v 1.49 2000/05/10 16:33:20 roberto Exp roberto $
** $Id: lgc.c,v 1.50 2000/05/11 18:57:19 roberto Exp roberto $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@ -193,7 +193,7 @@ static void collectstringtab (lua_State *L, int limit, stringtable *tb) {
}
}
}
if (tb->nuse < (tb->size/4) && tb->size > 10)
if (tb->nuse < (lint32)(tb->size/4) && tb->size > 10)
luaS_resize(L, tb, tb->size/2); /* table is too big */
}

View File

@ -1,5 +1,5 @@
/*
** $Id: liolib.c,v 1.62 2000/04/24 21:05:11 roberto Exp roberto $
** $Id: liolib.c,v 1.63 2000/05/09 14:50:16 roberto Exp roberto $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@ -322,19 +322,23 @@ static void read_word (lua_State *L, FILE *f) {
static int read_line (lua_State *L, FILE *f) {
int n;
char *b;
do {
for (;;) {
b = luaL_openspace(L, HUNK_LINE);
if (!fgets(b, HUNK_LINE, f)) return 0; /* read fails */
n = strlen(b);
luaL_addsize(L, n);
} while (b[n-1] != '\n');
luaL_addsize(L, -1); /* remove '\n' */
if (b[n-1] != '\n')
luaL_addsize(L, n);
else {
luaL_addsize(L, n-1); /* do not add the `\n' */
break;
}
}
return 1;
}
static void read_file (lua_State *L, FILE *f) {
int n;
size_t n;
do {
char *b = luaL_openspace(L, HUNK_FILE);
n = fread(b, sizeof(char), HUNK_FILE, f);
@ -343,9 +347,9 @@ static void read_file (lua_State *L, FILE *f) {
}
static int read_chars (lua_State *L, FILE *f, int n) {
static int read_chars (lua_State *L, FILE *f, size_t n) {
char *b = luaL_openspace(L, n);
int n1 = fread(b, sizeof(char), n, f);
size_t n1 = fread(b, sizeof(char), n, f);
luaL_addsize(L, n1);
return (n == n1);
}
@ -357,11 +361,11 @@ static void io_read (lua_State *L) {
FILE *f = getfileparam(L, ctrl, &arg, INFILE);
lua_Object op = lua_getparam(L, arg);
do { /* repeat for each part */
long l;
size_t l;
int success;
luaL_resetbuffer(L);
if (lua_isnumber(L, op))
success = read_chars(L, f, (int)lua_getnumber(L, op));
success = read_chars(L, f, (size_t)lua_getnumber(L, op));
else {
const char *p = luaL_opt_string(L, arg, "*l");
if (p[0] != '*')
@ -409,9 +413,9 @@ static void io_write (lua_State *L) {
status = status && fprintf(f, "%.16g", lua_getnumber(L, o)) > 0;
}
else {
long l;
size_t l;
const char *s = luaL_check_lstr(L, arg, &l);
status = status && ((long)fwrite(s, sizeof(char), l, f) == l);
status = status && (fwrite(s, sizeof(char), l, f) == l);
}
arg++;
}

13
llex.c
View File

@ -1,5 +1,5 @@
/*
** $Id: llex.c,v 1.57 2000/04/12 18:57:19 roberto Exp roberto $
** $Id: llex.c,v 1.58 2000/05/08 19:32:53 roberto Exp roberto $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@ -49,6 +49,16 @@ void luaX_init (lua_State *L) {
#define MAXSRC 80
void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) {
if (val > limit) {
char buff[100];
sprintf(buff, "too many %.50s (limit=%d)", msg, limit);
luaX_error(ls, buff, ls->token);
}
}
void luaX_syntaxerror (LexState *ls, const char *s, const char *token) {
char buff[MAXSRC];
luaL_chunkid(buff, zname(ls->z), sizeof(buff));
@ -175,6 +185,7 @@ static void inclinenumber (lua_State *L, LexState *LS) {
{"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL};
next(LS); /* skip '\n' */
++LS->linenumber;
luaX_checklimit(LS, LS->linenumber, MAX_INT, "lines in a chunk");
if (LS->current == '$') { /* is a pragma? */
char buff[PRAGMASIZE+1];
int ifnot = 0;

3
llex.h
View File

@ -1,5 +1,5 @@
/*
** $Id: llex.h,v 1.23 2000/04/07 13:11:49 roberto Exp roberto $
** $Id: llex.h,v 1.24 2000/04/12 18:57:19 roberto Exp roberto $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@ -63,6 +63,7 @@ typedef struct LexState {
void luaX_init (lua_State *L);
void luaX_setinput (lua_State *L, LexState *LS, ZIO *z);
int luaX_lex (LexState *LS);
void luaX_checklimit (LexState *ls, int val, int limit, const char *msg);
void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
void luaX_error (LexState *ls, const char *s, int token);
void luaX_token2str (int token, char *s);

View File

@ -1,5 +1,5 @@
/*
** $Id: llimits.h,v 1.5 2000/04/04 20:48:44 roberto Exp roberto $
** $Id: llimits.h,v 1.6 2000/04/26 13:43:25 roberto Exp roberto $
** Limits, basic types, and some other "instalation-dependent" definitions
** See Copyright Notice in lua.h
*/
@ -9,6 +9,7 @@
#include <limits.h>
#include <stddef.h>
/*
@ -22,6 +23,11 @@
typedef LUA_NUM_TYPE Number;
typedef unsigned long lint32; /* unsigned int with at least 32 bits */
#define MAX_SIZET ((size_t)(~0)-2)
#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */

15
lmem.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lmem.c,v 1.28 2000/03/10 18:37:44 roberto Exp roberto $
** $Id: lmem.c,v 1.29 2000/03/16 20:35:07 roberto Exp roberto $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
@ -88,6 +88,7 @@ static void *debug_realloc (void *block, size_t size) {
size_t realsize = HEADER+size+MARKSIZE;
char *newblock = (char *)(malloc)(realsize); /* alloc a new block */
int i;
if (realsize < size) return NULL; /* overflow! */
if (newblock == NULL) return NULL;
if (block) {
size_t oldsize = *blocksize(block);
@ -111,10 +112,10 @@ static void *debug_realloc (void *block, size_t size) {
void *luaM_growaux (lua_State *L, void *block, unsigned long nelems,
int inc, int size, const char *errormsg, unsigned long limit) {
unsigned long newn = nelems+inc;
if (newn >= limit) lua_error(L, errormsg);
void *luaM_growaux (lua_State *L, void *block, size_t nelems,
int inc, size_t size, const char *errormsg, size_t limit) {
size_t newn = nelems+inc;
if (nelems >= limit-inc) lua_error(L, errormsg);
if ((newn ^ nelems) <= nelems || /* still the same power-of-2 limit? */
(nelems > 0 && newn < MINPOWER2)) /* or block already is MINPOWER2? */
return block; /* do not need to reallocate */
@ -126,12 +127,12 @@ void *luaM_growaux (lua_State *L, void *block, unsigned long nelems,
/*
** generic allocation routine.
*/
void *luaM_realloc (lua_State *L, void *block, unsigned long size) {
void *luaM_realloc (lua_State *L, void *block, lint32 size) {
if (size == 0) {
free(block); /* block may be NULL; that is OK for free */
return NULL;
}
else if ((size_t)size != size)
else if (size >= MAX_SIZET)
lua_error(L, "memory allocation error: block too big");
block = realloc(block, size);
if (block == NULL)

28
lmem.h
View File

@ -1,5 +1,5 @@
/*
** $Id: lmem.h,v 1.12 2000/01/13 16:30:47 roberto Exp roberto $
** $Id: lmem.h,v 1.13 2000/03/16 20:35:07 roberto Exp roberto $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
@ -8,29 +8,29 @@
#define lmem_h
#include <stdlib.h>
#include <stddef.h>
#include "llimits.h"
#include "lua.h"
/* memory error messages */
#define codeEM "code size overflow"
#define constantEM "constant table overflow"
#define refEM "reference table overflow"
#define tableEM "table overflow"
/* memory error message */
#define memEM "not enough memory"
#define arrEM "internal array larger than `int' limit"
void *luaM_realloc (lua_State *L, void *oldblock, unsigned long size);
void *luaM_growaux (lua_State *L, void *block, unsigned long nelems, int inc, int size,
const char *errormsg, unsigned long limit);
void *luaM_realloc (lua_State *L, void *oldblock, lint32 size);
void *luaM_growaux (lua_State *L, void *block, size_t nelems,
int inc, size_t size, const char *errormsg,
size_t limit);
#define luaM_free(L, b) luaM_realloc(L, (b), 0)
#define luaM_free(L, b) luaM_realloc(L, (b), 0)
#define luaM_malloc(L, t) luaM_realloc(L, NULL, (t))
#define luaM_new(L, t) ((t *)luaM_malloc(L, sizeof(t)))
#define luaM_newvector(L, n,t) ((t *)luaM_malloc(L, (n)*sizeof(t)))
#define luaM_newvector(L, n,t) ((t *)luaM_malloc(L, (n)*(lint32)sizeof(t)))
#define luaM_growvector(L, v,nelems,inc,t,e,l) \
((v)=(t *)luaM_growaux(L, v,nelems,inc,sizeof(t),e,l))
#define luaM_reallocvector(L, v,n,t) ((v)=(t *)luaM_realloc(L, v,(n)*sizeof(t)))
#define luaM_reallocvector(L, v,n,t) \
((v)=(t *)luaM_realloc(L, v,(n)*(lint32)sizeof(t)))
#ifdef DEBUG

View File

@ -1,5 +1,5 @@
/*
** $Id: lobject.c,v 1.37 2000/04/25 16:55:09 roberto Exp roberto $
** $Id: lobject.c,v 1.38 2000/04/26 13:43:10 roberto Exp roberto $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@ -25,8 +25,8 @@ const TObject luaO_nilobject = {TAG_NIL, {NULL}};
/*
** returns smaller power of 2 larger than `n' (minimum is MINPOWER2)
*/
unsigned long luaO_power2 (unsigned long n) {
unsigned long p = MINPOWER2;
lint32 luaO_power2 (lint32 n) {
lint32 p = MINPOWER2;
while (p<=n) p<<=1;
return p;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lobject.h,v 1.63 2000/05/08 19:37:10 roberto Exp roberto $
** $Id: lobject.h,v 1.64 2000/05/10 16:33:20 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@ -92,7 +92,7 @@ typedef struct TString {
union {
struct { /* for strings */
unsigned long hash;
long len;
size_t len;
int constindex; /* hint to reuse constants */
} s;
struct { /* for userdata */
@ -170,10 +170,9 @@ extern const TObject luaO_nilobject;
#define luaO_typename(o) luaO_typenames[ttype(o)]
unsigned long luaO_power2 (unsigned long n);
lint32 luaO_power2 (lint32 n);
int luaO_equalObj (const TObject *t1, const TObject *t2);
int luaO_redimension (lua_State *L, int oldsize);
int luaO_str2d (const char *s, Number *result);

View File

@ -1,5 +1,5 @@
/*
** $Id: lparser.c,v 1.87 2000/05/15 19:48:04 roberto Exp roberto $
** $Id: lparser.c,v 1.88 2000/05/22 18:44:46 roberto Exp roberto $
** LL(1) Parser and code generator for Lua
** See Copyright Notice in lua.h
*/
@ -79,19 +79,10 @@ static void check (LexState *ls, int c) {
}
static void checklimit (LexState *ls, int val, int limit, const char *msg) {
if (val > limit) {
char buff[100];
sprintf(buff, "too many %.50s (limit=%d)", msg, limit);
luaK_error(ls, buff);
}
}
static void setline (LexState *ls) {
FuncState *fs = ls->fs;
if (ls->L->debug && ls->linenumber != fs->lastsetline) {
checklimit(ls, ls->linenumber, MAXARG_U, "lines in a chunk");
luaX_checklimit(ls, ls->linenumber, MAXARG_U, "lines in a chunk");
luaK_code1(fs, OP_SETLINE, ls->linenumber);
fs->lastsetline = ls->linenumber;
}
@ -142,7 +133,7 @@ static int string_constant (FuncState *fs, TString *s) {
int c = s->u.s.constindex;
if (c >= f->nkstr || f->kstr[c] != s) {
luaM_growvector(fs->L, f->kstr, f->nkstr, 1, TString *,
constantEM, MAXARG_U);
"constant table overflow", MAXARG_U);
c = f->nkstr++;
f->kstr[c] = s;
s->u.s.constindex = c; /* hint for next time */
@ -200,7 +191,7 @@ static void luaI_unregisterlocalvar (LexState *ls, int line) {
static void store_localvar (LexState *ls, TString *name, int n) {
FuncState *fs = ls->fs;
checklimit(ls, fs->nlocalvar+n+1, MAXLOCALS, "local variables");
luaX_checklimit(ls, fs->nlocalvar+n+1, MAXLOCALS, "local variables");
fs->localvar[fs->nlocalvar+n] = name;
}
@ -266,7 +257,7 @@ static int indexupvalue (LexState *ls, TString *n) {
}
/* new one */
++(fs->nupvalues);
checklimit(ls, fs->nupvalues, MAXUPVALUES, "upvalues");
luaX_checklimit(ls, fs->nupvalues, MAXUPVALUES, "upvalues");
fs->upvalues[i] = v; /* i = fs->nupvalues - 1 */
return i;
}
@ -306,7 +297,7 @@ static void adjust_mult_assign (LexState *ls, int nvars, int nexps) {
static void code_args (LexState *ls, int nparams, int dots) {
FuncState *fs = ls->fs;
adjustlocalvars(ls, nparams);
checklimit(ls, fs->nlocalvar, MAXPARAMS, "parameters");
luaX_checklimit(ls, fs->nlocalvar, MAXPARAMS, "parameters");
nparams = fs->nlocalvar; /* `self' could be there already */
fs->f->numparams = nparams;
fs->f->is_vararg = dots;
@ -369,7 +360,7 @@ static void func_onstack (LexState *ls, FuncState *func) {
for (i=0; i<func->nupvalues; i++)
luaK_tostack(ls, &func->upvalues[i], 1);
luaM_growvector(ls->L, f->kproto, f->nkproto, 1, Proto *,
constantEM, MAXARG_A);
"constant table overflow", MAXARG_A);
f->kproto[f->nkproto++] = func->f;
luaK_code2(fs, OP_CLOSURE, f->nkproto-1, func->nupvalues);
}
@ -623,8 +614,8 @@ static int listfields (LexState *ls) {
break;
exp1(ls);
n++;
checklimit(ls, n, MAXARG_A*LFIELDS_PER_FLUSH,
"items in a list initializer");
luaX_checklimit(ls, n/LFIELDS_PER_FLUSH, MAXARG_A,
"`item groups' in a list initializer");
if (++mod_n == LFIELDS_PER_FLUSH) {
luaK_code2(fs, OP_SETLIST, n/LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH);
mod_n = 0;
@ -697,6 +688,7 @@ static void constructor (LexState *ls) {
}
check_match(ls, '}', '{', line);
/* set initial table size */
luaX_checklimit(ls, nelems, MAXARG_U, "elements in a table constructor");
SETARG_U(fs->f->code[pc], nelems);
}
@ -846,7 +838,7 @@ static void block (LexState *ls) {
static int assignment (LexState *ls, expdesc *v, int nvars) {
int left = 0;
checklimit(ls, nvars, MAXVARSLH, "variables in a multiple assignment");
luaX_checklimit(ls, nvars, MAXVARSLH, "variables in a multiple assignment");
if (ls->token == ',') { /* assignment -> ',' NAME assignment */
expdesc nv;
next(ls);

5
lref.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lref.c,v 1.10 2000/03/27 20:10:21 roberto Exp roberto $
** $Id: lref.c,v 1.11 2000/03/29 20:19:20 roberto Exp roberto $
** reference mechanism
** See Copyright Notice in lua.h
*/
@ -25,7 +25,8 @@ int lua_ref (lua_State *L, int lock) {
L->refFree = L->refArray[ref].st;
}
else { /* no more free places */
luaM_growvector(L, L->refArray, L->refSize, 1, struct Ref, refEM, MAX_INT);
luaM_growvector(L, L->refArray, L->refSize, 1, struct Ref,
"reference table overflow", MAX_INT);
ref = L->refSize++;
}
L->refArray[ref].o = *(L->top-1);

View File

@ -1,5 +1,5 @@
/*
** $Id: lstate.h,v 1.32 2000/05/08 19:32:53 roberto Exp roberto $
** $Id: lstate.h,v 1.33 2000/05/10 16:33:20 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@ -42,7 +42,7 @@ struct C_Lua_Stack {
typedef struct stringtable {
int size;
long nuse; /* number of elements */
lint32 nuse; /* number of elements */
TString **hash;
} stringtable;
@ -57,9 +57,9 @@ struct lua_State {
struct C_Lua_Stack Cstack; /* C2lua struct */
struct lua_longjmp *errorJmp; /* current error recover point */
char *Mbuffer; /* global buffer */
int Mbuffbase; /* current first position of Mbuffer */
int Mbuffsize; /* size of Mbuffer */
int Mbuffnext; /* next position to fill in Mbuffer */
size_t Mbuffbase; /* current first position of Mbuffer */
size_t Mbuffsize; /* size of Mbuffer */
size_t Mbuffnext; /* next position to fill in Mbuffer */
struct C_Lua_Stack *Cblocks;
int numCblocks; /* number of nested Cblocks */
/* global state */

View File

@ -1,5 +1,5 @@
/*
** $Id: lstring.c,v 1.35 2000/05/08 19:32:53 roberto Exp roberto $
** $Id: lstring.c,v 1.36 2000/05/10 16:33:20 roberto Exp roberto $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@ -34,10 +34,10 @@ void luaS_freeall (lua_State *L) {
}
static unsigned long hash_s (const char *s, long l) {
static unsigned long hash_s (const char *s, size_t l) {
unsigned long h = l; /* seed */
long step = (l>>6)+1; /* if string is too long, don't hash all its chars */
for (; l>0; l-=step)
size_t step = (l>>6)|1; /* if string is too long, don't hash all its chars */
for (; l>=step; l-=step)
h = h ^ ((h<<5)+(h>>2)+(unsigned char)*(s++));
return h;
}
@ -71,13 +71,13 @@ static void newentry (lua_State *L, stringtable *tb, TString *ts, int h) {
ts->nexthash = tb->hash[h]; /* chain new entry */
tb->hash[h] = ts;
tb->nuse++;
if (tb->nuse > tb->size && tb->size < MAX_INT/2) /* too crowded? */
if (tb->nuse > (lint32)tb->size && tb->size < MAX_INT/2) /* too crowded? */
luaS_resize(L, tb, tb->size*2);
}
TString *luaS_newlstr (lua_State *L, const char *str, long l) {
TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
unsigned long h = hash_s(str, l);
int h1 = h&(L->strt.size-1);
TString *ts;
@ -86,7 +86,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, long l) {
return ts;
}
/* not found */
ts = (TString *)luaM_malloc(L, sizeof(TString)+l*sizeof(char));
ts = (TString *)luaM_malloc(L, sizeof(TString)+(lint32)l*sizeof(char));
ts->marked = 0;
ts->nexthash = NULL;
ts->u.s.len = l;

View File

@ -1,5 +1,5 @@
/*
** $Id: lstring.h,v 1.19 2000/05/08 19:32:53 roberto Exp roberto $
** $Id: lstring.h,v 1.20 2000/05/10 16:33:20 roberto Exp roberto $
** String table (keep all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@ -28,7 +28,7 @@ void luaS_init (lua_State *L);
void luaS_resize (lua_State *L, stringtable *tb, int newsize);
TString *luaS_createudata (lua_State *L, void *udata, int tag);
void luaS_freeall (lua_State *L);
TString *luaS_newlstr (lua_State *L, const char *str, long l);
TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
TString *luaS_new (lua_State *L, const char *str);
TString *luaS_newfixed (lua_State *L, const char *str);

View File

@ -1,11 +1,12 @@
/*
** $Id: lstrlib.c,v 1.41 2000/03/03 14:58:26 roberto Exp roberto $
** $Id: lstrlib.c,v 1.42 2000/05/02 18:32:22 roberto Exp roberto $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
*/
#include <ctype.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -18,7 +19,7 @@
static void addnchar (lua_State *L, const char *s, int n) {
static void addnchar (lua_State *L, const char *s, size_t n) {
char *b = luaL_openspace(L, n);
memcpy(b, s, n);
luaL_addsize(L, n);
@ -26,7 +27,7 @@ static void addnchar (lua_State *L, const char *s, int n) {
static void str_len (lua_State *L) {
long l;
size_t l;
luaL_check_lstr(L, 1, &l);
lua_pushnumber(L, l);
}
@ -37,19 +38,19 @@ static void closeandpush (lua_State *L) {
}
static long posrelat (long pos, long len) {
static long posrelat (long pos, size_t len) {
/* relative string position: negative means back from end */
return (pos>=0) ? pos : len+pos+1;
return (pos>=0) ? pos : (long)len+pos+1;
}
static void str_sub (lua_State *L) {
long l;
size_t l;
const char *s = luaL_check_lstr(L, 1, &l);
long start = posrelat(luaL_check_long(L, 2), l);
long end = posrelat(luaL_opt_long(L, 3, -1), l);
if (start < 1) start = 1;
if (end > l) end = l;
if (end > (long)l) end = l;
if (start <= end)
lua_pushlstring(L, s+start-1, end-start+1);
else lua_pushstring(L, "");
@ -57,8 +58,8 @@ static void str_sub (lua_State *L) {
static void str_lower (lua_State *L) {
long l;
int i;
size_t l;
size_t i;
const char *s = luaL_check_lstr(L, 1, &l);
luaL_resetbuffer(L);
for (i=0; i<l; i++)
@ -68,8 +69,8 @@ static void str_lower (lua_State *L) {
static void str_upper (lua_State *L) {
long l;
int i;
size_t l;
size_t i;
const char *s = luaL_check_lstr(L, 1, &l);
luaL_resetbuffer(L);
for (i=0; i<l; i++)
@ -78,7 +79,7 @@ static void str_upper (lua_State *L) {
}
static void str_rep (lua_State *L) {
long l;
size_t l;
const char *s = luaL_check_lstr(L, 1, &l);
int n = luaL_check_int(L, 2);
luaL_resetbuffer(L);
@ -89,10 +90,10 @@ static void str_rep (lua_State *L) {
static void str_byte (lua_State *L) {
long l;
size_t l;
const char *s = luaL_check_lstr(L, 1, &l);
long pos = posrelat(luaL_opt_long(L, 2, 1), l);
luaL_arg_check(L, 0<pos && pos<=l, 2, "out of range");
luaL_arg_check(L, 0<pos && (size_t)pos<=l, 2, "out of range");
lua_pushnumber(L, (unsigned char)s[pos-1]);
}
@ -126,7 +127,7 @@ struct Capture {
int level; /* total number of captures (finished or unfinished) */
struct {
const char *init;
int len; /* -1 signals unfinished capture */
long len; /* -1 signals unfinished capture */
} capture[MAX_CAPTURES];
};
@ -238,7 +239,8 @@ int luaI_singlematch (int c, const char *p, const char *ep) {
}
static const char *match (lua_State *L, const char *s, const char *p, struct Capture *cap);
static const char *match (lua_State *L, const char *s, const char *p,
struct Capture *cap);
static const char *matchbalance (lua_State *L, const char *s, const char *p,
@ -261,9 +263,9 @@ static const char *matchbalance (lua_State *L, const char *s, const char *p,
}
static const char *max_expand (lua_State *L, const char *s, const char *p, const char *ep,
struct Capture *cap) {
int i = 0; /* counts maximum expand for item */
static const char *max_expand (lua_State *L, const char *s, const char *p,
const char *ep, struct Capture *cap) {
long i = 0; /* counts maximum expand for item */
while ((s+i)<cap->src_end && luaI_singlematch((unsigned char)*(s+i), p, ep))
i++;
/* keeps trying to match mith the maximum repetitions */
@ -276,8 +278,8 @@ static const char *max_expand (lua_State *L, const char *s, const char *p, const
}
static const char *min_expand (lua_State *L, const char *s, const char *p, const char *ep,
struct Capture *cap) {
static const char *min_expand (lua_State *L, const char *s, const char *p,
const char *ep, struct Capture *cap) {
for (;;) {
const char *res = match(L, s, ep+1, cap);
if (res != NULL)
@ -317,15 +319,16 @@ static const char *end_capture (lua_State *L, const char *s, const char *p,
static const char *match_capture (lua_State *L, const char *s, int level,
struct Capture *cap) {
int l = check_capture(L, level, cap);
int len = cap->capture[l].len;
if (cap->src_end-s >= len &&
size_t len = cap->capture[l].len;
if ((size_t)(cap->src_end-s) >= len &&
memcmp(cap->capture[l].init, s, len) == 0)
return s+len;
else return NULL;
}
static const char *match (lua_State *L, const char *s, const char *p, struct Capture *cap) {
static const char *match (lua_State *L, const char *s, const char *p,
struct Capture *cap) {
init: /* using goto's to optimize tail recursion */
switch (*p) {
case '(': /* start capture */
@ -397,12 +400,12 @@ static const char *memfind (const char *s1, long l1, const char *s2, long l2) {
static void str_find (lua_State *L) {
long l1, l2;
size_t l1, l2;
const char *s = luaL_check_lstr(L, 1, &l1);
const char *p = luaL_check_lstr(L, 2, &l2);
long init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1;
struct Capture cap;
luaL_arg_check(L, 0 <= init && init <= l1, 3, "out of range");
luaL_arg_check(L, 0 <= init && (size_t)init <= l1, 3, "out of range");
if (lua_getparam(L, 4) != LUA_NOOBJECT ||
strpbrk(p, SPECIALS) == NULL) { /* no special characters? */
const char *s2 = memfind(s+init, l1-init, p, l2);
@ -434,8 +437,8 @@ static void str_find (lua_State *L) {
static void add_s (lua_State *L, lua_Object newp, struct Capture *cap) {
if (lua_isstring(L, newp)) {
const char *news = lua_getstring(L, newp);
int l = lua_strlen(L, newp);
int i;
size_t l = lua_strlen(L, newp);
size_t i;
for (i=0; i<l; i++) {
if (news[i] != ESC)
luaL_addchar(L, news[i]);
@ -453,7 +456,7 @@ static void add_s (lua_State *L, lua_Object newp, struct Capture *cap) {
else { /* is a function */
lua_Object res;
int status;
int oldbuff;
size_t oldbuff;
lua_beginblock(L);
push_captures(L, cap);
/* function may use buffer, so save it and create a new one */
@ -474,7 +477,7 @@ static void add_s (lua_State *L, lua_Object newp, struct Capture *cap) {
static void str_gsub (lua_State *L) {
long srcl;
size_t srcl;
const char *src = luaL_check_lstr(L, 1, &srcl);
const char *p = luaL_check_string(L, 2);
lua_Object newp = lua_getparam(L, 3);
@ -510,7 +513,7 @@ static void str_gsub (lua_State *L) {
static void luaI_addquoted (lua_State *L, int arg) {
long l;
size_t l;
const char *s = luaL_check_lstr(L, arg, &l);
luaL_addchar(L, '"');
while (l--) {
@ -573,7 +576,7 @@ static void str_format (lua_State *L) {
luaI_addquoted(L, arg);
continue; /* skip the "addsize" at the end */
case 's': {
long l;
size_t l;
const char *s = luaL_check_lstr(L, arg, &l);
if (cap.capture[1].len == 0 && l >= 100) {
/* no precision and string is too long to be formatted;

View File

@ -1,5 +1,5 @@
/*
** $Id: ltable.c,v 1.41 2000/05/08 19:32:53 roberto Exp roberto $
** $Id: ltable.c,v 1.42 2000/05/11 18:57:19 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@ -122,10 +122,12 @@ int luaH_pos (lua_State *L, const Hash *t, const TObject *key) {
}
static void setnodevector (lua_State *L, Hash *t, int size) {
static void setnodevector (lua_State *L, Hash *t, lint32 size) {
int i;
if (size > MAX_INT)
lua_error(L, "table overflow");
t->node = luaM_newvector(L, size, Node);
for (i=0; i<size; i++) {
for (i=0; i<(int)size; i++) {
ttype(&t->node[i].key) = ttype(&t->node[i].val) = TAG_NIL;
t->node[i].next = NULL;
}
@ -153,7 +155,7 @@ void luaH_free (lua_State *L, Hash *t) {
}
static int newsize (const Hash *t) {
static int numuse (const Hash *t) {
Node *v = t->node;
int size = t->size;
int realuse = 0;
@ -162,16 +164,24 @@ static int newsize (const Hash *t) {
if (ttype(&v[i].val) != TAG_NIL)
realuse++;
}
return luaO_power2(realuse+realuse/4+1);
return realuse;
}
static void rehash (lua_State *L, Hash *t) {
int oldsize = t->size;
Node *nold = t->node;
int newsize = numuse(t);
int i;
LUA_ASSERT(L, newsize<=oldsize, "wrong count");
if (newsize >= oldsize-oldsize/4) /* using more than 3/4? */
setnodevector(L, t, (lint32)oldsize*2);
else if (newsize <= oldsize/4 && /* less than 1/4? */
oldsize > MINPOWER2)
setnodevector(L, t, oldsize/2);
else
setnodevector(L, t, oldsize);
L->nblocks -= gcsize(L, oldsize);
setnodevector(L, t, newsize(t)); /* create new array of nodes */
for (i=0; i<oldsize; i++) {
Node *old = nold+i;
if (ttype(&old->val) != TAG_NIL)
@ -249,3 +259,4 @@ void luaH_setint (lua_State *L, Hash *t, int key, const TObject *val) {
const TObject *luaH_getglobal (lua_State *L, const char *name) {
return luaH_getstr(L->gt, luaS_new(L, name));
}

7
ltm.c
View File

@ -1,5 +1,5 @@
/*
** $Id: ltm.c,v 1.38 2000/03/29 20:19:20 roberto Exp roberto $
** $Id: ltm.c,v 1.39 2000/03/30 16:41:51 roberto Exp roberto $
** Tag methods
** See Copyright Notice in lua.h
*/
@ -67,7 +67,7 @@ static void init_entry (lua_State *L, int tag) {
void luaT_init (lua_State *L) {
int t;
L->last_tag = NUM_TAGS-1;
luaM_growvector(L, L->IMtable, 0, NUM_TAGS, struct IM, arrEM, MAX_INT);
luaM_growvector(L, L->IMtable, 0, NUM_TAGS, struct IM, "", MAX_INT);
for (t=0; t<=L->last_tag; t++)
init_entry(L, t);
}
@ -75,7 +75,8 @@ void luaT_init (lua_State *L) {
int lua_newtag (lua_State *L) {
++L->last_tag;
luaM_growvector(L, L->IMtable, L->last_tag, 1, struct IM, arrEM, MAX_INT);
luaM_growvector(L, L->IMtable, L->last_tag, 1, struct IM,
"tag table overflow", MAX_INT);
init_entry(L, L->last_tag);
return L->last_tag;
}

15
lua.h
View File

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.51 2000/05/09 14:50:16 roberto Exp roberto $
** $Id: lua.h,v 1.52 2000/05/10 16:35:18 roberto Exp roberto $
** Lua - An Extensible Extension Language
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
** e-mail: lua@tecgraf.puc-rio.br
@ -11,6 +11,11 @@
#ifndef lua_h
#define lua_h
/* definition of `size_t' */
#include <stddef.h>
#define LUA_VERSION "Lua 4.0 (alpha)"
#define LUA_COPYRIGHT "Copyright (C) 1994-2000 TeCGraf, PUC-Rio"
#define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
@ -50,8 +55,8 @@ int lua_dofile (lua_State *L, const char *filename);
/* Out: returns */
int lua_dostring (lua_State *L, const char *str);
/* Out: returns */
int lua_dobuffer (lua_State *L, const char *buff, int size,
const char *name); /* Out: returns */
int lua_dobuffer (lua_State *L, const char *buff, size_t size,
const char *name); /* Out: returns */
int lua_callfunction (lua_State *L, lua_Object f);
/* In: parameters; Out: returns */
@ -79,14 +84,14 @@ int lua_equal (lua_State *L, lua_Object o1, lua_Object o2);
double lua_getnumber (lua_State *L, lua_Object obj);
const char *lua_getstring (lua_State *L, lua_Object obj);
long lua_strlen (lua_State *L, lua_Object obj);
size_t lua_strlen (lua_State *L, lua_Object obj);
lua_CFunction lua_getcfunction (lua_State *L, lua_Object obj);
void *lua_getuserdata (lua_State *L, lua_Object obj);
void lua_pushnil (lua_State *L);
void lua_pushnumber (lua_State *L, double n);
void lua_pushlstring (lua_State *L, const char *s, long len);
void lua_pushlstring (lua_State *L, const char *s, size_t len);
void lua_pushstring (lua_State *L, const char *s);
void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
void lua_pushusertag (lua_State *L, void *u, int tag);

34
lvm.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lvm.c,v 1.106 2000/05/15 19:48:04 roberto Exp roberto $
** $Id: lvm.c,v 1.107 2000/05/22 18:44:46 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -187,7 +187,7 @@ void luaV_setglobal (lua_State *L, TString *s, StkId top) {
const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL);
if (ttype(im) == TAG_NIL) { /* is there a tag method? */
if (oldvalue != &luaO_nilobject)
*oldvalue = *(top-1);
*(TObject *)oldvalue = *(top-1);
else {
TObject key;
ttype(&key) = TAG_STRING;
@ -239,21 +239,22 @@ static void addK (lua_State *L, StkId top, int k) {
static int luaV_strcomp (const TString *ls, const TString *rs) {
const char *l = ls->str;
long ll = ls->u.s.len;
size_t ll = ls->u.s.len;
const char *r = rs->str;
long lr = rs->u.s.len;
size_t lr = rs->u.s.len;
for (;;) {
long temp = strcoll(l, r);
int temp = strcoll(l, r);
if (temp != 0) return temp;
/* strings are equal up to a '\0' */
temp = strlen(l); /* index of first '\0' in both strings */
if (temp == ll) /* l is finished? */
return (temp == lr) ? 0 : -1; /* l is equal or smaller than r */
else if (temp == lr) /* r is finished? */
return 1; /* l is greater than r (because l is not finished) */
/* both strings longer than temp; go on comparing (after the '\0') */
temp++;
l += temp; ll -= temp; r += temp; lr -= temp;
else { /* strings are equal up to a '\0' */
size_t len = strlen(l); /* index of first '\0' in both strings */
if (len == ll) /* l is finished? */
return (len == lr) ? 0 : -1; /* l is equal or smaller than r */
else if (len == lr) /* r is finished? */
return 1; /* l is greater than r (because l is not finished) */
/* both strings longer than `len'; go on comparing (after the '\0') */
len++;
l += len; ll -= len; r += len; lr -= len;
}
}
}
@ -281,17 +282,18 @@ static void strconc (lua_State *L, int total, StkId top) {
call_binTM(L, top, IM_CONCAT, "unexpected type for concatenation");
else if (tsvalue(top-1)->u.s.len > 0) { /* if len=0, do nothing */
/* at least two string values; get as many as possible */
long tl = tsvalue(top-1)->u.s.len + tsvalue(top-2)->u.s.len;
lint32 tl = tsvalue(top-1)->u.s.len + tsvalue(top-2)->u.s.len;
char *buffer;
int i;
while (n < total && !tostring(L, top-n-1)) { /* collect total length */
tl += tsvalue(top-n-1)->u.s.len;
n++;
}
if (tl > MAX_SIZET) lua_error(L, "string size overflow");
buffer = luaL_openspace(L, tl);
tl = 0;
for (i=n; i>0; i--) { /* concat all strings */
long l = tsvalue(top-i)->u.s.len;
lint32 l = tsvalue(top-i)->u.s.len;
memcpy(buffer+tl, tsvalue(top-i)->str, l);
tl += l;
}

10
lzio.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lzio.c,v 1.10 2000/02/08 16:39:42 roberto Exp roberto $
** $Id: lzio.c,v 1.11 2000/03/03 14:58:26 roberto Exp roberto $
** a generic input stream interface
** See Copyright Notice in lua.h
*/
@ -21,7 +21,7 @@ static int zmfilbuf (ZIO* z) {
}
ZIO* zmopen (ZIO* z, const char* b, int size, const char *name) {
ZIO* zmopen (ZIO* z, const char* b, size_t size, const char *name) {
if (b==NULL) return NULL;
z->n = size;
z->p = (const unsigned char *)b;
@ -41,7 +41,7 @@ ZIO* zsopen (ZIO* z, const char* s, const char *name) {
/* -------------------------------------------------------------- FILEs --- */
static int zffilbuf (ZIO* z) {
int n;
size_t n;
if (feof((FILE *)z->u)) return EOZ;
n = fread(z->buffer, 1, ZBSIZE, (FILE *)z->u);
if (n==0) return EOZ;
@ -63,9 +63,9 @@ ZIO* zFopen (ZIO* z, FILE* f, const char *name) {
/* --------------------------------------------------------------- read --- */
int zread (ZIO *z, void *b, int n) {
size_t zread (ZIO *z, void *b, size_t n) {
while (n) {
int m;
size_t m;
if (z->n == 0) {
if (z->filbuf(z) == EOZ)
return n; /* return number of missing bytes */

10
lzio.h
View File

@ -1,5 +1,5 @@
/*
** $Id: lzio.h,v 1.4 1998/01/09 14:57:43 roberto Exp roberto $
** $Id: lzio.h,v 1.5 1999/08/16 20:52:00 roberto Exp roberto $
** Buffered streams
** See Copyright Notice in lua.h
*/
@ -24,11 +24,11 @@ typedef struct zio ZIO;
ZIO* zFopen (ZIO* z, FILE* f, const char *name); /* open FILEs */
ZIO* zsopen (ZIO* z, const char* s, const char *name); /* string */
ZIO* zmopen (ZIO* z, const char* b, int size, const char *name); /* memory */
ZIO* zmopen (ZIO* z, const char* b, size_t size, const char *name); /* memory */
int zread (ZIO* z, void* b, int n); /* read next n bytes */
size_t zread (ZIO* z, void* b, size_t n); /* read next n bytes */
#define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z))
#define zgetc(z) (((z)->n--)>0 ? ((int)*(z)->p++): (z)->filbuf(z))
#define zungetc(z) (++(z)->n,--(z)->p)
#define zname(z) ((z)->name)
@ -38,7 +38,7 @@ int zread (ZIO* z, void* b, int n); /* read next n bytes */
#define ZBSIZE 256 /* buffer size */
struct zio {
int n; /* bytes still unread */
size_t n; /* bytes still unread */
const unsigned char* p; /* current position in buffer */
int (*filbuf)(ZIO* z);
void* u; /* additional data */

View File

@ -1,4 +1,4 @@
% $Id: manual.tex,v 1.37 2000/05/12 19:19:18 roberto Exp roberto $
% $Id: manual.tex,v 1.38 2000/05/12 19:49:18 roberto Exp roberto $
\documentclass[11pt]{article}
\usepackage{fullpage,bnf}
@ -122,7 +122,7 @@ Waldemar Celes
\tecgraf\ --- Computer Science Department --- PUC-Rio
}
\date{{\small \tt\$Date: 2000/05/12 19:19:18 $ $}}
\date{{\small \tt\$Date: 2000/05/12 19:49:18 $ $}}
\maketitle
@ -1695,7 +1695,7 @@ you can use the following conversion functions:
\begin{verbatim}
double lua_getnumber (lua_Object object);
const char *lua_getstring (lua_Object object);
long lua_strlen (lua_Object object);
size_t lua_strlen (lua_Object object);
lua_CFunction lua_getcfunction (lua_Object object);
void *lua_getuserdata (lua_Object object);
\end{verbatim}
@ -1765,7 +1765,7 @@ is done with the following functions:
\Deffunc{lua_pushuserdata}\label{pushing}
\begin{verbatim}
void lua_pushnumber (double n);
void lua_pushlstring (const char *s, long len);
void lua_pushlstring (const char *s, size_t len);
void lua_pushstring (const char *s);
void lua_pushusertag (void *u, int tag);
void lua_pushnil (void);
@ -1864,7 +1864,7 @@ using the following functions:%
\begin{verbatim}
int lua_dofile (const char *filename);
int lua_dostring (const char *string);
int lua_dobuffer (const char *buff, int size, const char *name);
int lua_dobuffer (const char *buff, size_t size, const char *name);
\end{verbatim}
All these functions return an error code:
0, in case of success; non zero, in case of errors.