rev 414 - in trunk: modules/Prosist pr src

SVN User <[email protected]> Sun, 25 Apr 2004 15:32:05 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-04-25 15:32:02 -0400 (Sun, 25 Apr 2004)
New Revision: 414

Modified:
   trunk/modules/Prosist/Prosist.c
   trunk/pr/prosist.pr
   trunk/src/object.c
Log:
Prosist store and load (pickle replacement) finally works

Modified: trunk/modules/Prosist/Prosist.c
===================================================================
--- trunk/modules/Prosist/Prosist.c	2004-04-25 16:21:54 UTC (rev 413)
+++ trunk/modules/Prosist/Prosist.c	2004-04-25 19:32:02 UTC (rev 414)
@@ -277,6 +277,7 @@
 void store_obj(isp ist, psrec_p psrecp, obj_p obj) {
 	apr_status_t aprerr;
 	apr_datum_t key, value;
+	attr_key_t akey;
 	obj_p mw_obj, proxy_obj;
 	psid_t id;
 	int i, plen, added_attr = FALSE;
@@ -305,17 +306,15 @@
 		if (i < plen-1) ADD_CHR(',') 
 		else            ADD_CHR(';'); 
 	}
-	if (!proxy_obj->has_attrs) {
-		attr_key_t akey = attr_first_key(ist, proxy_obj);
-		while(akey) {
-			ADD_CHR('a');
-			ADD_STR(key_to_symstr(ist, akey));
-			ADD_CHR(':');
-			ADD_REF(attr_value_by_key(ist, proxy_obj, akey));
-			ADD_CHR(',');
-			added_attr = TRUE;
-			akey = attr_next_key(ist, proxy_obj, akey);
-		}
+	akey = attr_first_key(ist, proxy_obj);
+	if (akey) ADD_CHR('a');
+	while(akey) {
+		ADD_STR(key_to_symstr(ist, akey));
+		ADD_CHR(':');
+		ADD_REF(attr_value_by_key(ist, proxy_obj, akey));
+		ADD_CHR(',');
+		added_attr = TRUE;
+		akey = attr_next_key(ist, proxy_obj, akey);
 	}
 	if (added_attr) { _idx--; ADD_CHR(';'); }
 	if (proxy_obj->data_type == DATA_TYPE_IMMDATA) {
@@ -370,6 +369,7 @@
 //******************************** append_store_refs ****************************
 void append_store_refs(isp ist, psrec_p psrecp, obj_p obj, int objidx, obj_p store_refs) {
 	psid_t id;
+	attr_key_t key;
 	obj_p mw_obj, id_obj, id_tuple, proxy_obj;
 	int i, plen, tuple_type=FALSE;
 
@@ -462,17 +462,15 @@
 		del_unlock(mw_obj);
 		if_exc_return;
 	}
-	if (proxy_obj->has_attrs) {
-		attr_key_t key = attr_first_key(ist, proxy_obj);
-		while(key) {
-			obj_p attr = attr_value_by_key(ist, proxy_obj, key);
-			mw_obj = NEW_MW(attr);
-			if (!is_unclonable(attr) && !dict_item(ist, psrecp->obj_to_id, mw_obj))
-				list_append(ist, store_refs, attr);
-			del_unlock(mw_obj);
-			if_exc_return;
-			key = attr_next_key(ist, proxy_obj, key);
-		}
+	key = attr_first_key(ist, proxy_obj);
+	while(key) {
+		obj_p attr = attr_value_by_key(ist, proxy_obj, key);
+		mw_obj = NEW_MW(attr);
+		if (!is_unclonable(attr) && !dict_item(ist, psrecp->obj_to_id, mw_obj))
+			list_append(ist, store_refs, attr);
+		del_unlock(mw_obj);
+		if_exc_return;
+		key = attr_next_key(ist, proxy_obj, key);
 	}
 	if (tuple_type) {
 		int llen = (int) list_len(ist, proxy_obj);
@@ -520,7 +518,7 @@
 				}
 				break;
 			}
-			case 'a': {
+			case 'a': {   // 0x009b87e0
 				while(*p++ != ';') {
 					obj_p ref_id_obj, aval;
 					char *q, *aname = pr_malloc(value.dsize);
@@ -570,8 +568,15 @@
 	}
 done:
 	res = call_func0(ist, obj, SYM(__FROMSTORPROXY__));
-	if (obj != res)
+	if (obj != res) {
+		obj_p mw_res = NEW_MW(res);
+		dict_add(ist, psrecp->obj_to_id, mw_res, id_obj);
+		if (ist->exception_obj) { del_unlock(mw_res); return NULL; }
+		dict_add(ist, psrecp->id_to_obj, id_obj, res);
+		if (ist->exception_obj) { del_unlock(mw_res); return NULL; }
+		del_unlock(mw_res);
 		del_unlock(obj);
+	}
 	return res;
 }
 

Modified: trunk/pr/prosist.pr
===================================================================
--- trunk/pr/prosist.pr	2004-04-25 16:21:54 UTC (rev 413)
+++ trunk/pr/prosist.pr	2004-04-25 19:32:02 UTC (rev 414)
@@ -28,6 +28,7 @@
 x = db.root
 db.close()
 
+print
 print 'these two should match .. '
 print
 print a, a[6].a , a[6].b , a[6].c 
@@ -36,5 +37,6 @@
 a = 1
 
 print
-print x
-#, x[6].a , x[6].b , x[6].c 
+print x,
+y = x[6]
+print y.a, y.b, y.c

Modified: trunk/src/object.c
===================================================================
--- trunk/src/object.c	2004-04-25 16:21:54 UTC (rev 413)
+++ trunk/src/object.c	2004-04-25 19:32:02 UTC (rev 414)
@@ -544,8 +544,7 @@
 	write_unlock(ist, obj);
 }
 
-//********************************* switch_proto ****************************
-
+//********************************* attr_first_key ****************************
 attr_key_t attr_first_key(isp ist, obj_p obj) {
 	int i;
 	size_t asize;
@@ -560,6 +559,7 @@
 	return 0;
 }
 
+//********************************* attr_next_key *****************************
 attr_key_t attr_next_key(isp ist, obj_p obj, attr_key_t key) {
 	if (obj->has_attrs){
 		attr_p attrs = obj->attr_proto.attrs;
@@ -574,6 +574,7 @@
 	return 0;
 }
 
+//********************************* attr_value_by_key *************************
 obj_p attr_value_by_key(isp ist, obj_p obj, attr_key_t key) {
 	if (obj->has_attrs){
 		attr_p ptr, attrs = obj->attr_proto.attrs;
@@ -584,6 +585,7 @@
 	return NULL;
 }
 
+//********************************* switch_proto ******************************
 void switch_proto(isp ist, obj_p obj, obj_p new_proto) {
 	attr_p attrs;
 	wrlock_rtrn(obj);