Use short names in Lucy methods for C bindings

Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/0ed6815f
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/0ed6815f
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/0ed6815f

Branch: refs/heads/c-bindings-wip2
Commit: 0ed6815f1f51de8fd60cdecbcc66eb646000211f
Parents: 38a653f
Author: Nick Wellnhofer <[email protected]>
Authored: Thu Mar 7 19:16:25 2013 +0100
Committer: Nick Wellnhofer <[email protected]>
Committed: Thu Mar 7 19:16:25 2013 +0100

----------------------------------------------------------------------
 c/src/Lucy/Document/Doc.c    |  105 ++++++++++++++++++-----------------
 c/src/Lucy/Index/DocReader.c |  102 ++++++++++++++++++----------------
 c/src/Lucy/Index/Inverter.c  |  111 +++++++++++++++++++-----------------
 3 files changed, 168 insertions(+), 150 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/0ed6815f/c/src/Lucy/Document/Doc.c
----------------------------------------------------------------------
diff --git a/c/src/Lucy/Document/Doc.c b/c/src/Lucy/Document/Doc.c
index a855ba3..2cf88ec 100644
--- a/c/src/Lucy/Document/Doc.c
+++ b/c/src/Lucy/Document/Doc.c
@@ -15,22 +15,27 @@
  */
 
 #define C_LUCY_DOC
+#define CHY_USE_SHORT_NAMES
+#define LUCY_USE_SHORT_NAMES
 
-#include "CFBind.h"
 #include "Lucy/Document/Doc.h"
+#include "Clownfish/CharBuf.h"
+#include "Clownfish/Err.h"
+#include "Clownfish/Hash.h"
+#include "Clownfish/VTable.h"
 #include "Lucy/Store/InStream.h"
 #include "Lucy/Store/OutStream.h"
 
-lucy_Doc*
-lucy_Doc_init(lucy_Doc *self, void *fields, int32_t doc_id) {
-    lucy_Hash *hash;
+Doc*
+Doc_init(Doc *self, void *fields, int32_t doc_id) {
+    Hash *hash;
 
     if (fields) {
-        hash = (lucy_Hash *)CFISH_CERTIFY(fields, LUCY_HASH);
-        CFISH_INCREF(hash);
+        hash = (Hash *)CERTIFY(fields, HASH);
+        INCREF(hash);
     }
     else {
-        hash = lucy_Hash_new(0);
+        hash = Hash_new(0);
     }
     self->fields = hash;
     self->doc_id = doc_id;
@@ -39,84 +44,84 @@ lucy_Doc_init(lucy_Doc *self, void *fields, int32_t doc_id) 
{
 }
 
 void
-lucy_Doc_set_fields(lucy_Doc *self, void *fields) {
-    CFISH_DECREF(self->fields);
-    self->fields = CFISH_CERTIFY(fields, LUCY_HASH);
+Doc_set_fields(Doc *self, void *fields) {
+    DECREF(self->fields);
+    self->fields = CERTIFY(fields, HASH);
 }
 
 uint32_t
-lucy_Doc_get_size(lucy_Doc *self) {
-    lucy_Hash *hash = (lucy_Hash *)self->fields;
-    return Lucy_Hash_Get_Size(hash);
+Doc_get_size(Doc *self) {
+    Hash *hash = (Hash *)self->fields;
+    return Hash_Get_Size(hash);
 }
 
 void
-lucy_Doc_store(lucy_Doc *self, const lucy_CharBuf *field, lucy_Obj *value) {
-    lucy_Hash *hash = (lucy_Hash *)self->fields;
-    Lucy_Hash_Store(hash, (lucy_Obj *)field, value);
-    CFISH_INCREF(value);
+Doc_store(Doc *self, const CharBuf *field, Obj *value) {
+    Hash *hash = (Hash *)self->fields;
+    Hash_Store(hash, (Obj *)field, value);
+    INCREF(value);
 }
 
 void
-lucy_Doc_serialize(lucy_Doc *self, lucy_OutStream *outstream) {
-    lucy_Hash *hash = (lucy_Hash *)self->fields;
-    Lucy_Hash_Serialize(hash, outstream);
-    Lucy_OutStream_Write_C32(outstream, self->doc_id);
+Doc_serialize(Doc *self, OutStream *outstream) {
+    Hash *hash = (Hash *)self->fields;
+    Hash_Serialize(hash, outstream);
+    OutStream_Write_C32(outstream, self->doc_id);
 }
 
-lucy_Doc*
-lucy_Doc_deserialize(lucy_Doc *self, lucy_InStream *instream) {
-     lucy_Hash *hash = (lucy_Hash*)Lucy_VTable_Make_Obj(LUCY_HASH);
-     self->fields = Lucy_Hash_Deserialize(hash, instream);
-     self->doc_id = Lucy_InStream_Read_C32(instream);
+Doc*
+Doc_deserialize(Doc *self, InStream *instream) {
+     Hash *hash = (Hash*)VTable_Make_Obj(HASH);
+     self->fields = Hash_Deserialize(hash, instream);
+     self->doc_id = InStream_Read_C32(instream);
      return self;
 }
 
-lucy_Obj*
-lucy_Doc_extract(lucy_Doc *self, lucy_CharBuf *field,
-                 lucy_ViewCharBuf *target) {
-    lucy_Hash *hash = (lucy_Hash *)self->fields;
-    lucy_Obj  *obj  = Lucy_Hash_Fetch(hash, (lucy_Obj *)field);
+Obj*
+Doc_extract(Doc *self, CharBuf *field,
+                 ViewCharBuf *target) {
+    Hash *hash = (Hash *)self->fields;
+    Obj  *obj  = Hash_Fetch(hash, (Obj *)field);
 
-    if (obj && Lucy_Obj_Is_A(obj, LUCY_CHARBUF)) {
-        Lucy_ViewCB_Assign(target, (lucy_CharBuf *)obj);
+    if (obj && Obj_Is_A(obj, CHARBUF)) {
+        ViewCB_Assign(target, (CharBuf *)obj);
     }
 
     return obj;
 }
 
 void*
-lucy_Doc_to_host(lucy_Doc *self) {
-    THROW(LUCY_ERR, "TODO");
+Doc_to_host(Doc *self) {
+    THROW(ERR, "TODO");
     UNREACHABLE_RETURN(void*);
 }
 
-lucy_Hash*
-lucy_Doc_dump(lucy_Doc *self) {
-    THROW(LUCY_ERR, "TODO");
-    UNREACHABLE_RETURN(lucy_Hash*);
+Hash*
+Doc_dump(Doc *self) {
+    THROW(ERR, "TODO");
+    UNREACHABLE_RETURN(Hash*);
 }
 
-lucy_Doc*
-lucy_Doc_load(lucy_Doc *self, lucy_Obj *dump) {
-    THROW(LUCY_ERR, "TODO");
-    UNREACHABLE_RETURN(lucy_Doc*);
+Doc*
+Doc_load(Doc *self, Obj *dump) {
+    THROW(ERR, "TODO");
+    UNREACHABLE_RETURN(Doc*);
 }
 
 bool
-lucy_Doc_equals(lucy_Doc *self, lucy_Obj *other) {
-    lucy_Doc *twin = (lucy_Doc*)other;
+Doc_equals(Doc *self, Obj *other) {
+    Doc *twin = (Doc*)other;
 
     if (twin == self)                    { return true;  }
-    if (!Lucy_Obj_Is_A(other, LUCY_DOC)) { return false; }
+    if (!Obj_Is_A(other, DOC)) { return false; }
 
-    return Lucy_Hash_Equals(self->fields, twin->fields);
+    return Hash_Equals(self->fields, twin->fields);
 }
 
 void
-lucy_Doc_destroy(lucy_Doc *self) {
-    CFISH_DECREF(self->fields);
-    LUCY_SUPER_DESTROY(self, LUCY_DOC);
+Doc_destroy(Doc *self) {
+    DECREF(self->fields);
+    SUPER_DESTROY(self, DOC);
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/0ed6815f/c/src/Lucy/Index/DocReader.c
----------------------------------------------------------------------
diff --git a/c/src/Lucy/Index/DocReader.c b/c/src/Lucy/Index/DocReader.c
index a20ecbb..e06e7ee 100644
--- a/c/src/Lucy/Index/DocReader.c
+++ b/c/src/Lucy/Index/DocReader.c
@@ -16,99 +16,105 @@
 
 #define C_LUCY_DOCREADER
 #define C_LUCY_DEFAULTDOCREADER
+#define CHY_USE_SHORT_NAMES
+#define LUCY_USE_SHORT_NAMES
 
-#include "CFBind.h"
 #include "Lucy/Index/DocReader.h"
+#include "Clownfish/ByteBuf.h"
+#include "Clownfish/CharBuf.h"
+#include "Clownfish/Err.h"
+#include "Clownfish/Hash.h"
+#include "Clownfish/Num.h"
 #include "Clownfish/Util/Memory.h"
 #include "Lucy/Document/HitDoc.h"
 #include "Lucy/Plan/FieldType.h"
 #include "Lucy/Plan/Schema.h"
 #include "Lucy/Store/InStream.h"
 
-lucy_HitDoc*
-lucy_DefDocReader_fetch_doc(lucy_DefaultDocReader *self, int32_t doc_id) {
-    lucy_Schema   *const schema = self->schema;
-    lucy_InStream *const dat_in = self->dat_in;
-    lucy_InStream *const ix_in  = self->ix_in;
-    lucy_Hash     *const fields = lucy_Hash_new(1);
+HitDoc*
+DefDocReader_fetch_doc(DefaultDocReader *self, int32_t doc_id) {
+    Schema   *const schema = self->schema;
+    InStream *const dat_in = self->dat_in;
+    InStream *const ix_in  = self->ix_in;
+    Hash     *const fields = Hash_new(1);
     int64_t   start;
     uint32_t  num_fields;
     uint32_t  field_name_cap = 31;
-    char     *field_name = (char*)LUCY_MALLOCATE(field_name_cap + 1);
+    char     *field_name = (char*)MALLOCATE(field_name_cap + 1);
 
     // Get data file pointer from index, read number of fields.
-    Lucy_InStream_Seek(ix_in, (int64_t)doc_id * 8);
-    start = Lucy_InStream_Read_U64(ix_in);
-    Lucy_InStream_Seek(dat_in, start);
-    num_fields = Lucy_InStream_Read_C32(dat_in);
+    InStream_Seek(ix_in, (int64_t)doc_id * 8);
+    start = InStream_Read_U64(ix_in);
+    InStream_Seek(dat_in, start);
+    num_fields = InStream_Read_C32(dat_in);
 
     // Decode stored data and build up the doc field by field.
     while (num_fields--) {
         uint32_t        field_name_len;
-        lucy_Obj       *value;
-        lucy_FieldType *type;
+        Obj       *value;
+        FieldType *type;
 
         // Read field name.
-        field_name_len = Lucy_InStream_Read_C32(dat_in);
+        field_name_len = InStream_Read_C32(dat_in);
         if (field_name_len > field_name_cap) {
             field_name_cap = field_name_len;
-            field_name     = (char*)LUCY_REALLOCATE(field_name,
+            field_name     = (char*)REALLOCATE(field_name,
                                                     field_name_cap + 1);
         }
-        Lucy_InStream_Read_Bytes(dat_in, field_name, field_name_len);
+        InStream_Read_Bytes(dat_in, field_name, field_name_len);
 
         // Find the Field's FieldType.
-        lucy_ZombieCharBuf *field_name_zcb
-            = CFISH_ZCB_WRAP_STR(field_name, field_name_len);
-        type = Lucy_Schema_Fetch_Type(schema, (lucy_CharBuf*)field_name_zcb);
+        ZombieCharBuf *field_name_zcb
+            = ZCB_WRAP_STR(field_name, field_name_len);
+        type = Schema_Fetch_Type(schema, (CharBuf*)field_name_zcb);
 
         // Read the field value.
-        switch (Lucy_FType_Primitive_ID(type) & lucy_FType_PRIMITIVE_ID_MASK) {
-            case lucy_FType_TEXT: {
-                    uint32_t value_len = Lucy_InStream_Read_C32(dat_in);
-                    char *buf = (char*)LUCY_MALLOCATE(value_len + 1);
-                    Lucy_InStream_Read_Bytes(dat_in, buf, value_len);
+        switch (FType_Primitive_ID(type) & FType_PRIMITIVE_ID_MASK) {
+            case FType_TEXT: {
+                    uint32_t value_len = InStream_Read_C32(dat_in);
+                    char *buf = (char*)MALLOCATE(value_len + 1);
+                    InStream_Read_Bytes(dat_in, buf, value_len);
                     buf[value_len] = '\0'; 
-                    value = (lucy_Obj*)lucy_CB_new_steal_from_trusted_str(
+                    value = (Obj*)CB_new_steal_from_trusted_str(
                                 buf, value_len, value_len + 1);
                     break;
                 }
-            case lucy_FType_BLOB: {
-                    uint32_t value_len = Lucy_InStream_Read_C32(dat_in);
-                    char *buf = (char*)LUCY_MALLOCATE(value_len);
-                    Lucy_InStream_Read_Bytes(dat_in, buf, value_len);
-                    value = (lucy_Obj*)lucy_BB_new_steal_bytes(
+            case FType_BLOB: {
+                    uint32_t value_len = InStream_Read_C32(dat_in);
+                    char *buf = (char*)MALLOCATE(value_len);
+                    InStream_Read_Bytes(dat_in, buf, value_len);
+                    value = (Obj*)BB_new_steal_bytes(
                                 buf, value_len, value_len);
                     break;
                 }
-            case lucy_FType_FLOAT32:
-                value = (lucy_Obj*)lucy_Float32_new(
-                                Lucy_InStream_Read_F32(dat_in));
+            case FType_FLOAT32:
+                value = (Obj*)Float32_new(
+                                InStream_Read_F32(dat_in));
                 break;
-            case lucy_FType_FLOAT64:
-                value = (lucy_Obj*)lucy_Float64_new(
-                                Lucy_InStream_Read_F64(dat_in));
+            case FType_FLOAT64:
+                value = (Obj*)Float64_new(
+                                InStream_Read_F64(dat_in));
                 break;
-            case lucy_FType_INT32:
-                value = (lucy_Obj*)lucy_Int32_new(
-                                (int32_t)Lucy_InStream_Read_C32(dat_in));
+            case FType_INT32:
+                value = (Obj*)Int32_new(
+                                (int32_t)InStream_Read_C32(dat_in));
                 break;
-            case lucy_FType_INT64:
-                value = (lucy_Obj*)lucy_Int64_new(
-                                (int64_t)Lucy_InStream_Read_C64(dat_in));
+            case FType_INT64:
+                value = (Obj*)Int64_new(
+                                (int64_t)InStream_Read_C64(dat_in));
                 break;
             default:
                 value = NULL;
-                CFISH_THROW(LUCY_ERR, "Unrecognized type: %o", type);
+                THROW(ERR, "Unrecognized type: %o", type);
         }
 
         // Store the value.
-        Lucy_Hash_Store_Str(fields, field_name, field_name_len, value);
+        Hash_Store_Str(fields, field_name, field_name_len, value);
     }
-    LUCY_FREEMEM(field_name);
+    FREEMEM(field_name);
 
-    lucy_HitDoc *retval = lucy_HitDoc_new(fields, doc_id, 0.0);
-    CFISH_DECREF(fields);
+    HitDoc *retval = HitDoc_new(fields, doc_id, 0.0);
+    DECREF(fields);
     return retval;
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/0ed6815f/c/src/Lucy/Index/Inverter.c
----------------------------------------------------------------------
diff --git a/c/src/Lucy/Index/Inverter.c b/c/src/Lucy/Index/Inverter.c
index 9dc6529..cfaafcd 100644
--- a/c/src/Lucy/Index/Inverter.c
+++ b/c/src/Lucy/Index/Inverter.c
@@ -16,104 +16,111 @@
 
 #define C_LUCY_INVERTER
 #define C_LUCY_INVERTERENTRY
+#define CHY_USE_SHORT_NAMES
+#define LUCY_USE_SHORT_NAMES
 
-#include "CFBind.h"
 #include "Lucy/Index/Inverter.h"
+#include "Clownfish/ByteBuf.h"
+#include "Clownfish/CharBuf.h"
+#include "Clownfish/Err.h"
+#include "Clownfish/Hash.h"
+#include "Clownfish/Num.h"
+#include "Clownfish/VArray.h"
 #include "Lucy/Document/Doc.h"
 #include "Lucy/Index/Segment.h"
 #include "Lucy/Plan/FieldType.h"
 #include "Lucy/Plan/Schema.h"
 
-static lucy_InverterEntry*
-S_fetch_entry(lucy_Inverter *self, lucy_CharBuf *field) {
-    lucy_Schema *const schema = self->schema;
-    int32_t field_num = Lucy_Seg_Field_Num(self->segment, field);
+static InverterEntry*
+S_fetch_entry(Inverter *self, CharBuf *field) {
+    Schema *const schema = self->schema;
+    int32_t field_num = Seg_Field_Num(self->segment, field);
     if (!field_num) {
         // This field seems not to be in the segment yet.  Try to find it in
         // the Schema.
-        if (Lucy_Schema_Fetch_Type(schema, field)) {
+        if (Schema_Fetch_Type(schema, field)) {
             // The field is in the Schema.  Get a field num from the Segment.
-            field_num = Lucy_Seg_Add_Field(self->segment, field);
+            field_num = Seg_Add_Field(self->segment, field);
         }
         else {
             // We've truly failed to find the field.  The user must
             // not have spec'd it.
-            THROW(LUCY_ERR, "Unknown field name: '%o'", field);
+            THROW(ERR, "Unknown field name: '%o'", field);
         }
     }
 
-    lucy_InverterEntry *entry
-        = (lucy_InverterEntry*)Lucy_VA_Fetch(self->entry_pool, field_num);
+    InverterEntry *entry
+        = (InverterEntry*)VA_Fetch(self->entry_pool, field_num);
     if (!entry) {
-        entry = lucy_InvEntry_new(schema, (lucy_CharBuf*)field, field_num);
-        Lucy_VA_Store(self->entry_pool, field_num, (lucy_Obj*)entry);
+        entry = InvEntry_new(schema, (CharBuf*)field, field_num);
+        VA_Store(self->entry_pool, field_num, (Obj*)entry);
     }
     return entry;
 }
 
 void
-lucy_Inverter_invert_doc(lucy_Inverter *self, lucy_Doc *doc) {
-    lucy_Hash *const fields = (lucy_Hash*)Lucy_Doc_Get_Fields(doc);
-    uint32_t   num_keys     = Lucy_Hash_Iterate(fields);
+Inverter_invert_doc(Inverter *self, Doc *doc) {
+    Hash *const fields = (Hash*)Doc_Get_Fields(doc);
+    uint32_t   num_keys     = Hash_Iterate(fields);
 
     // Prepare for the new doc.
-    Lucy_Inverter_Set_Doc(self, doc);
+    Inverter_Set_Doc(self, doc);
 
     // Extract and invert the doc's fields.
     while (num_keys--) {
-        lucy_Obj *key, *obj;
-        Lucy_Hash_Next(fields, &key, &obj);
-        lucy_CharBuf *field = (lucy_CharBuf*)CFISH_CERTIFY(key, LUCY_CHARBUF);
-        lucy_InverterEntry *inv_entry = S_fetch_entry(self, field);
-        lucy_FieldType *type = inv_entry->type;
+        Obj *key, *obj;
+        Hash_Next(fields, &key, &obj);
+        CharBuf *field = (CharBuf*)CERTIFY(key, CHARBUF);
+        InverterEntry *inv_entry = S_fetch_entry(self, field);
+        FieldType *type = inv_entry->type;
 
         // Get the field value.
-        switch (Lucy_FType_Primitive_ID(type) & lucy_FType_PRIMITIVE_ID_MASK) {
-            case lucy_FType_TEXT: {
-                    lucy_CharBuf *char_buf
-                        = (lucy_CharBuf*)CFISH_CERTIFY(obj, LUCY_CHARBUF);
-                    lucy_ViewCharBuf *value
-                        = (lucy_ViewCharBuf*)inv_entry->value;
-                    Lucy_ViewCB_Assign(value, char_buf);
+        switch (FType_Primitive_ID(type) & FType_PRIMITIVE_ID_MASK) {
+            case FType_TEXT: {
+                    CharBuf *char_buf
+                        = (CharBuf*)CERTIFY(obj, CHARBUF);
+                    ViewCharBuf *value
+                        = (ViewCharBuf*)inv_entry->value;
+                    ViewCB_Assign(value, char_buf);
                     break;
                 }
-            case lucy_FType_BLOB: {
-                    lucy_ByteBuf *byte_buf
-                        = (lucy_ByteBuf*)CFISH_CERTIFY(obj, LUCY_BYTEBUF);
-                    lucy_ViewByteBuf *value
-                        = (lucy_ViewByteBuf*)inv_entry->value;
-                    Lucy_ViewBB_Assign(value, byte_buf);
+            case FType_BLOB: {
+                    ByteBuf *byte_buf
+                        = (ByteBuf*)CERTIFY(obj, BYTEBUF);
+                    ViewByteBuf *value
+                        = (ViewByteBuf*)inv_entry->value;
+                    ViewBB_Assign(value, byte_buf);
                     break;
                 }
-            case lucy_FType_INT32: {
-                    int32_t int_val = (int32_t)Lucy_Obj_To_I64(obj);
-                    lucy_Integer32* value = (lucy_Integer32*)inv_entry->value;
-                    Lucy_Int32_Set_Value(value, int_val);
+            case FType_INT32: {
+                    int32_t int_val = (int32_t)Obj_To_I64(obj);
+                    Integer32* value = (Integer32*)inv_entry->value;
+                    Int32_Set_Value(value, int_val);
                     break;
                 }
-            case lucy_FType_INT64: {
-                    int64_t int_val = Lucy_Obj_To_I64(obj);
-                    lucy_Integer64* value = (lucy_Integer64*)inv_entry->value;
-                    Lucy_Int64_Set_Value(value, int_val);
+            case FType_INT64: {
+                    int64_t int_val = Obj_To_I64(obj);
+                    Integer64* value = (Integer64*)inv_entry->value;
+                    Int64_Set_Value(value, int_val);
                     break;
                 }
-            case lucy_FType_FLOAT32: {
-                    float float_val = (float)Lucy_Obj_To_F64(obj);
-                    lucy_Float32* value = (lucy_Float32*)inv_entry->value;
-                    Lucy_Float32_Set_Value(value, float_val);
+            case FType_FLOAT32: {
+                    float float_val = (float)Obj_To_F64(obj);
+                    Float32* value = (Float32*)inv_entry->value;
+                    Float32_Set_Value(value, float_val);
                     break;
                 }
-            case lucy_FType_FLOAT64: {
-                    double float_val = Lucy_Obj_To_F64(obj);
-                    lucy_Float64* value = (lucy_Float64*)inv_entry->value;
-                    Lucy_Float64_Set_Value(value, float_val);
+            case FType_FLOAT64: {
+                    double float_val = Obj_To_F64(obj);
+                    Float64* value = (Float64*)inv_entry->value;
+                    Float64_Set_Value(value, float_val);
                     break;
                 }
             default:
-                THROW(LUCY_ERR, "Unrecognized type: %o", type);
+                THROW(ERR, "Unrecognized type: %o", type);
         }
 
-        Lucy_Inverter_Add_Field(self, inv_entry);
+        Inverter_Add_Field(self, inv_entry);
     }
 }
 

Reply via email to