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:53 UTC
[03/16] lucy-clownfish git commit: Replace refcounting method call
invocations.
Replace refcounting method call invocations.
Introduce not-null ("NN") macros to increment, decrement or obtain an
object's refcount and swap them in for all direct method calls.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/93c2bfd4
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/93c2bfd4
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/93c2bfd4
Branch: refs/heads/master
Commit: 93c2bfd42fc0ddd84554168b21bb9c543be2c4d3
Parents: d1a2034
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Feb 7 08:31:45 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Feb 7 08:44:33 2015 -0800
----------------------------------------------------------------------
compiler/src/CFCPerlConstructor.c | 2 +-
runtime/core/Clownfish/Err.cfh | 2 +-
runtime/core/Clownfish/Obj.cfh | 13 +++++++++++++
runtime/core/Clownfish/Test/TestObj.c | 10 +++++-----
runtime/core/Clownfish/Test/TestVArray.c | 4 ++--
runtime/perl/xs/XSBind.h | 2 +-
6 files changed, 23 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/93c2bfd4/compiler/src/CFCPerlConstructor.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlConstructor.c b/compiler/src/CFCPerlConstructor.c
index e03487a..5752e43 100644
--- a/compiler/src/CFCPerlConstructor.c
+++ b/compiler/src/CFCPerlConstructor.c
@@ -134,7 +134,7 @@ CFCPerlConstructor_xsub_def(CFCPerlConstructor *self) {
" retval = %s(%s);\n"
" if (retval) {\n"
" ST(0) = (SV*)CFISH_Obj_To_Host((cfish_Obj*)retval);\n"
- " CFISH_Obj_Dec_RefCount((cfish_Obj*)retval);\n"
+ " CFISH_DECREF_NN(retval);\n"
" }\n"
" else {\n"
" ST(0) = newSV(0);\n"
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/93c2bfd4/runtime/core/Clownfish/Err.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Err.cfh b/runtime/core/Clownfish/Err.cfh
index bae7e9e..da63a0f 100644
--- a/runtime/core/Clownfish/Err.cfh
+++ b/runtime/core/Clownfish/Err.cfh
@@ -241,7 +241,7 @@ cfish_Err_abstract_class_check(cfish_Obj *obj, cfish_Class *klass) {
if (my_class == klass) {
cfish_String *mess = CFISH_MAKE_MESS("%o is an abstract class",
CFISH_Obj_Get_Class_Name(obj));
- CFISH_Obj_Dec_RefCount(obj);
+ CFISH_DECREF_NN(obj);
cfish_Err_throw_mess(CFISH_ERR, mess);
}
}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/93c2bfd4/runtime/core/Clownfish/Obj.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Obj.cfh b/runtime/core/Clownfish/Obj.cfh
index 930e1f5..aa9f9f4 100644
--- a/runtime/core/Clownfish/Obj.cfh
+++ b/runtime/core/Clownfish/Obj.cfh
@@ -172,6 +172,7 @@ cfish_Obj_incref(cfish_Obj *self) {
}
#define CFISH_INCREF(_self) cfish_Obj_incref((cfish_Obj*)_self)
+#define CFISH_INCREF_NN(_self) CFISH_Obj_Inc_RefCount((cfish_Obj*)_self)
static CFISH_INLINE uint32_t
cfish_Obj_decref(cfish_Obj *self) {
@@ -180,11 +181,23 @@ cfish_Obj_decref(cfish_Obj *self) {
}
#define CFISH_DECREF(_self) cfish_Obj_decref((cfish_Obj*)_self)
+#define CFISH_DECREF_NN(_self) CFISH_Obj_Dec_RefCount((cfish_Obj*)_self)
+
+static CFISH_INLINE uint32_t
+cfish_refcount(void *vself) {
+ return CFISH_Obj_Get_RefCount((cfish_Obj*)vself);
+}
+
+#define CFISH_REFCOUNT_NN(_self) \
+ cfish_refcount(_self)
#ifdef CFISH_USE_SHORT_NAMES
#define SUPER_DESTROY(_self, _class) CFISH_SUPER_DESTROY(_self, _class)
#define INCREF(_self) CFISH_INCREF(_self)
+ #define INCREF_NN(_self) CFISH_INCREF_NN(_self)
#define DECREF(_self) CFISH_DECREF(_self)
+ #define DECREF_NN(_self) CFISH_DECREF_NN(_self)
+ #define REFCOUNT_NN(_self) CFISH_REFCOUNT_NN(_self)
#endif
__END_C__
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/93c2bfd4/runtime/core/Clownfish/Test/TestObj.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestObj.c b/runtime/core/Clownfish/Test/TestObj.c
index a0ea072..e0bcf6a 100644
--- a/runtime/core/Clownfish/Test/TestObj.c
+++ b/runtime/core/Clownfish/Test/TestObj.c
@@ -50,14 +50,14 @@ static void
test_refcounts(TestBatchRunner *runner) {
Obj *obj = S_new_testobj();
- TEST_INT_EQ(runner, Obj_Get_RefCount(obj), 1,
+ TEST_INT_EQ(runner, CFISH_REFCOUNT_NN(obj), 1,
"Correct starting refcount");
- obj = Obj_Inc_RefCount(obj);
- TEST_INT_EQ(runner, Obj_Get_RefCount(obj), 2, "Inc_RefCount");
+ obj = CFISH_INCREF_NN(obj);
+ TEST_INT_EQ(runner, CFISH_REFCOUNT_NN(obj), 2, "INCREF_NN");
- Obj_Dec_RefCount(obj);
- TEST_INT_EQ(runner, Obj_Get_RefCount(obj), 1, "Dec_RefCount");
+ CFISH_DECREF_NN(obj);
+ TEST_INT_EQ(runner, CFISH_REFCOUNT_NN(obj), 1, "DECREF_NN");
DECREF(obj);
}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/93c2bfd4/runtime/core/Clownfish/Test/TestVArray.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestVArray.c b/runtime/core/Clownfish/Test/TestVArray.c
index 10255f7..2e47a67 100644
--- a/runtime/core/Clownfish/Test/TestVArray.c
+++ b/runtime/core/Clownfish/Test/TestVArray.c
@@ -89,10 +89,10 @@ test_Store_Fetch(TestBatchRunner *runner) {
TEST_TRUE(runner, Str_Equals_Utf8(elem, "foo", 3), "Store");
elem = (String*)INCREF(elem);
- TEST_INT_EQ(runner, 2, Str_Get_RefCount(elem),
+ TEST_INT_EQ(runner, 2, CFISH_REFCOUNT_NN(elem),
"start with refcount of 2");
VA_Store(array, 2, (Obj*)Str_newf("bar"));
- TEST_INT_EQ(runner, 1, Str_Get_RefCount(elem),
+ TEST_INT_EQ(runner, 1, CFISH_REFCOUNT_NN(elem),
"Displacing elem via Store updates refcount");
DECREF(elem);
elem = (String*)CERTIFY(VA_Fetch(array, 2), STRING);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/93c2bfd4/runtime/perl/xs/XSBind.h
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.h b/runtime/perl/xs/XSBind.h
index 5e6c096..5d237fc 100644
--- a/runtime/perl/xs/XSBind.h
+++ b/runtime/perl/xs/XSBind.h
@@ -100,7 +100,7 @@ cfish_XSBind_cfish_obj_to_sv_noinc(cfish_Obj *obj) {
SV *retval;
if (obj) {
retval = (SV*)CFISH_Obj_To_Host(obj);
- CFISH_Obj_Dec_RefCount(obj);
+ CFISH_DECREF_NN(obj);
}
else {
retval = newSV(0);