From: MORIOKA Tomohiko Date: Tue, 16 Apr 2013 03:59:48 +0000 (+0900) Subject: (COS_Object_release_function_table): Add `cos_release_cons'. X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e108fbaaff85cfaddae07cfec6e4bfdf73880aca;p=chise%2Fconcord.git (COS_Object_release_function_table): Add `cos_release_cons'. (cos_retain_object): Use `COS_OBJECT_P' to check `obj' is a fat object. (cos_release_object): Likewise. (cos_cons): New function. (cos_release_cons): New function. (cos_car): New function. (cos_cdr): New function. --- diff --git a/cos.c b/cos.c index 303b2dd..299852b 100644 --- a/cos.c +++ b/cos.c @@ -33,6 +33,7 @@ int (*COS_Object_release_function_table (COS_Object) = { cos_release_string, cos_release_symbol, + cos_release_cons, cos_release_container, cos_release_sexp, cos_release_binary, @@ -104,22 +105,24 @@ cos_allocate_object_0 (enum COS_Object_Type type, size_t size) COS_Object cos_retain_object (COS_Object obj) { - obj->header.reference_count++; - + if (COS_OBJECT_P (obj)) + obj->header.reference_count++; return obj; } int cos_release_object (COS_object obj) { - ((COS_Object)obj)->header.reference_count--; + 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 - return 0; + 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); + } + return 0; } @@ -199,6 +202,53 @@ cos_string_data (COS_String string) } +COS_Cons +cos_cons (COS_object car, COS_object cdr) +{ + COS_Cons obj = COS_ALLOCATE_OBJECT (Cons); + + if (obj == NULL) + return NULL; + + obj->car = car; + obj->cdr = cdr; + cos_retain_object (car); + cos_retain_object (cdr); + + return obj; +} + +int +cos_release_cons (COS_Object obj) +{ + if (obj == NULL) + return 0; + + cos_release_object (COS_CAR (obj)); + cos_release_object (COS_CDR (obj)); + free (obj); + return 0; +} + +COS_object +cos_car (COS_Cons pair) +{ + if (COS_OBJECT_CONS_P (pair)) + return COS_CAR (pair); + else + return NULL; +} + +COS_object +cos_cdr (COS_Cons pair) +{ + if (COS_OBJECT_CONS_P (pair)) + return COS_CDR (pair); + else + return NULL; +} + + int cos_release_container (COS_Object obj) {