You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2015/02/13 22:45:57 UTC

[07/16] lucy-clownfish git commit: Normalize arg typing for obj allocation macros.

Normalize arg typing for obj allocation macros.

Make SUPER_DESTROY check for NULL first to make it consistent with
INCREF, DECREF, etc.

Prefer void* over casting.  Neither is safe, but at least an argument
type of void* in a static inline function only accepts pointers without
complaint.


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

Branch: refs/heads/master
Commit: 7adc3069cb09f7ea5408ee7edb6b4f95feb73448
Parents: d08401b
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Feb 7 11:12:09 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Feb 7 11:14:00 2015 -0800

----------------------------------------------------------------------
 runtime/core/Clownfish/Obj.cfh | 62 +++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/7adc3069/runtime/core/Clownfish/Obj.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Obj.cfh b/runtime/core/Clownfish/Obj.cfh
index aa9f9f4..1cba9f0 100644
--- a/runtime/core/Clownfish/Obj.cfh
+++ b/runtime/core/Clownfish/Obj.cfh
@@ -40,14 +40,6 @@ public class Clownfish::Obj {
     incremented Obj*
     Inc_RefCount(Obj *self);
 
-    /** NULL-safe invocation of [](cfish:.Inc_RefCount).
-     *
-     * @return NULL if `self` is NULL, otherwise the return value
-     * of [](cfish:.Inc_RefCount).
-     */
-    inert inline incremented Obj*
-    incref(Obj *self);
-
     /** Decrement an object's refcount, calling [](cfish:.Destroy) if it hits 0.
      *
      * @return the modified refcount.
@@ -55,14 +47,6 @@ public class Clownfish::Obj {
     uint32_t
     Dec_RefCount(Obj *self);
 
-    /** NULL-safe invocation of [](cfish:.Dec_RefCount).
-     *
-     * @return NULL if `self` is NULL, otherwise the return value
-     * of [](cfish:.Dec_RefCount).
-     */
-    inert inline uint32_t
-    decref(Obj *self);
-
     /** Return a host-language object wrapper for this object.
      */
     void*
@@ -79,14 +63,6 @@ public class Clownfish::Obj {
     public void
     Destroy(Obj *self);
 
-    /** Invoke the [](cfish:.Destroy) method found in `klass` on
-     * `self`.
-     *
-     * TODO: Eliminate this function if we can arrive at a proper SUPER syntax.
-     */
-    inert inline void
-    super_destroy(Obj *self, Class *klass);
-
     /** Indicate whether two objects are the same.  By default, compares the
      * memory address.
      *
@@ -155,32 +131,52 @@ public class Clownfish::Obj {
 }
 
 __C__
+/** Invoke the [](cfish:.Destroy) method found in `klass` on
+ * `self`.
+ *
+ * TODO: Eliminate this function if we can arrive at a proper SUPER syntax.
+ */
 static CFISH_INLINE void
-cfish_Obj_super_destroy(cfish_Obj *self, cfish_Class *klass) {
-    CFISH_Obj_Destroy_t super_destroy
-        = CFISH_SUPER_METHOD_PTR(klass, CFISH_Obj_Destroy);
-    super_destroy(self);
+cfish_super_destroy(void *vself, cfish_Class *klass) {
+    cfish_Obj *self = (cfish_Obj*)vself;
+    if (self != NULL) {
+        CFISH_Obj_Destroy_t super_destroy
+            = CFISH_SUPER_METHOD_PTR(klass, CFISH_Obj_Destroy);
+        super_destroy(self);
+    }
 }
 
 #define CFISH_SUPER_DESTROY(_self, _class) \
-    cfish_Obj_super_destroy((cfish_Obj*)_self, _class)
+    cfish_super_destroy(_self, _class)
 
+/** NULL-safe invocation of [](cfish:.Inc_RefCount).
+ *
+ * @return NULL if `self` is NULL, otherwise the return value
+ * of [](cfish:.Inc_RefCount).
+ */
 static CFISH_INLINE cfish_Obj*
-cfish_Obj_incref(cfish_Obj *self) {
+cfish_incref(void *vself) {
+    cfish_Obj *self = (cfish_Obj*)vself;
     if (self != NULL) { return CFISH_Obj_Inc_RefCount(self); }
     else { return NULL; }
 }
 
-#define CFISH_INCREF(_self) cfish_Obj_incref((cfish_Obj*)_self)
+#define CFISH_INCREF(_self) cfish_incref(_self)
 #define CFISH_INCREF_NN(_self) CFISH_Obj_Inc_RefCount((cfish_Obj*)_self)
 
+/** NULL-safe invocation of [](cfish:.Dec_RefCount).
+ *
+ * @return NULL if `self` is NULL, otherwise the return value
+ * of [](cfish:.Dec_RefCount).
+ */
 static CFISH_INLINE uint32_t
-cfish_Obj_decref(cfish_Obj *self) {
+cfish_decref(void *vself) {
+    cfish_Obj *self = (cfish_Obj*)vself;
     if (self != NULL) { return CFISH_Obj_Dec_RefCount(self); }
     else { return 0; }
 }
 
-#define CFISH_DECREF(_self) cfish_Obj_decref((cfish_Obj*)_self)
+#define CFISH_DECREF(_self) cfish_decref(_self)
 #define CFISH_DECREF_NN(_self) CFISH_Obj_Dec_RefCount((cfish_Obj*)_self)
 
 static CFISH_INLINE uint32_t