Replace refcounting methods with functions. Each host must now provide implementations for three functions:
* `cfish_get_refcount` * `cfish_inc_refcount` * `cfish_dec_refcount` Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/e5794914 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/e5794914 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/e5794914 Branch: refs/heads/master Commit: e5794914faf239f000d52cc9513ffbdcdd07ce5e Parents: 7adc306 Author: Marvin Humphrey <[email protected]> Authored: Sat Feb 7 11:45:12 2015 -0800 Committer: Marvin Humphrey <[email protected]> Committed: Sat Feb 7 15:39:31 2015 -0800 ---------------------------------------------------------------------- runtime/c/src/Clownfish/Obj.c | 13 ++----- runtime/core/Clownfish/Obj.cfh | 51 +++++++++------------------ runtime/example-lang/src/Clownfish/Obj.c | 6 ++-- runtime/perl/xs/XSBind.c | 13 ++----- 4 files changed, 24 insertions(+), 59 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/e5794914/runtime/c/src/Clownfish/Obj.c ---------------------------------------------------------------------- diff --git a/runtime/c/src/Clownfish/Obj.c b/runtime/c/src/Clownfish/Obj.c index 296192d..222b283 100644 --- a/runtime/c/src/Clownfish/Obj.c +++ b/runtime/c/src/Clownfish/Obj.c @@ -24,7 +24,8 @@ #include "Clownfish/String.h" uint32_t -Obj_Get_RefCount_IMP(Obj *self) { +cfish_get_refcount(void *vself) { + cfish_Obj *self = (cfish_Obj*)vself; return self->refcount; } @@ -68,11 +69,6 @@ cfish_inc_refcount(void *vself) { } } -Obj* -Obj_Inc_RefCount_IMP(Obj *self) { - return cfish_inc_refcount(self); -} - uint32_t cfish_dec_refcount(void *vself) { cfish_Obj *self = (Obj*)vself; @@ -97,11 +93,6 @@ cfish_dec_refcount(void *vself) { return modified_refcount; } -uint32_t -Obj_Dec_RefCount_IMP(Obj *self) { - return cfish_dec_refcount(self); -} - void* Obj_To_Host_IMP(Obj *self) { UNUSED_VAR(self); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/e5794914/runtime/core/Clownfish/Obj.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Obj.cfh b/runtime/core/Clownfish/Obj.cfh index 1cba9f0..028d802 100644 --- a/runtime/core/Clownfish/Obj.cfh +++ b/runtime/core/Clownfish/Obj.cfh @@ -28,25 +28,6 @@ public class Clownfish::Obj { public inert Obj* init(Obj* self); - /** Return an object's refcount. - */ - uint32_t - Get_RefCount(Obj *self); - - /** Increment an object's refcount. - * - * @return The object, allowing an assignment idiom. - */ - incremented Obj* - Inc_RefCount(Obj *self); - - /** Decrement an object's refcount, calling [](cfish:.Destroy) if it hits 0. - * - * @return the modified refcount. - */ - uint32_t - Dec_RefCount(Obj *self); - /** Return a host-language object wrapper for this object. */ void* @@ -149,43 +130,45 @@ cfish_super_destroy(void *vself, cfish_Class *klass) { #define CFISH_SUPER_DESTROY(_self, _class) \ cfish_super_destroy(_self, _class) -/** NULL-safe invocation of [](cfish:.Inc_RefCount). +extern CFISH_VISIBLE cfish_Obj* +cfish_inc_refcount(void *vself); + +/** NULL-safe invocation invocation of `cfish_inc_refcount`. * * @return NULL if `self` is NULL, otherwise the return value - * of [](cfish:.Inc_RefCount). + * of `cfish_inc_refcount`. */ static CFISH_INLINE cfish_Obj* cfish_incref(void *vself) { - cfish_Obj *self = (cfish_Obj*)vself; - if (self != NULL) { return CFISH_Obj_Inc_RefCount(self); } + if (vself != NULL) { return cfish_inc_refcount(vself); } else { return NULL; } } #define CFISH_INCREF(_self) cfish_incref(_self) -#define CFISH_INCREF_NN(_self) CFISH_Obj_Inc_RefCount((cfish_Obj*)_self) +#define CFISH_INCREF_NN(_self) cfish_inc_refcount(_self) + +extern CFISH_VISIBLE uint32_t +cfish_dec_refcount(void *vself); -/** NULL-safe invocation of [](cfish:.Dec_RefCount). +/** NULL-safe invocation of `cfish_dec_refcount`. * * @return NULL if `self` is NULL, otherwise the return value - * of [](cfish:.Dec_RefCount). + * of `cfish_dec_refcount`. */ static CFISH_INLINE uint32_t cfish_decref(void *vself) { - cfish_Obj *self = (cfish_Obj*)vself; - if (self != NULL) { return CFISH_Obj_Dec_RefCount(self); } + if (vself != NULL) { return cfish_dec_refcount(vself); } else { return 0; } } #define CFISH_DECREF(_self) cfish_decref(_self) -#define CFISH_DECREF_NN(_self) CFISH_Obj_Dec_RefCount((cfish_Obj*)_self) +#define CFISH_DECREF_NN(_self) cfish_dec_refcount(_self) -static CFISH_INLINE uint32_t -cfish_refcount(void *vself) { - return CFISH_Obj_Get_RefCount((cfish_Obj*)vself); -} +extern CFISH_VISIBLE uint32_t +cfish_get_refcount(void *vself); #define CFISH_REFCOUNT_NN(_self) \ - cfish_refcount(_self) + cfish_get_refcount(_self) #ifdef CFISH_USE_SHORT_NAMES #define SUPER_DESTROY(_self, _class) CFISH_SUPER_DESTROY(_self, _class) http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/e5794914/runtime/example-lang/src/Clownfish/Obj.c ---------------------------------------------------------------------- diff --git a/runtime/example-lang/src/Clownfish/Obj.c b/runtime/example-lang/src/Clownfish/Obj.c index f8679c8..c4a5dce 100644 --- a/runtime/example-lang/src/Clownfish/Obj.c +++ b/runtime/example-lang/src/Clownfish/Obj.c @@ -19,19 +19,19 @@ #include "CFBind.h" uint32_t -CFISH_Obj_Get_RefCount_IMP(cfish_Obj *self) { +cfish_get_refcount(void *vself) { THROW(CFISH_ERR, "TODO"); UNREACHABLE_RETURN(uint32_t); } cfish_Obj* -CFISH_Obj_Inc_RefCount_IMP(cfish_Obj *self) { +cfish_inc_refcount(void *vself) { THROW(CFISH_ERR, "TODO"); UNREACHABLE_RETURN(cfish_Obj*); } uint32_t -CFISH_Obj_Dec_RefCount_IMP(cfish_Obj *self) { +cfish_dec_refcount(void *vself) { THROW(CFISH_ERR, "TODO"); UNREACHABLE_RETURN(uint32_t); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/e5794914/runtime/perl/xs/XSBind.c ---------------------------------------------------------------------- diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c index 07e3fc6..d624ff7 100644 --- a/runtime/perl/xs/XSBind.c +++ b/runtime/perl/xs/XSBind.c @@ -643,7 +643,8 @@ S_lazy_init_host_obj(cfish_Obj *self) { } uint32_t -CFISH_Obj_Get_RefCount_IMP(cfish_Obj *self) { +cfish_get_refcount(void *vself) { + cfish_Obj *self = (cfish_Obj*)vself; return self->ref.count & XSBIND_REFCOUNT_FLAG ? self->ref.count >> XSBIND_REFCOUNT_SHIFT : SvREFCNT((SV*)self->ref.host_obj); @@ -676,11 +677,6 @@ cfish_inc_refcount(void *vself) { return self; } -cfish_Obj* -CFISH_Obj_Inc_RefCount_IMP(cfish_Obj *self) { - return cfish_inc_refcount(self); -} - uint32_t cfish_dec_refcount(void *vself) { cfish_Obj *self = (cfish_Obj*)vself; @@ -713,11 +709,6 @@ cfish_dec_refcount(void *vself) { return modified_refcount; } -uint32_t -CFISH_Obj_Dec_RefCount_IMP(cfish_Obj *self) { - return cfish_dec_refcount(self); -} - void* CFISH_Obj_To_Host_IMP(cfish_Obj *self) { if (self->ref.count & XSBIND_REFCOUNT_FLAG) { S_lazy_init_host_obj(self); }
