You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2013/03/07 19:25:54 UTC

[lucy-commits] [3/6] git commit: refs/heads/c-bindings-wip2 - Use short names in Clownfish methods for C bindings

Use short names in Clownfish 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/38a653f1
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/38a653f1
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/38a653f1

Branch: refs/heads/c-bindings-wip2
Commit: 38a653f1348240b19444b27ce777c7c57d4bfc73
Parents: 4cae583
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Thu Mar 7 19:06:30 2013 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Thu Mar 7 19:06:30 2013 +0100

----------------------------------------------------------------------
 c/src/Clownfish/Err.c              |   57 +++++++++++++++++--------------
 c/src/Clownfish/LockFreeRegistry.c |    8 +++--
 c/src/Clownfish/Obj.c              |   21 ++++++-----
 c/src/Clownfish/VTable.c           |   35 +++++++++++--------
 4 files changed, 68 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/38a653f1/c/src/Clownfish/Err.c
----------------------------------------------------------------------
diff --git a/c/src/Clownfish/Err.c b/c/src/Clownfish/Err.c
index a4c3e38..fa85b82 100644
--- a/c/src/Clownfish/Err.c
+++ b/c/src/Clownfish/Err.c
@@ -14,71 +14,76 @@
  * limitations under the License.
  */
 
-#include "CFBind.h"
+#define CHY_USE_SHORT_NAMES
+#define LUCY_USE_SHORT_NAMES
 
 #include <setjmp.h>
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "Clownfish/Err.h"
+#include "Clownfish/CharBuf.h"
+#include "Clownfish/VTable.h"
+
 /* TODO: Thread safety */
-static lucy_Err *current_error;
-static lucy_Err *thrown_error;
+static Err *current_error;
+static Err *thrown_error;
 static jmp_buf  *current_env;
 
 void
-lucy_Err_init_class(void) {
+Err_init_class(void) {
 }
 
-lucy_Err*
-lucy_Err_get_error() {
+Err*
+Err_get_error() {
     return current_error;
 }
 
 void
-lucy_Err_set_error(lucy_Err *error) {
+Err_set_error(Err *error) {
     if (current_error) {
-        CFISH_DECREF(current_error);
+        DECREF(current_error);
     }
     current_error = error;
 }
 
 void
-lucy_Err_do_throw(lucy_Err *error) {
+Err_do_throw(Err *error) {
     if (current_env) {
         thrown_error = error;
         longjmp(*current_env, 1);
     }
     else {
-        lucy_CharBuf *message = lucy_Err_get_mess(error);
-        fprintf(stderr, "%s", Lucy_CB_Get_Ptr8(message));
+        CharBuf *message = Err_get_mess(error);
+        fprintf(stderr, "%s", CB_Get_Ptr8(message));
         exit(EXIT_FAILURE);
     }
 }
 
 void*
-lucy_Err_to_host(lucy_Err *self) {
-    THROW(LUCY_ERR, "TODO");
+Err_to_host(Err *self) {
+    THROW(ERR, "TODO");
     UNREACHABLE_RETURN(void*);
 }
 
 void
-lucy_Err_throw_mess(lucy_VTable *vtable, lucy_CharBuf *message) {
-    Lucy_Err_Make_t make
-        = CFISH_METHOD_PTR(CFISH_CERTIFY(vtable, LUCY_VTABLE), Lucy_Err_Make);
-    lucy_Err *err = (lucy_Err*)CFISH_CERTIFY(make(NULL), LUCY_ERR);
-    Lucy_Err_Cat_Mess(err, message);
-    CFISH_DECREF(message);
-    lucy_Err_do_throw(err);
+Err_throw_mess(VTable *vtable, CharBuf *message) {
+    Err_Make_t make
+        = METHOD_PTR(CERTIFY(vtable, VTABLE), Lucy_Err_Make);
+    Err *err = (Err*)CERTIFY(make(NULL), ERR);
+    Err_Cat_Mess(err, message);
+    DECREF(message);
+    Err_do_throw(err);
 }
 
 void
-lucy_Err_warn_mess(lucy_CharBuf *message) {
-    fprintf(stderr, "%s", Lucy_CB_Get_Ptr8(message));
-    CFISH_DECREF(message);
+Err_warn_mess(CharBuf *message) {
+    fprintf(stderr, "%s", CB_Get_Ptr8(message));
+    DECREF(message);
 }
 
-lucy_Err*
-lucy_Err_trap(Cfish_Err_Attempt_t routine, void *context) {
+Err*
+Err_trap(Err_Attempt_t routine, void *context) {
     jmp_buf  env;
     jmp_buf *prev_env = current_env;
     current_env = &env;
@@ -89,7 +94,7 @@ lucy_Err_trap(Cfish_Err_Attempt_t routine, void *context) {
 
     current_env = prev_env;
 
-    lucy_Err *error = thrown_error;
+    Err *error = thrown_error;
     thrown_error = NULL;
     return error;
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/38a653f1/c/src/Clownfish/LockFreeRegistry.c
----------------------------------------------------------------------
diff --git a/c/src/Clownfish/LockFreeRegistry.c b/c/src/Clownfish/LockFreeRegistry.c
index 1f208c4..d6350c4 100644
--- a/c/src/Clownfish/LockFreeRegistry.c
+++ b/c/src/Clownfish/LockFreeRegistry.c
@@ -15,13 +15,15 @@
  */
 
 #define C_LUCY_LOCKFREEREGISTRY
+#define CHY_USE_SHORT_NAMES
+#define LUCY_USE_SHORT_NAMES
 
-#include "CFBind.h"
 #include "Clownfish/LockFreeRegistry.h"
+#include "Clownfish/Err.h"
 
 void*
-lucy_LFReg_to_host(lucy_LockFreeRegistry *self) {
-    THROW(LUCY_ERR, "TODO");
+LFReg_to_host(LockFreeRegistry *self) {
+    THROW(ERR, "TODO");
     UNREACHABLE_RETURN(void*);
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/38a653f1/c/src/Clownfish/Obj.c
----------------------------------------------------------------------
diff --git a/c/src/Clownfish/Obj.c b/c/src/Clownfish/Obj.c
index d8e781a..17fa4ab 100644
--- a/c/src/Clownfish/Obj.c
+++ b/c/src/Clownfish/Obj.c
@@ -15,30 +15,33 @@
  */
 
 #define C_LUCY_OBJ
+#define CHY_USE_SHORT_NAMES
+#define LUCY_USE_SHORT_NAMES
 
-#include "CFBind.h"
+#include "Clownfish/Obj.h"
+#include "Clownfish/Err.h"
 
 uint32_t
-lucy_Obj_get_refcount(lucy_Obj *self) {
+Obj_get_refcount(Obj *self) {
     return self->ref.count;
 }
 
-lucy_Obj*
-lucy_Obj_inc_refcount(lucy_Obj *self) {
+Obj*
+Obj_inc_refcount(Obj *self) {
     self->ref.count++;
     return self;
 }
 
 uint32_t
-lucy_Obj_dec_refcount(lucy_Obj *self) {
+Obj_dec_refcount(Obj *self) {
     uint32_t modified_refcount = INT32_MAX;
     switch (self->ref.count) {
         case 0:
-            THROW(LUCY_ERR, "Illegal refcount of 0");
+            THROW(ERR, "Illegal refcount of 0");
             break; // useless
         case 1:
             modified_refcount = 0;
-            Lucy_Obj_Destroy(self);
+            Obj_Destroy(self);
             break;
         default:
             modified_refcount = --self->ref.count;
@@ -48,8 +51,8 @@ lucy_Obj_dec_refcount(lucy_Obj *self) {
 }
 
 void*
-lucy_Obj_to_host(lucy_Obj *self) {
-    THROW(LUCY_ERR, "TODO");
+Obj_to_host(Obj *self) {
+    THROW(ERR, "TODO");
     UNREACHABLE_RETURN(void*);
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/38a653f1/c/src/Clownfish/VTable.c
----------------------------------------------------------------------
diff --git a/c/src/Clownfish/VTable.c b/c/src/Clownfish/VTable.c
index d444e77..42d7f7e 100644
--- a/c/src/Clownfish/VTable.c
+++ b/c/src/Clownfish/VTable.c
@@ -14,38 +14,43 @@
  * limitations under the License.
  */
 
+#define CHY_USE_SHORT_NAMES
+#define LUCY_USE_SHORT_NAMES
 #define C_LUCY_OBJ
 #define C_LUCY_VTABLE
 
-#include "CFBind.h"
+#include "Clownfish/VTable.h"
+#include "Clownfish/CharBuf.h"
+#include "Clownfish/Err.h"
+#include "Clownfish/VArray.h"
 
-lucy_Obj*
-lucy_VTable_foster_obj(lucy_VTable *self, void *host_obj) {
-    THROW(LUCY_ERR, "TODO");
-    UNREACHABLE_RETURN(lucy_Obj*);
+Obj*
+VTable_foster_obj(VTable *self, void *host_obj) {
+    THROW(ERR, "TODO");
+    UNREACHABLE_RETURN(Obj*);
 }
 
 void
-lucy_VTable_register_with_host(lucy_VTable *singleton, lucy_VTable *parent) {
+VTable_register_with_host(VTable *singleton, VTable *parent) {
     UNUSED_VAR(singleton);
     UNUSED_VAR(parent);
 }
 
-lucy_VArray*
-lucy_VTable_fresh_host_methods(const lucy_CharBuf *class_name) {
+VArray*
+VTable_fresh_host_methods(const CharBuf *class_name) {
     UNUSED_VAR(class_name);
-    return lucy_VA_new(0);
+    return VA_new(0);
 }
 
-lucy_CharBuf*
-lucy_VTable_find_parent_class(const lucy_CharBuf *class_name) {
-    THROW(LUCY_ERR, "TODO");
-    UNREACHABLE_RETURN(lucy_CharBuf*);
+CharBuf*
+VTable_find_parent_class(const CharBuf *class_name) {
+    THROW(ERR, "TODO");
+    UNREACHABLE_RETURN(CharBuf*);
 }
 
 void*
-lucy_VTable_to_host(lucy_VTable *self) {
-    THROW(LUCY_ERR, "TODO");
+VTable_to_host(VTable *self) {
+    THROW(ERR, "TODO");
     UNREACHABLE_RETURN(void*);
 }