rev 202 - in trunk: include/prothon modules/File src

SVN User <[email protected]>
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-03-29 23:06:07 -0500 (Mon, 29 Mar 2004)
New Revision: 202

Modified:
   trunk/include/prothon/prothon.h
   trunk/modules/File/File.c
   trunk/src/console.c
Log:
Fixed bug 6, console crashed on unused stack entries

Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h	2004-03-30 02:55:33 UTC (rev 201)
+++ trunk/include/prothon/prothon.h	2004-03-30 04:06:07 UTC (rev 202)
@@ -88,7 +88,7 @@
 //#define TRACE_PARSER
 //#define TRACE_INTERPRETER
 //#define DUMP_MODULE_CODE
-//#define DUMP_OBJECTS_AT_END
+#define DUMP_OBJECTS_AT_END
 
 //************************* BASIC TYPE DEFINITIONS ********************************
 

Modified: trunk/modules/File/File.c
===================================================================
--- trunk/modules/File/File.c	2004-03-30 02:55:33 UTC (rev 201)
+++ trunk/modules/File/File.c	2004-03-30 04:06:07 UTC (rev 202)
@@ -187,11 +187,19 @@
 }
 
 DEF(FILE_PROTO, closed, NULL) { 
+	if (!has_proto(ist, self, FILE_PROTO)) {
+		raise_exception(ist, OBJ(TYPE_EXC), "closed can only be called on a File object");
+		return NULL;
+	}
 	if (OPEN(self)) return OBJ(PR_FALSE);
 	else			return OBJ(PR_TRUE);
 }
 
 DEF(FILE_PROTO, flush, NULL) { 
+	if (!has_proto(ist, self, FILE_PROTO)) {
+		raise_exception(ist, OBJ(TYPE_EXC), "flush can only be called on a File object");
+		return NULL;
+	}
 	if (!OPEN(self)) {
 		raise_exception(ist, OBJ(IOEXCEPTION), "flush called on closed file");
 		return NULL;
@@ -204,6 +212,10 @@
 }
 #if 0
 DEF(FILE_PROTO, fileno, NULL) { 
+	if (!has_proto(ist, self, FILE_PROTO)) {
+		raise_exception(ist, OBJ(TYPE_EXC), "fileno can only be called on a File object");
+		return NULL;
+	}
 	if (!OPEN(self)) {
 		raise_exception(ist, OBJ(IOEXCEPTION), "fileno called on closed file");
 		return NULL;
@@ -234,6 +246,10 @@
 		raise_exception(ist, OBJ(TYPE_EXC), "file read size parameter must be an integer");
 		return NULL;
 	}
+	if (!has_proto(ist, self, FILE_PROTO)) {
+		raise_exception(ist, OBJ(TYPE_EXC), "read can only be called on a File object");
+		return NULL;
+	}
 	if (!OPEN(self)) {
 		raise_exception(ist, OBJ(IOEXCEPTION), "read called on closed file");
 		return NULL;
@@ -310,6 +326,10 @@
 		raise_exception(ist, OBJ(TYPE_EXC), "file read size parameter must be an integer");
 		return NULL;
 	}
+	if (!has_proto(ist, self, FILE_PROTO)) {
+		raise_exception(ist, OBJ(TYPE_EXC), "readline can only be called on a File object");
+		return NULL;
+	}
 	if (!OPEN(self)) {
 		raise_exception(ist, OBJ(IOEXCEPTION), "readline called on closed file");
 		return NULL;
@@ -384,6 +404,10 @@
 		raise_exception(ist, OBJ(TYPE_EXC), "file read size parameter must be an integer");
 		return NULL;
 	}
+	if (!has_proto(ist, self, FILE_PROTO)) {
+		raise_exception(ist, OBJ(TYPE_EXC), "readlines can only be called on a File object");
+		return NULL;
+	}
 	if (!OPEN(self)) {
 		raise_exception(ist, OBJ(IOEXCEPTION), "readlines called on closed file");
 		return NULL;
@@ -467,6 +491,10 @@
 		raise_exception(ist, OBJ(TYPE_EXC), "file seek how parameter must be an integer");
 		return NULL;
 	}
+	if (!has_proto(ist, self, FILE_PROTO)) {
+		raise_exception(ist, OBJ(TYPE_EXC), "seek can only be called on a File object");
+		return NULL;
+	}
 	if (!OPEN(self)) {
 		raise_exception(ist, OBJ(IOEXCEPTION), "seek called on closed file");
 		return NULL;
@@ -507,6 +535,10 @@
 		raise_exception(ist, OBJ(TYPE_EXC), "file truncate size parameter must be an integer");
 		return NULL;
 	}
+	if (!has_proto(ist, self, FILE_PROTO)) {
+		raise_exception(ist, OBJ(TYPE_EXC), "truncate can only be called on a File object");
+		return NULL;
+	}
 	if (!OPEN(self)) {
 		raise_exception(ist, OBJ(IOEXCEPTION), "truncate called on closed file");
 		return NULL;
@@ -539,6 +571,10 @@
 		raise_exception(ist, OBJ(TYPE_EXC), "file write str parameter must be a string");
 		return NULL;
 	}
+	if (!has_proto(ist, self, FILE_PROTO)) {
+		raise_exception(ist, OBJ(TYPE_EXC), "write can only be called on a File object");
+		return NULL;
+	}
 	if (!OPEN(self)) {
 		raise_exception(ist, OBJ(IOEXCEPTION), "write called on closed file");
 		return NULL;
@@ -569,6 +605,10 @@
 		raise_exception(ist, OBJ(TYPE_EXC), "file writelines parameter must be a sequence or a string");
 		return NULL;
 	}
+	if (!has_proto(ist, self, FILE_PROTO)) {
+		raise_exception(ist, OBJ(TYPE_EXC), "writelines can only be called on a File object");
+		return NULL;
+	}
 	if (!OPEN(self)) {
 		raise_exception(ist, OBJ(IOEXCEPTION), "write called on closed file");
 		return NULL;

Modified: trunk/src/console.c
===================================================================
--- trunk/src/console.c	2004-03-30 02:55:33 UTC (rev 201)
+++ trunk/src/console.c	2004-03-30 04:06:07 UTC (rev 202)
@@ -227,10 +227,12 @@
 		} else {
 			if (res && res != OBJ(NONE)) {
 				char* res_str = as_str(ist, res);
-				if (res_str[strlen(res_str)-1] == '\n')
-					printf("%s", res_str);
-				else
-					printf("%s\n",res_str);
+				if (res_str) {
+					if (res_str[strlen(res_str)-1] == '\n')
+						printf("%s", res_str);
+					else
+						printf("%s\n",res_str);
+				}
 			}
 		}
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.