rev 216 - trunk/src
SVN User <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: bcollins
Date: 2004-03-30 15:32:57 -0500 (Tue, 30 Mar 2004)
New Revision: 216
Modified:
trunk/src/builtins.c
Log:
Fix for bug #9. Printing List, Dict or Tuple would cause a segv. We now
check if self == {Dict,Tuple,List}_OBJ and print a default for that case.
Modified: trunk/src/builtins.c
===================================================================
--- trunk/src/builtins.c 2004-03-30 19:27:07 UTC (rev 215)
+++ trunk/src/builtins.c 2004-03-30 20:32:57 UTC (rev 216)
@@ -328,6 +328,7 @@
{
int i, len=list_len(ist, self);
char msg[64], *res;
+ obj_p ret_obj;
/* Need enough room for just empty list */
res = pr_malloc(strlen(ldelim) + strlen(rdelim) + 1);
@@ -359,7 +360,10 @@
}
strcat(res, rdelim);
- return new_string_obj(res);
+ ret_obj = new_string_obj(res);
+ pr_free(res);
+
+ return ret_obj;
}
#define SEQ_TYPE_STRING 0
@@ -763,6 +767,8 @@
MODULE_START(Tuple);
DEF(Tuple, __str__, NULL) {
+ if (self == Tuple_OBJ)
+ return new_string_obj("()");
return str_tuple_list(ist, self, "(", ")");
}
@@ -791,6 +797,8 @@
MODULE_START(List);
DEF(List, __str__, NULL) {
+ if (self == List_OBJ)
+ return new_string_obj("[]");
return str_tuple_list(ist, self, "[", "]");
}
@@ -1018,11 +1026,19 @@
DEF(Dict, __str__, NULL) {
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);
+ size_t len;
+ char* res;
+ obj_p res_obj, keys, vals;
+
+ if (self == Dict_OBJ)
+ return new_string_obj("{}");
+
+ len = dict_len(ist, self);
+ keys = dict_keys(ist, self);
+ dict_values(ist, self);
+
+ res = pr_malloc(3);
+
strcpy(res, "{");
for (i=0; i < (int) len; i++) {
char* str1 = as_str(ist, list_item(ist, keys,i));