From: MORIOKA Tomohiko Date: Fri, 19 Apr 2013 05:15:51 +0000 (+0900) Subject: (cos_retain_symbol): Don't retain recursively. X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4cc23a6e3b2a8c5a398422464d1ca8ed6a78594;p=chise%2Fconcord.git (cos_retain_symbol): Don't retain recursively. (cos_symbol_p): New function. (cos_symbol_table_intern): Check type of each entry of the hash; use `cos_retain_object' for the returned symbol. (cos_print_symbol_table): New function. --- diff --git a/symbol.c b/symbol.c index 94cf020..bf6f2ce 100644 --- a/symbol.c +++ b/symbol.c @@ -73,8 +73,8 @@ cos_make_symbol (COS_String string) int cos_retain_symbol (COS_Object obj) { - cos_retain_object (((COS_Symbol)obj)->value); - cos_retain_object (((COS_Symbol)obj)->name); + //cos_retain_object (((COS_Symbol)obj)->value); + //cos_retain_object (((COS_Symbol)obj)->name); return 0; } @@ -92,6 +92,12 @@ cos_release_symbol (COS_Object obj) return 0; } +int +cos_symbol_p (COS_object obj) +{ + return COS_OBJECT_SYMBOL_P (obj); +} + COS_Symbol cos_symbol_table_intern (COS_Symbol_Table table, COS_object name) { @@ -123,10 +129,13 @@ cos_symbol_table_intern (COS_Symbol_Table table, COS_object name) table->data[i] = entry; return entry; } - else if ( (entry->name->size == key_string->size) + else if ( COS_OBJECT_SYMBOL_P (entry) + && COS_OBJECT_STRING_P (entry->name) + && (entry->name->size == key_string->size) && (memcmp (entry->name->data, key_string->data, key_string->size) == 0) ) { + cos_retain_object ((COS_object)entry); return entry; } } @@ -273,6 +282,26 @@ cos_symbol_table_set (COS_Symbol_Table table, COS_Symbol symbol) } int +cos_print_symbol_table (COS_Symbol_Table table) +{ + int i; + COS_Symbol entry; + + if (table == NULL) + table = cos_default_symbol_table; + + printf ("#[symbol_table %lX\tsize = %d", table->size); + for (i = 0; i < table->size; i++) + { + entry = table->data[i]; + printf ("\n\t%d : ", i); + cos_print_object (entry); + } + printf ("\t]\n"); + return 0; +} + +int cos_symbol_table_grow (COS_Symbol_Table table) { COS_Symbol_Table new_table @@ -283,6 +312,8 @@ cos_symbol_table_grow (COS_Symbol_Table table) if (new_table == NULL) return -1; + //printf ("\n(old table is "); + //cos_print_symbol_table (table); for (i = 0; i < table->size; i++) { COS_Symbol entry = table->data[i]; @@ -302,5 +333,8 @@ cos_symbol_table_grow (COS_Symbol_Table table) table->size = new_table->size; table->data = new_table->data; free (new_table); + //printf ("\t)\n(new table is "); + //cos_print_symbol_table (table); + //printf ("\t)\n"); return 0; }