summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-04-15 14:32:47 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-04-15 14:32:47 -0300
commit209602ac31512c9f201d11edca6fe7aa368b85a4 (patch)
tree878c569fdbae1e867ed420da8d0e2e54e7fe4c98
parent6251d889ca96dc9c3219f5908b706cd4ca053259 (diff)
downloadlua-209602ac31512c9f201d11edca6fe7aa368b85a4.tar.gz
lua-209602ac31512c9f201d11edca6fe7aa368b85a4.tar.bz2
lua-209602ac31512c9f201d11edca6fe7aa368b85a4.zip
BUG: input file must be closed just after parser.
-rw-r--r--inout.c11
-rw-r--r--opcode.c24
2 files changed, 15 insertions, 20 deletions
diff --git a/inout.c b/inout.c
index 8332c257..6b3e490f 100644
--- a/inout.c
+++ b/inout.c
@@ -5,7 +5,7 @@
5** Also provides some predefined lua functions. 5** Also provides some predefined lua functions.
6*/ 6*/
7 7
8char *rcs_inout="$Id: inout.c,v 2.56 1997/04/06 14:08:08 roberto Exp roberto $"; 8char *rcs_inout="$Id: inout.c,v 2.57 1997/04/06 14:14:27 roberto Exp roberto $";
9 9
10#include <stdio.h> 10#include <stdio.h>
11#include <string.h> 11#include <string.h>
@@ -68,8 +68,6 @@ FILE *lua_openfile (char *fn)
68 } 68 }
69 else 69 else
70 fp = fopen (fn, "r"); 70 fp = fopen (fn, "r");
71 if (fp == NULL)
72 return NULL;
73 lua_parsedfile = luaI_createfixedstring(fn)->str; 71 lua_parsedfile = luaI_createfixedstring(fn)->str;
74 return fp; 72 return fp;
75} 73}
@@ -79,11 +77,8 @@ FILE *lua_openfile (char *fn)
79*/ 77*/
80void lua_closefile (void) 78void lua_closefile (void)
81{ 79{
82 if (fp != NULL && fp != stdin) 80 if (fp != stdin)
83 { 81 fclose(fp);
84 fclose (fp);
85 fp = NULL;
86 }
87} 82}
88 83
89/* 84/*
diff --git a/opcode.c b/opcode.c
index 2b1c02f8..77b680d6 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 4.1 1997/04/03 18:27:06 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 4.2 1997/04/04 22:24:51 roberto Exp roberto $";
7 7
8#include <setjmp.h> 8#include <setjmp.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -554,7 +554,7 @@ int luaI_dorun (TFunc *tf)
554 return status; 554 return status;
555} 555}
556 556
557static int do_protectedmain (void) 557static int do_protectedmain (lua_CFunction closef)
558{ 558{
559 TFunc tf; 559 TFunc tf;
560 int status; 560 int status;
@@ -563,16 +563,17 @@ static int do_protectedmain (void)
563 errorJmp = &myErrorJmp; 563 errorJmp = &myErrorJmp;
564 luaI_initTFunc(&tf); 564 luaI_initTFunc(&tf);
565 tf.fileName = lua_parsedfile; 565 tf.fileName = lua_parsedfile;
566 if (setjmp(myErrorJmp) == 0) 566 if (setjmp(myErrorJmp) == 0) {
567 {
568 lua_parse(&tf); 567 lua_parse(&tf);
569 status = luaI_dorun(&tf); 568 status = 0;
570 } 569 }
571 else 570 else {
572 {
573 status = 1;
574 adjustC(0); /* erase extra slot */ 571 adjustC(0); /* erase extra slot */
572 status = 1;
575 } 573 }
574 closef();
575 if (status == 0)
576 status = luaI_dorun(&tf);
576 errorJmp = oldErr; 577 errorJmp = oldErr;
577 luaI_free(tf.code); 578 luaI_free(tf.code);
578 return status; 579 return status;
@@ -620,13 +621,13 @@ int lua_dofile (char *filename)
620 if (c == ID_CHUNK) { 621 if (c == ID_CHUNK) {
621 f = freopen(filename, "rb", f); /* set binary mode */ 622 f = freopen(filename, "rb", f); /* set binary mode */
622 status = luaI_undump(f); 623 status = luaI_undump(f);
624 lua_closefile();
623 } 625 }
624 else { 626 else {
625 if (c == '#') 627 if (c == '#')
626 while ((c=fgetc(f)) != '\n') /* skip first line */; 628 while ((c=fgetc(f)) != '\n') /* skip first line */;
627 status = do_protectedmain(); 629 status = do_protectedmain(lua_closefile);
628 } 630 }
629 lua_closefile();
630 return status; 631 return status;
631} 632}
632 633
@@ -640,8 +641,7 @@ int lua_dostring (char *str)
640 if (str == NULL) 641 if (str == NULL)
641 return 1; 642 return 1;
642 lua_openstring(str); 643 lua_openstring(str);
643 status = do_protectedmain(); 644 status = do_protectedmain(lua_closestring);
644 lua_closestring();
645 return status; 645 return status;
646} 646}
647 647