rev 200 - in trunk: . include/prothon src

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

Modified:
   trunk/STATUS.txt
   trunk/include/prothon/dict.h
   trunk/include/prothon/prothon.h
   trunk/src/builtins.c
   trunk/src/object.c
   trunk/src/object.h
Log:
fuxed bug 4 -- d={}; d[0]=0; -> crash

Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt	2004-03-29 20:57:56 UTC (rev 199)
+++ trunk/STATUS.txt	2004-03-30 01:54:01 UTC (rev 200)
@@ -33,7 +33,7 @@
 
 Full unicode support like Java
 
-Syntax extension modifier
+Syntax extension modifier -- language spec?
 
 ----------------------- TO-DO (highest priority first) ------------------------
 

Modified: trunk/include/prothon/dict.h
===================================================================
--- trunk/include/prothon/dict.h	2004-03-29 20:57:56 UTC (rev 199)
+++ trunk/include/prothon/dict.h	2004-03-30 01:54:01 UTC (rev 200)
@@ -0,0 +1,4 @@
+
+// dict.h
+
+#define DEFAULT_INITIAL_DICT_SIZE  8
\ No newline at end of file

Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h	2004-03-29 20:57:56 UTC (rev 199)
+++ trunk/include/prothon/prothon.h	2004-03-30 01:54:01 UTC (rev 200)
@@ -571,7 +571,7 @@
 int dict_add(isp ist, obj_p dict_obj, obj_p key_in, obj_p value_in);
 
 // DICT_LEN: Return the number of key/value pairs in the dictionary.
-int dict_len(isp ist, obj_p dict);
+size_t dict_len(isp ist, obj_p dict);
 
 // DICT_ITEM:  Look up a value in the dictionary for the given key.
 // Find a key using the same __eq__ match criteria given for dict_add and return the

Modified: trunk/src/builtins.c
===================================================================
--- trunk/src/builtins.c	2004-03-29 20:57:56 UTC (rev 199)
+++ trunk/src/builtins.c	2004-03-30 01:54:01 UTC (rev 200)
@@ -921,13 +921,14 @@
 // ***************************** DICT ******************************************
 #define DICT_OBJ OBJ(DICT_PROTO)
 DEF(DICT_OBJ, __str__, NULL) {
-	int i, len = dict_len(ist, self);
+	int i;
+	size_t len = dict_len(ist, self);
 	char* res = pr_malloc(3); 
 	obj_p res_obj;
 	obj_p keys = dict_keys(ist, self);
 	obj_p vals = dict_values(ist, self);
 	strcpy(res, "{");
-	for (i=0; i < len; i++) {
+	for (i=0; i < (int) len; i++) {
 		char* str1 = as_str(ist, list_item(ist, keys,i));
 		char* str2 = as_str(ist, list_item(ist, vals,i));
 		res = pr_realloc(res, strlen(res)+strlen(str1)+1+strlen(str2)+( i != len-1 ? 3 : 2));
@@ -943,7 +944,7 @@
 }
 
 DEF(DICT_OBJ, __objlist__, FORM_RPARAM) {
-	int i, size, len;
+	size_t i, size, len;
 	dict_p dict, dp;
 	dict = dict_d(self);
 	size = dictsize(dict);

Modified: trunk/src/object.c
===================================================================
--- trunk/src/object.c	2004-03-29 20:57:56 UTC (rev 199)
+++ trunk/src/object.c	2004-03-30 01:54:01 UTC (rev 200)
@@ -65,6 +65,7 @@
 #include "clist.h"
 #include "memory_mgr.h"
 #include "interp.h"
+#include "prothon/dict.h"
 
 #ifdef ASSERT_
 void assert(int cond){
@@ -1092,16 +1093,18 @@
 //********************************* new_dict_obj ******************************
 obj_p new_dict_obj(int initial_size){
 	obj_p dict_obj = new_object(OBJ(DICT_PROTO));
-	dict_p dict = obj_malloc(dict_obj, (DICT_OVERHEAD+initial_size)*sizeof(dict_t));
+	dict_p dict;
+	initial_size = max(initial_size, DEFAULT_INITIAL_DICT_SIZE);
+	dict = obj_malloc(dict_obj, (DICT_OVERHEAD+initial_size)*sizeof(dict_t));
 	memset(dict, 0, (DICT_OVERHEAD+initial_size)*sizeof(dict_t));
 	dictsize(dict) = initial_size;
 	return dict_obj;
 }
 
-#define dict_wr_chk()			\
-if (ist->exception_obj) {	\
-	write_unlock(ist, dict_obj);		\
-	return FALSE;				\
+#define dict_wr_chk()				\
+if (ist->exception_obj) {			\
+	write_unlock(ist, dict_obj);	\
+	return FALSE;					\
 }
 
 //********************************* dict_add **********************************
@@ -1137,8 +1140,8 @@
 }
 
 //********************************* dict_len **********************************
-int dict_len(isp ist, obj_p dict_obj){
-	int res;
+size_t dict_len(isp ist, obj_p dict_obj){
+	size_t res;
 	read_lock(ist, dict_obj);
 	res = dictlen(dict_d(dict_obj));
 	read_unlock(ist, dict_obj);
@@ -1177,14 +1180,14 @@
 
 //********************************* dict_keys_values **************************
 obj_p dict_keys_values(isp ist, obj_p dict_obj, int key_flg){
-	int i, size, len, cnt=0;
+	size_t i, size, len, cnt=0;
 	obj_p list_obj;
 	dict_p dict, dp;
 	read_lock(ist, dict_obj);
 	dict = dict_d(dict_obj);
 	size = dictsize(dict);
 	len  = dictlen(dict);
-	list_obj = new_list_obj(dictlen(dict));
+	list_obj = new_list_obj((int)dictlen(dict));
 	for(i=0; i < size; i++)
 		if ((dp=dictptr(dict,i))->entry.hash > 0) {
 			assert (cnt++ < len);

Modified: trunk/src/object.h
===================================================================
--- trunk/src/object.h	2004-03-29 20:57:56 UTC (rev 199)
+++ trunk/src/object.h	2004-03-30 01:54:01 UTC (rev 200)
@@ -85,8 +85,8 @@
 obj_p list_append_no_lock(obj_p list_obj, obj_p item);
 
 typedef struct {
-	i32_t	size;
-	i32_t	len;
+	size_t	size;
+	size_t	len;
 } dict_hdr_t;
 
 typedef struct {
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.