update.
[chise/concord.git] / cos.c
diff --git a/cos.c b/cos.c
index 299852b..546078c 100644 (file)
--- a/cos.c
+++ b/cos.c
@@ -28,6 +28,22 @@ const char concord_system_db_dir[] = CONCORD_SI_DB_DIR;
 
 CONCORD_DS concord_current_env = NULL;
 
+int (*COS_Object_retain_function_table
+     [COS_OBJECT_TYPE_MAX - COS_Object_Type_char])
+  (COS_Object)
+  = { cos_retain_string,
+      cos_retain_symbol,
+      cos_retain_cons,
+      cos_retain_container,
+      cos_retain_sexp,
+      cos_retain_binary,
+      cos_retain_ds,
+      cos_retain_genre,
+      cos_retain_feature,
+      cos_retain_index,
+      cos_retain_db_object
+};
+
 int (*COS_Object_release_function_table
      [COS_OBJECT_TYPE_MAX - COS_Object_Type_char])
   (COS_Object)
@@ -51,6 +67,12 @@ cos_make_int (COS_C_Int num)
   return (COS_object)((COS_INT)(num << 1) | 1);
 }
 
+int
+cos_int_p (COS_object obj)
+{
+  return COS_OBJECT_INT_P (obj);
+}
+
 COS_C_Int
 cos_int_value (COS_object obj)
 {
@@ -59,12 +81,6 @@ cos_int_value (COS_object obj)
   return INTPTR_MIN;
 }
 
-int
-cos_int_p (COS_object obj)
-{
-  return COS_OBJECT_INT_P (obj);
-}
-
 
 COS_object
 cos_make_char (int code)
@@ -73,17 +89,17 @@ cos_make_char (int code)
 }
 
 int
-cos_char_id (COS_object obj)
+cos_char_p (COS_object obj)
 {
-  if (COS_OBJECT_CHAR_P (obj))
-    return ((COS_INT)obj) >> 2;
-  return -1;
+  return COS_OBJECT_CHAR_P (obj);
 }
 
 int
-cos_char_p (COS_object obj)
+cos_char_id (COS_object obj)
 {
-  return COS_OBJECT_CHAR_P (obj);
+  if (COS_OBJECT_CHAR_P (obj))
+    return ((COS_INT)obj) >> 2;
+  return -1;
 }
 
 
@@ -106,7 +122,12 @@ COS_Object
 cos_retain_object (COS_Object obj)
 {
   if (COS_OBJECT_P (obj))
-    obj->header.reference_count++;
+    {
+      obj->header.reference_count++;
+      (*COS_Object_retain_function_table
+       [((COS_Object)obj)->header.type
+       - COS_FAT_OBJECT_TYPE_MIN])(obj);
+    }
   return obj;
 }
 
@@ -173,6 +194,12 @@ cos_build_string (char* str)
 }
 
 int
+cos_retain_string (COS_Object obj)
+{
+  return 0;
+}
+
+int
 cos_release_string (COS_Object obj)
 {
   if (obj == NULL)
@@ -219,6 +246,14 @@ 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));
+  return 0;
+}
+
+int
 cos_release_cons (COS_Object obj)
 {
   if (obj == NULL)
@@ -230,6 +265,12 @@ cos_release_cons (COS_Object obj)
   return 0;
 }
 
+int
+cos_cons_p (COS_object obj)
+{
+  return COS_OBJECT_CONS_P (obj);
+}
+
 COS_object
 cos_car (COS_Cons pair)
 {
@@ -250,6 +291,12 @@ cos_cdr (COS_Cons pair)
 
 
 int
+cos_retain_container (COS_Object obj)
+{
+  return 0;
+}
+
+int
 cos_release_container (COS_Object obj)
 {
   return 0;
@@ -257,6 +304,12 @@ cos_release_container (COS_Object obj)
 
 
 int
+cos_retain_sexp (COS_Object obj)
+{
+  return 0;
+}
+
+int
 cos_release_sexp (COS_Object obj)
 {
   return 0;
@@ -264,6 +317,12 @@ cos_release_sexp (COS_Object obj)
 
 
 int
+cos_retain_binary (COS_Object obj)
+{
+  return 0;
+}
+
+int
 cos_release_binary (COS_Object obj)
 {
   return 0;
@@ -293,6 +352,12 @@ concord_open_env (COS_object ds)
 }
 
 int
+cos_retain_ds (COS_Object obj)
+{
+  return 0;
+}
+
+int
 cos_release_ds (COS_Object obj)
 {
   return concord_close_ds ((COS_DS)obj);
@@ -312,6 +377,12 @@ concord_get_genre (COS_object ds, COS_object genre)
 }
 
 int
+cos_retain_genre (COS_Object obj)
+{
+  return 0;
+}
+
+int
 cos_release_genre (COS_Object obj)
 {
   return concord_close_genre ((COS_Genre)obj);
@@ -343,6 +414,12 @@ concord_get_feature (COS_object ds,
 }
 
 int
+cos_retain_feature (COS_Object obj)
+{
+  return 0;
+}
+
+int
 cos_release_feature (COS_Object obj)
 {
   return concord_close_feature ((COS_Feature)obj);
@@ -371,6 +448,12 @@ concord_get_feature_index (COS_object ds,
 }
 
 int
+cos_retain_index (COS_Object obj)
+{
+  return concord_close_index ((COS_Feature_INDEX)obj);
+}
+
+int
 cos_release_index (COS_Object obj)
 {
   return concord_close_index ((COS_Feature_INDEX)obj);
@@ -378,6 +461,12 @@ cos_release_index (COS_Object obj)
 
 
 int
+cos_retain_db_object (COS_Object obj)
+{
+  return 0;
+}
+
+int
 cos_release_db_object (COS_Object obj)
 {
   return 0;
@@ -464,9 +553,6 @@ concord_object_get_feature_value (COS_object object, COS_object feature)
   CONCORD_String_Tank val_st;
   COS_String val_string;
   size_t end;
-  int val_cid;
-  COS_String val_str;
-  COS_object val_obj;
 
   if (COS_OBJECT_CHAR_P (object))
     {
@@ -491,23 +577,7 @@ concord_object_get_feature_value (COS_object object, COS_object feature)
          concord_feature_get_name (fobj),
          cos_string_data (val_string));
 
-  val_obj = cos_read_int (CONCORD_String_data (&val_st),
+  return cos_read_object (CONCORD_String_data (&val_st),
                          CONCORD_String_size (&val_st),
                          0, &end);
-  if ( val_obj != NULL )
-    return val_obj;
-
-  val_cid = cos_read_char (CONCORD_String_data (&val_st),
-                          CONCORD_String_size (&val_st),
-                          0, &end);
-  if ( val_cid >= 0 )
-    return cos_make_char (val_cid);
-
-  val_str = cos_read_string (CONCORD_String_data (&val_st),
-                            CONCORD_String_size (&val_st),
-                            0, &end);
-  if ( val_str != NULL )
-    return val_str;
-
-  return NULL;
 }