Read about our upcoming Code of Conduct on this issue

Commit 830c2ee9 authored by hudson@kremvax's avatar hudson@kremvax
Browse files

Fixes to build with Magic Lantern

parent 2aefc328d1ca
......@@ -20,7 +20,7 @@ MYLIBS=
# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris arm
LUA_A= liblua.a
CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
......@@ -36,7 +36,7 @@ LUAC_T= luac
LUAC_O= luac.o print.o
ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
ALL_T= $(LUA_A) #$(LUA_T) $(LUAC_T)
ALL_A= $(LUA_A)
default: $(PLAT)
......@@ -48,7 +48,8 @@ o: $(ALL_O)
a: $(ALL_A)
$(LUA_A): $(CORE_O) $(LIB_O)
$(AR) $@ $?
-$(RM) $@
$(AR) $@ $^
$(RANLIB) $@
$(LUA_T): $(LUA_O) $(LUA_A)
......@@ -115,6 +116,14 @@ posix:
solaris:
$(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl"
arm:
$(MAKE) \
all \
CC=/opt/local/bin/arm-elf-gcc-4.3.2 \
RANLIB=/opt/local/bin/arm-elf-ranlib \
MYCFLAGS="-DCONFIG_MAGICLANTERN=1" \
# list targets that do not create files (but not all makes understand .PHONY)
.PHONY: all $(PLATS) default o a clean depend echo none
......
......@@ -513,6 +513,9 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
#ifndef CONFIG_MAGICLANTERN
/* We have no file operations */
/*
** {======================================================
** Load functions
......@@ -588,6 +591,7 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
lua_remove(L, fnameindex);
return status;
}
#endif // !CONFIG_MAGICLANTERN
typedef struct LoadS {
......@@ -628,7 +632,8 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
(void)ud;
(void)osize;
if (nsize == 0) {
free(ptr);
if (ptr)
free(ptr);
return NULL;
}
else
......@@ -637,16 +642,32 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
static int panic (lua_State *L) {
#ifdef CONFIG_MAGICLANTERN
extern void bmp_printf( int, int, int, const char * fmt, ... );
DebugMsg( 50, 3,
"PANIC: unprotected error in call to Lua API (%s)",
lua_tostring(L, -1));
bmp_printf( 0, 0, 40,
"PANIC: unprotected error in call to Lua API (%s)\n",
lua_tostring(L, -1));
dumpf();
#else
(void)L; /* to avoid warnings */
fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n",
lua_tostring(L, -1));
#endif
return 0;
}
extern void DebugMsg(int,int,const char *fmt, ...);
LUALIB_API lua_State *luaL_newstate (void) {
DebugMsg(50,3,"%s:%d", __func__, __LINE__);
lua_State *L = lua_newstate(l_alloc, NULL);
DebugMsg(50,3,"%s:%d", __func__, __LINE__);
if (L) lua_atpanic(L, &panic);
DebugMsg(50,3,"%s:%d", __func__, __LINE__);
return L;
}
......@@ -9,8 +9,10 @@
#define lauxlib_h
#ifndef CONFIG_MAGICLANTERN
#include <stddef.h>
#include <stdio.h>
#endif
#include "lua.h"
......
......@@ -6,7 +6,14 @@
#include <ctype.h>
#ifdef CONFIG_MAGICLANTERN
static void * localeconv(void) { return 0; }
struct lconv {
char * decimal_point;
};
#else
#include <locale.h>
#endif
#include <string.h>
#define llex_c
......@@ -102,6 +109,7 @@ static const char *txtToken (LexState *ls, int token) {
void luaX_lexerror (LexState *ls, const char *msg, int token) {
char buff[MAXSRC];
luaO_chunkid(buff, getstr(ls->source), MAXSRC);
DebugMsg( 50, 3, "%s: %s:%d: %s", __func__, buff, ls->linenumber, msg);
msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg);
if (token)
luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token));
......
......@@ -330,10 +330,14 @@ static int ll_loadlib (lua_State *L) {
static int readable (const char *filename) {
#ifdef CONFIG_MAGICLANTERN
return -1;
#else
FILE *f = fopen(filename, "r"); /* try to open file */
if (f == NULL) return 0; /* open failed */
fclose(f);
return 1;
#endif
}
......
......@@ -142,7 +142,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
}
case 'p': {
char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */
sprintf(buff, "%p", va_arg(argp, void *));
snprintf(buff, sizeof(buff), "%p", va_arg(argp, void *));
pushstr(L, buff);
break;
}
......
......@@ -42,19 +42,30 @@ static int os_execute (lua_State *L) {
static int os_remove (lua_State *L) {
#ifdef CONFIG_MAGICLANTERN
return luaL_error(L, "remove not implemented");
#else
const char *filename = luaL_checkstring(L, 1);
return os_pushresult(L, remove(filename) == 0, filename);
#endif
}
static int os_rename (lua_State *L) {
#ifdef CONFIG_MAGICLANTERN
return luaL_error(L, "rename not implemented");
#else
const char *fromname = luaL_checkstring(L, 1);
const char *toname = luaL_checkstring(L, 2);
return os_pushresult(L, rename(fromname, toname) == 0, fromname);
#endif
}
static int os_tmpname (lua_State *L) {
#ifdef CONFIG_MAGICLANTERN
return luaL_error(L, "tmpname not implemented");
#else
char buff[LUA_TMPNAMBUFSIZE];
int err;
lua_tmpnam(buff, err);
......@@ -62,6 +73,7 @@ static int os_tmpname (lua_State *L) {
return luaL_error(L, "unable to generate a unique filename");
lua_pushstring(L, buff);
return 1;
#endif
}
......
......@@ -68,16 +68,26 @@ static void freestack (lua_State *L, lua_State *L1) {
** open parts that may cause memory-allocation errors
*/
static void f_luaopen (lua_State *L, void *ud) {
DEBUG();
global_State *g = G(L);
UNUSED(ud);
DEBUG();
stack_init(L, L); /* init stack */
DEBUG();
sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */
DEBUG();
sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */
DEBUG();
luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
DEBUG();
luaT_init(L);
DEBUG();
luaX_init(L);
DEBUG();
luaS_fix(luaS_newliteral(L, MEMERRMSG));
DEBUG();
g->GCthreshold = 4*g->totalbytes;
DEBUG();
}
......@@ -139,22 +149,30 @@ void luaE_freethread (lua_State *L, lua_State *L1) {
luaM_freemem(L, fromstate(L1), state_size(lua_State));
}
LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
DEBUG();
int i;
lua_State *L;
global_State *g;
void *l = (*f)(ud, NULL, 0, state_size(LG));
DEBUG();
if (l == NULL) return NULL;
L = tostate(l);
DEBUG();
g = &((LG *)L)->g;
L->next = NULL;
L->tt = LUA_TTHREAD;
DEBUG();
g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);
L->marked = luaC_white(g);
DEBUG();
set2bits(L->marked, FIXEDBIT, SFIXEDBIT);
DEBUG();
preinit_state(L, g);
DEBUG();
g->frealloc = f;
DEBUG();
g->ud = ud;
g->mainthread = L;
g->uvhead.u.l.prev = &g->uvhead;
......@@ -163,8 +181,11 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
g->strt.size = 0;
g->strt.nuse = 0;
g->strt.hash = NULL;
DEBUG();
setnilvalue(registry(L));
DEBUG();
luaZ_initbuffer(L, &g->buff);
DEBUG();
g->panic = NULL;
g->gcstate = GCSpause;
g->rootgc = obj2gco(L);
......@@ -179,13 +200,16 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
g->gcstepmul = LUAI_GCMUL;
g->gcdept = 0;
for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL;
DEBUG();
if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
DEBUG();
/* memory allocation error: free partial state */
close_state(L);
L = NULL;
}
else
luai_userstateopen(L);
DEBUG();
return L;
}
......
......@@ -772,22 +772,22 @@ static int str_format (lua_State *L) {
strfrmt = scanformat(L, strfrmt, form);
switch (*strfrmt++) {
case 'c': {
sprintf(buff, form, (int)luaL_checknumber(L, arg));
snprintf(buff, sizeof(buff), form, (int)luaL_checknumber(L, arg));
break;
}
case 'd': case 'i': {
addintlen(form);
sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg));
snprintf(buff, sizeof(buff), form, (LUA_INTFRM_T)luaL_checknumber(L, arg));
break;
}
case 'o': case 'u': case 'x': case 'X': {
addintlen(form);
sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
snprintf(buff, sizeof(buff), form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
break;
}
case 'e': case 'E': case 'f':
case 'g': case 'G': {
sprintf(buff, form, (double)luaL_checknumber(L, arg));
snprintf(buff, sizeof(buff), form, (double)luaL_checknumber(L, arg));
break;
}
case 'q': {
......@@ -805,7 +805,7 @@ static int str_format (lua_State *L) {
continue; /* skip the `addsize' at the end */
}
else {
sprintf(buff, form, s);
snprintf(buff, sizeof(buff), form, s);
break;
}
}
......
......@@ -485,7 +485,11 @@
/*
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
*/
#ifndef CONFIG_MAGICLANTERN
#define LUAL_BUFFERSIZE BUFSIZ
#else
#define LUAL_BUFFERSIZE 512
#endif
/* }================================================================== */
......@@ -520,7 +524,7 @@
*/
#define LUA_NUMBER_SCAN "%lf"
#define LUA_NUMBER_FMT "%.14g"
#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
#define lua_number2str(s,sz,n) snprintf((s), (sz), LUA_NUMBER_FMT, (n))
#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
#define lua_str2number(s,p) strtod((s), (p))
......@@ -617,9 +621,25 @@ union luai_Cast { double l_d; long l_l; };
#define luai_jmpbuf jmp_buf
#else
extern void DebugMsg(int,int,const char *,...);
#define DEBUG(fmt,...) DebugMsg(50,3,"%s:%d: " fmt, __func__, __LINE__, ## __VA_ARGS__)
/* default handling with long jumps */
#define LUAI_THROW(L,c) longjmp((c)->b, 1)
#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
#define LUAI_THROW(L,c) do { \
DEBUG("throw %08x", __builtin_return_address(0)); \
longjmp((c)->b, 1); \
} while(0)
#define LUAI_TRY(L,c,a) do { \
if (setjmp((c)->b) == 0) { \
DEBUG("try %08x", __builtin_return_address(0)); \
a \
} \
else \
DEBUG("catch %08x", __builtin_return_address(0)); \
} while(0)
#define luai_jmpbuf jmp_buf
#endif
......
......@@ -50,7 +50,7 @@ int luaV_tostring (lua_State *L, StkId obj) {
else {
char s[LUAI_MAXNUMBER2STR];
lua_Number n = nvalue(obj);
lua_number2str(s, n);
lua_number2str(s, sizeof(s), n);
setsvalue2s(L, obj, luaS_new(L, s));
return 1;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment