From: MORIOKA Tomohiko Date: Fri, 19 Apr 2013 05:24:22 +0000 (+0900) Subject: (cos_char_id): Fixed. X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf7490e04a37304273a67dae554f4a9f273873df;p=chise%2Fconcord.git (cos_char_id): Fixed. (cos_release_object): Fixed. (cos_retain_cons): Don't use `cos_retain_object' recursively. (cos_assoc): New function. (cos_alist_get): New function. --- diff --git a/cos.c b/cos.c index 546078c..7e5a51d 100644 --- a/cos.c +++ b/cos.c @@ -98,7 +98,7 @@ int cos_char_id (COS_object obj) { if (COS_OBJECT_CHAR_P (obj)) - return ((COS_INT)obj) >> 2; + return (((COS_INT)obj) >> 2) & 0x7FFFFFFF; return -1; } @@ -136,12 +136,12 @@ cos_release_object (COS_object obj) { if (COS_OBJECT_P (obj)) { - ((COS_Object)obj)->header.reference_count--; - if ( ((COS_Object)obj)->header.reference_count <= 0 ) return (*COS_Object_release_function_table [((COS_Object)obj)->header.type - COS_FAT_OBJECT_TYPE_MIN])(obj); + else + ((COS_Object)obj)->header.reference_count--; } return 0; } @@ -248,8 +248,8 @@ cos_cons (COS_object car, COS_object cdr) int cos_retain_cons (COS_Object obj) { - cos_retain_object (COS_CAR (obj)); - cos_retain_object (COS_CDR (obj)); + //cos_retain_object (COS_CAR (obj)); + //cos_retain_object (COS_CDR (obj)); return 0; } @@ -289,6 +289,29 @@ cos_cdr (COS_Cons pair) return NULL; } +COS_Cons +cos_assoc (COS_object key, COS_Cons alist) +{ + COS_Cons rest = alist; + + while ( COS_OBJECT_CONS_P (rest) ) + { + COS_Cons cell = cos_car (rest); + + if ( cos_car (cell) == key ) + return cell; + + rest = cos_cdr (rest); + } + return NULL; +} + +COS_object +cos_alist_get (COS_Cons alist, COS_object key) +{ + return cos_cdr (cos_assoc (key, alist)); +} + int cos_retain_container (COS_Object obj)