BUG: input file must be closed just after parser.
This commit is contained in:
9
inout.c
9
inout.c
@@ -5,7 +5,7 @@
|
|||||||
** Also provides some predefined lua functions.
|
** Also provides some predefined lua functions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_inout="$Id: inout.c,v 2.56 1997/04/06 14:08:08 roberto Exp roberto $";
|
char *rcs_inout="$Id: inout.c,v 2.57 1997/04/06 14:14:27 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -68,8 +68,6 @@ FILE *lua_openfile (char *fn)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
fp = fopen (fn, "r");
|
fp = fopen (fn, "r");
|
||||||
if (fp == NULL)
|
|
||||||
return NULL;
|
|
||||||
lua_parsedfile = luaI_createfixedstring(fn)->str;
|
lua_parsedfile = luaI_createfixedstring(fn)->str;
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
@@ -79,11 +77,8 @@ FILE *lua_openfile (char *fn)
|
|||||||
*/
|
*/
|
||||||
void lua_closefile (void)
|
void lua_closefile (void)
|
||||||
{
|
{
|
||||||
if (fp != NULL && fp != stdin)
|
if (fp != stdin)
|
||||||
{
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
fp = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
24
opcode.c
24
opcode.c
@@ -3,7 +3,7 @@
|
|||||||
** TecCGraf - PUC-Rio
|
** TecCGraf - PUC-Rio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_opcode="$Id: opcode.c,v 4.1 1997/04/03 18:27:06 roberto Exp roberto $";
|
char *rcs_opcode="$Id: opcode.c,v 4.2 1997/04/04 22:24:51 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -554,7 +554,7 @@ int luaI_dorun (TFunc *tf)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_protectedmain (void)
|
static int do_protectedmain (lua_CFunction closef)
|
||||||
{
|
{
|
||||||
TFunc tf;
|
TFunc tf;
|
||||||
int status;
|
int status;
|
||||||
@@ -563,16 +563,17 @@ static int do_protectedmain (void)
|
|||||||
errorJmp = &myErrorJmp;
|
errorJmp = &myErrorJmp;
|
||||||
luaI_initTFunc(&tf);
|
luaI_initTFunc(&tf);
|
||||||
tf.fileName = lua_parsedfile;
|
tf.fileName = lua_parsedfile;
|
||||||
if (setjmp(myErrorJmp) == 0)
|
if (setjmp(myErrorJmp) == 0) {
|
||||||
{
|
|
||||||
lua_parse(&tf);
|
lua_parse(&tf);
|
||||||
status = luaI_dorun(&tf);
|
status = 0;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
status = 1;
|
|
||||||
adjustC(0); /* erase extra slot */
|
adjustC(0); /* erase extra slot */
|
||||||
|
status = 1;
|
||||||
}
|
}
|
||||||
|
closef();
|
||||||
|
if (status == 0)
|
||||||
|
status = luaI_dorun(&tf);
|
||||||
errorJmp = oldErr;
|
errorJmp = oldErr;
|
||||||
luaI_free(tf.code);
|
luaI_free(tf.code);
|
||||||
return status;
|
return status;
|
||||||
@@ -620,13 +621,13 @@ int lua_dofile (char *filename)
|
|||||||
if (c == ID_CHUNK) {
|
if (c == ID_CHUNK) {
|
||||||
f = freopen(filename, "rb", f); /* set binary mode */
|
f = freopen(filename, "rb", f); /* set binary mode */
|
||||||
status = luaI_undump(f);
|
status = luaI_undump(f);
|
||||||
|
lua_closefile();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (c == '#')
|
if (c == '#')
|
||||||
while ((c=fgetc(f)) != '\n') /* skip first line */;
|
while ((c=fgetc(f)) != '\n') /* skip first line */;
|
||||||
status = do_protectedmain();
|
status = do_protectedmain(lua_closefile);
|
||||||
}
|
}
|
||||||
lua_closefile();
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -640,8 +641,7 @@ int lua_dostring (char *str)
|
|||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
lua_openstring(str);
|
lua_openstring(str);
|
||||||
status = do_protectedmain();
|
status = do_protectedmain(lua_closestring);
|
||||||
lua_closestring();
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user