rev 310 - in trunk: include/prothon modules/File pr src

SVN User <[email protected]>
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-04-09 16:20:30 -0400 (Fri, 09 Apr 2004)
New Revision: 310

Modified:
   trunk/include/prothon/prothon.h
   trunk/modules/File/File.c
   trunk/pr/stdio_test.pr
   trunk/src/object.c
   trunk/src/src.vcproj
Log:
Fixed stdio_test.pr by adding File.set_stdout() to 
avoid having to modify File directly which is a 
permission violation.

Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h	2004-04-09 20:08:30 UTC (rev 309)
+++ trunk/include/prothon/prothon.h	2004-04-09 20:20:30 UTC (rev 310)
@@ -927,10 +927,34 @@
 void del_lock  (obj_p obj);		
 void del_unlock(obj_p obj);
 
-// SU, UN_SU: get super_user access,  restore normal access
+//************************** ACCESS PERMISSION ********************************
+// Every thread as an access level defined at any one time.  The access levels are
+// ACC_GUEST, ACC_USER1, ACC_USER2, & ACC_SYSTEM.  System can read or write any
+// object and guest can do very little.  User2 is the normal programming level 
+// and main module threads start out at this level.
+// Each object has an access level set for read access and write access.  The
+// thread must match the read level to read_lock the object or a read access
+// exception will be thrown and the the thread level must likewise match the 
+// write level to write_lock the object or a write access exception will occur.
+// The C code can change any levels at any time, but the programmer should
+// follow the access logic rules to keep the security tight.
+
+// SU, UN_SU: get super_user access for thread,  restore normal access
+// A temp int variable must be available to save the current level.
+// Use this to temporarily access things like Object attributes.
+// DO NOT FORGET AND LEAVE ACCESS OPEN.
 #define su(save_int)    ((save_int) = ist->access, ist->access = ACC_SYSTEM)
 #define un_su(save_int) (ist->access = (save_int))
 
+// XET_OBJ_XXACC: get/set object access
+// Get or set read or write access level of an object
+// Use constants ACC_GUEST, ACC_USER1, ACC_USER2, & ACC_SYSTEM for access param.
+void set_obj_rdacc(obj_p obj, int access);
+void set_obj_wracc(obj_p obj, int access);
+int get_obj_rdacc(obj_p obj);
+int get_obj_wracc(obj_p obj);
+
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/modules/File/File.c
===================================================================
--- trunk/modules/File/File.c	2004-04-09 20:08:30 UTC (rev 309)
+++ trunk/modules/File/File.c	2004-04-09 20:20:30 UTC (rev 310)
@@ -671,6 +671,17 @@
 	return parms[1];
 }
 
+DEF(File, set_stdout, FORM_RPARAM) {
+	int i;
+	if (!has_proto_QUES(ist, parms[1], File_OBJ)) {
+		raise_exception(ist, OBJ(TYPE_EXC), "stdout can only be assigned to a file object");
+		return NULL;
+	}
+	su(i);  read_unlock(ist, self);
+	set_attr(ist, self, sym(ist, "stdout"), parms[1]);
+	un_su(i); read_lock(ist, self);
+	return parms[1];
+}
 
 MODULE_START(Dir)
 {
@@ -752,6 +763,7 @@
 	MODULE_ADD_SYM(File, truncate);
 	MODULE_ADD_SYM(File, write);
 	MODULE_ADD_SYM(File, writelines);
+	MODULE_ADD_SYM(File, set_stdout);
 
 	MODULE_SUB_INIT(Dir);
 	MODULE_ADD_SYM(Dir, __objlist__);

Modified: trunk/pr/stdio_test.pr
===================================================================
--- trunk/pr/stdio_test.pr	2004-04-09 20:08:30 UTC (rev 309)
+++ trunk/pr/stdio_test.pr	2004-04-09 20:20:30 UTC (rev 310)
@@ -16,6 +16,6 @@
 
 print "Opening test file for stdout"
 
-File.stdout = File("stdout.txt", "w+")
+File.set_stdout(File("stdout.txt", "w+"))
 stdout.write("Should still go to stdout\n")
 File.stdout.write("Should go to stdout.txt file\n")

Modified: trunk/src/object.c
===================================================================
--- trunk/src/object.c	2004-04-09 20:08:30 UTC (rev 309)
+++ trunk/src/object.c	2004-04-09 20:20:30 UTC (rev 310)
@@ -282,6 +282,39 @@
 	free_wrlock(obj);
 }
 
+//********************************* set_obj_rdacc *****************************
+void set_obj_rdacc(obj_p obj, int access) {
+	get_wrlock(obj, NO_WAIT);
+	obj->rd_access = access; 
+	free_wrlock(obj);
+}
+
+//********************************* set_obj_wracc *****************************
+void set_obj_wracc(obj_p obj, int access) {
+	get_wrlock(obj, NO_WAIT);
+	obj->wr_access = access; 
+	free_wrlock(obj);
+}
+
+//********************************* get_obj_rdacc *****************************
+int get_obj_rdacc(obj_p obj) {
+	int res;
+	get_wrlock(obj, NO_WAIT);
+	res = obj->rd_access;
+	free_wrlock(obj);
+	return res;
+}
+
+//********************************* get_obj_wracc *****************************
+int get_obj_wracc(obj_p obj) {
+	int res;
+	get_wrlock(obj, NO_WAIT);
+	res = obj->wr_access;
+	free_wrlock(obj);
+	return res;
+}
+
+
 //********************************* raise_exception ***************************
 void raise_exception(isp ist, obj_p proto_obj, const char *format, ...)
 {

Modified: trunk/src/src.vcproj
===================================================================
--- trunk/src/src.vcproj	2004-04-09 20:08:30 UTC (rev 309)
+++ trunk/src/src.vcproj	2004-04-09 20:20:30 UTC (rev 310)
@@ -280,6 +280,9 @@
 				RelativePath="..\status.txt">
 			</File>
 			<File
+				RelativePath="..\pr\stdio_test.pr">
+			</File>
+			<File
 				RelativePath="..\pr\test.pr">
 			</File>
 		</Filter>
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.