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:51 UTC
[01/16] lucy-clownfish git commit: Skip tests with memory leaks under
valgrind.
Repository: lucy-clownfish
Updated Branches:
refs/heads/master 5055c1ae2 -> 5646bf057
Skip tests with memory leaks under valgrind.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/532c6d6c
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/532c6d6c
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/532c6d6c
Branch: refs/heads/master
Commit: 532c6d6cfe68a79d7556aa910b64a87a1b4282b4
Parents: cf94088
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri Feb 6 10:51:29 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Feb 7 07:36:32 2015 -0800
----------------------------------------------------------------------
runtime/core/Clownfish/Test/TestVArray.c | 5 +++++
runtime/perl/t/binding/019-obj.t | 8 ++++----
2 files changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/532c6d6c/runtime/core/Clownfish/Test/TestVArray.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestVArray.c b/runtime/core/Clownfish/Test/TestVArray.c
index 923d637..10255f7 100644
--- a/runtime/core/Clownfish/Test/TestVArray.c
+++ b/runtime/core/Clownfish/Test/TestVArray.c
@@ -15,6 +15,7 @@
*/
#include <string.h>
+#include <stdlib.h>
#define C_CFISH_VARRAY
#define CFISH_USE_SHORT_NAMES
@@ -341,6 +342,10 @@ S_test_exception(TestBatchRunner *runner, Err_Attempt_t func,
static void
test_exceptions(TestBatchRunner *runner) {
+ if (getenv("LUCY_VALGRIND")) {
+ SKIP(runner, 4, "memory leak");
+ return;
+ }
S_test_exception(runner, S_overflow_Push,
"Push throws on overflow");
S_test_exception(runner, S_overflow_Unshift,
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/532c6d6c/runtime/perl/t/binding/019-obj.t
----------------------------------------------------------------------
diff --git a/runtime/perl/t/binding/019-obj.t b/runtime/perl/t/binding/019-obj.t
index c548634..06e3642 100644
--- a/runtime/perl/t/binding/019-obj.t
+++ b/runtime/perl/t/binding/019-obj.t
@@ -120,7 +120,7 @@ like( $object->to_string, qr/STRING:.*?SonOfTestObj/,
"overridden XS bindings can be called via SUPER" );
SKIP: {
- skip( "Exception thrown within callback leaks", 1 )
+ skip( "Exception thrown within callback leaks", 2 )
if $ENV{LUCY_VALGRIND};
# The Perl binding for VArray#store calls inc_refcount() from C space.
@@ -132,10 +132,10 @@ SKIP: {
eval { $array->store( 1, BadRefCount->new ); };
like( $@, qr/NULL/,
"Don't allow methods without nullable return values to return NULL" );
-}
-eval { InvalidCallbackTestObj->new; };
-like( $@, qr/Can't override CFISH_Obj_To_Host via binding/ );
+ eval { InvalidCallbackTestObj->new; };
+ like( $@, qr/Can't override CFISH_Obj_To_Host via binding/ );
+}
my $alias_test = Clownfish::Test::AliasTestObj->new;
is( $alias_test->perl_alias, 'C', "Host method aliases work" );
[08/16] lucy-clownfish git commit: Replace refcounting methods with
functions.
Posted by ma...@apache.org.
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 <ma...@rectangular.com>
Authored: Sat Feb 7 11:45:12 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
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); }
[14/16] lucy-clownfish git commit: Consolidate SvSHARE calls on
cached host obj.
Posted by ma...@apache.org.
Consolidate SvSHARE calls on cached host obj.
Call SvSHARE on all cached host objects before they are even cached.
This allows us to eliminate method overriding for To_Host for both Class
and LockFreeRegistry. Also, other immortals are now shared properly.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/55b19f45
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/55b19f45
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/55b19f45
Branch: refs/heads/master
Commit: 55b19f459b049cc22f00890f6099eec64e0fb9b2
Parents: afde943
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sun Feb 8 21:34:08 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Feb 8 21:34:08 2015 -0800
----------------------------------------------------------------------
runtime/c/src/Clownfish/Class.c | 7 -----
runtime/c/src/Clownfish/LockFreeRegistry.c | 32 --------------------
runtime/core/Clownfish/Class.cfh | 3 --
runtime/core/Clownfish/LockFreeRegistry.cfh | 3 --
runtime/example-lang/src/Clownfish/Class.c | 6 ----
.../src/Clownfish/LockFreeRegistry.c | 28 -----------------
runtime/perl/xs/XSBind.c | 28 +----------------
7 files changed, 1 insertion(+), 106 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/55b19f45/runtime/c/src/Clownfish/Class.c
----------------------------------------------------------------------
diff --git a/runtime/c/src/Clownfish/Class.c b/runtime/c/src/Clownfish/Class.c
index 82a5892..1ad617d 100644
--- a/runtime/c/src/Clownfish/Class.c
+++ b/runtime/c/src/Clownfish/Class.c
@@ -69,10 +69,3 @@ Class_find_parent_class(String *class_name) {
UNREACHABLE_RETURN(String*);
}
-void*
-Class_To_Host_IMP(Class *self) {
- UNUSED_VAR(self);
- THROW(ERR, "TODO");
- UNREACHABLE_RETURN(void*);
-}
-
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/55b19f45/runtime/c/src/Clownfish/LockFreeRegistry.c
----------------------------------------------------------------------
diff --git a/runtime/c/src/Clownfish/LockFreeRegistry.c b/runtime/c/src/Clownfish/LockFreeRegistry.c
deleted file mode 100644
index 396b78b..0000000
--- a/runtime/c/src/Clownfish/LockFreeRegistry.c
+++ /dev/null
@@ -1,32 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define C_CFISH_LOCKFREEREGISTRY
-#define CFISH_USE_SHORT_NAMES
-
-#include "charmony.h"
-
-#include "Clownfish/LockFreeRegistry.h"
-#include "Clownfish/Err.h"
-
-void*
-LFReg_To_Host_IMP(LockFreeRegistry *self) {
- UNUSED_VAR(self);
- THROW(ERR, "TODO");
- UNREACHABLE_RETURN(void*);
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/55b19f45/runtime/core/Clownfish/Class.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Class.cfh b/runtime/core/Clownfish/Class.cfh
index 23623b7..566f29f 100644
--- a/runtime/core/Clownfish/Class.cfh
+++ b/runtime/core/Clownfish/Class.cfh
@@ -138,9 +138,6 @@ class Clownfish::Class inherits Clownfish::Obj {
public incremented Class*
Clone(Class *self);
- void*
- To_Host(Class *self);
-
public void
Destroy(Class *self);
}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/55b19f45/runtime/core/Clownfish/LockFreeRegistry.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/LockFreeRegistry.cfh b/runtime/core/Clownfish/LockFreeRegistry.cfh
index bb41fbd..330507b 100644
--- a/runtime/core/Clownfish/LockFreeRegistry.cfh
+++ b/runtime/core/Clownfish/LockFreeRegistry.cfh
@@ -37,9 +37,6 @@ class Clownfish::LockFreeRegistry nickname LFReg inherits Clownfish::Obj {
nullable Obj*
Fetch(LockFreeRegistry *self, Obj *key);
-
- void*
- To_Host(LockFreeRegistry *self);
}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/55b19f45/runtime/example-lang/src/Clownfish/Class.c
----------------------------------------------------------------------
diff --git a/runtime/example-lang/src/Clownfish/Class.c b/runtime/example-lang/src/Clownfish/Class.c
index 19abca4..ca0f89d 100644
--- a/runtime/example-lang/src/Clownfish/Class.c
+++ b/runtime/example-lang/src/Clownfish/Class.c
@@ -54,9 +54,3 @@ cfish_Class_find_parent_class(const cfish_String *class_name) {
UNREACHABLE_RETURN(cfish_String*);
}
-void*
-CFISH_Class_To_Host_IMP(cfish_Class *self) {
- THROW(CFISH_ERR, "TODO");
- UNREACHABLE_RETURN(void*);
-}
-
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/55b19f45/runtime/example-lang/src/Clownfish/LockFreeRegistry.c
----------------------------------------------------------------------
diff --git a/runtime/example-lang/src/Clownfish/LockFreeRegistry.c b/runtime/example-lang/src/Clownfish/LockFreeRegistry.c
deleted file mode 100644
index cbc0c60..0000000
--- a/runtime/example-lang/src/Clownfish/LockFreeRegistry.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define C_CFISH_LOCKFREEREGISTRY
-
-#include "CFBind.h"
-#include "Clownfish/LockFreeRegistry.h"
-
-void*
-CFISH_LFReg_To_Host_IMP(cfish_LockFreeRegistry *self) {
- THROW(CFISH_ERR, "TODO");
- UNREACHABLE_RETURN(void*);
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/55b19f45/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index ae5591a..2534c8d 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -653,6 +653,7 @@ S_lazy_init_host_obj(cfish_Obj *self) {
// Overwrite refcount with host object.
cfish_Class *klass = self->klass;
if (SI_immortal(klass) || SI_threadsafe_but_not_immortal(klass)) {
+ SvSHARE(inner_obj);
if (!cfish_Atomic_cas_ptr((void**)&self->ref, old_ref.host_obj, inner_obj)) {
// Another thread beat us to it. Now we have a Perl object to defuse.
SvSTASH_set(inner_obj, NULL);
@@ -842,19 +843,6 @@ cfish_Class_find_parent_class(cfish_String *class_name) {
return parent_class;
}
-void*
-CFISH_Class_To_Host_IMP(cfish_Class *self) {
- bool first_time = self->ref.count & XSBIND_REFCOUNT_FLAG ? true : false;
- CFISH_Class_To_Host_t to_host
- = CFISH_SUPER_METHOD_PTR(CFISH_CLASS, CFISH_Class_To_Host);
- SV *host_obj = (SV*)to_host(self);
- if (first_time) {
- SvSHARE((SV*)self->ref.host_obj);
- }
- return host_obj;
-}
-
-
/*************************** Clownfish::Method ******************************/
cfish_String*
@@ -1031,20 +1019,6 @@ cfish_Err_trap(CFISH_Err_Attempt_t routine, void *context) {
return error;
}
-/*********************** Clownfish::LockFreeRegistry ************************/
-
-void*
-CFISH_LFReg_To_Host_IMP(cfish_LockFreeRegistry *self) {
- bool first_time = self->ref.count & XSBIND_REFCOUNT_FLAG ? true : false;
- CFISH_LFReg_To_Host_t to_host
- = CFISH_SUPER_METHOD_PTR(CFISH_LOCKFREEREGISTRY, CFISH_LFReg_To_Host);
- SV *host_obj = (SV*)to_host(self);
- if (first_time) {
- SvSHARE((SV*)self->ref.host_obj);
- }
- return host_obj;
-}
-
/*********************** Clownfish::Test::TestThreads ***********************/
void
[03/16] lucy-clownfish git commit: Replace refcounting method call
invocations.
Posted by ma...@apache.org.
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);
[12/16] lucy-clownfish git commit: Use atomic op for setting cached
host obj.
Posted by ma...@apache.org.
Use atomic op for setting cached host obj.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/52b1f981
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/52b1f981
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/52b1f981
Branch: refs/heads/master
Commit: 52b1f981408a7820ad0384593d4c1c61a147e7bb
Parents: 2dab35a
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sun Feb 8 21:02:15 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Feb 8 21:02:15 2015 -0800
----------------------------------------------------------------------
runtime/perl/xs/XSBind.c | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/52b1f981/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index 659ab35..d29d1ec 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -27,6 +27,7 @@
#include "Clownfish/Method.h"
#include "Clownfish/Test/TestThreads.h"
#include "Clownfish/TestHarness/TestBatchRunner.h"
+#include "Clownfish/Util/Atomic.h"
#include "Clownfish/Util/StringHelper.h"
#include "Clownfish/Util/NumberUtils.h"
#include "Clownfish/Util/Memory.h"
@@ -645,9 +646,28 @@ S_lazy_init_host_obj(cfish_Obj *self) {
* will assume responsibility for maintaining the refcount. ref.host_obj
* starts off with a refcount of 1, so we need to transfer any refcounts
* in excess of that. */
- size_t old_refcount = self->ref.count;
- self->ref.host_obj = inner_obj;
- SvREFCNT(inner_obj) += (old_refcount >> XSBIND_REFCOUNT_SHIFT) - 1;
+ cfish_ref_t old_ref = self->ref;
+ size_t excess = (old_ref.count >> XSBIND_REFCOUNT_SHIFT) - 1;
+ SvREFCNT(inner_obj) += excess;
+
+ // Overwrite refcount with host object.
+ cfish_Class *klass = self->klass;
+ if (SI_immortal(klass) || SI_threadsafe_but_not_immortal(klass)) {
+ if (!cfish_Atomic_cas_ptr((void**)&self->ref, old_ref.host_obj, inner_obj)) {
+ // Another thread beat us to it. Now we have a Perl object to defuse.
+ SvSTASH_set(inner_obj, NULL);
+ SvREFCNT_dec((SV*)stash);
+ SvOBJECT_off(inner_obj);
+ SvREFCNT(inner_obj) -= excess;
+ SvREFCNT_dec(inner_obj);
+#if (PERL_VERSION <= 16)
+ PL_sv_objcount--;
+#endif
+ }
+ }
+ else {
+ self->ref.host_obj = inner_obj;
+ }
}
uint32_t
[07/16] lucy-clownfish git commit: Normalize arg typing for obj
allocation macros.
Posted by ma...@apache.org.
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
[16/16] lucy-clownfish git commit: Merge branch
'CLOWNFISH-27-refcount_functions'
Posted by ma...@apache.org.
Merge branch 'CLOWNFISH-27-refcount_functions'
Refcount manipulation is challenging to get right across multiple host
languages. It is not something we can sanely document and design for
extensibility, so overriding it via the method hierarchy should not be a
user-level feature.
This closes #3
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/5646bf05
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/5646bf05
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/5646bf05
Branch: refs/heads/master
Commit: 5646bf0573fe32d1ec0709b3d47741f6f1e08f19
Parents: 5055c1a c0b9090
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri Feb 13 13:31:21 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Fri Feb 13 13:31:21 2015 -0800
----------------------------------------------------------------------
compiler/src/CFCBindCore.c | 78 ++++++++++-
compiler/src/CFCPerlConstructor.c | 2 +-
runtime/c/src/Clownfish/Class.c | 7 -
runtime/c/src/Clownfish/LockFreeRegistry.c | 32 -----
runtime/c/src/Clownfish/Obj.c | 71 +++++++++-
runtime/core/Clownfish/Class.c | 60 ++++-----
runtime/core/Clownfish/Class.cfh | 13 +-
runtime/core/Clownfish/Err.cfh | 2 +-
runtime/core/Clownfish/Hash.c | 20 ---
runtime/core/Clownfish/Hash.cfh | 9 --
runtime/core/Clownfish/LockFreeRegistry.cfh | 3 -
runtime/core/Clownfish/Method.c | 40 +++---
runtime/core/Clownfish/Method.cfh | 14 +-
runtime/core/Clownfish/Num.c | 11 --
runtime/core/Clownfish/Num.cfh | 6 -
runtime/core/Clownfish/Obj.cfh | 79 -----------
runtime/core/Clownfish/String.c | 15 +--
runtime/core/Clownfish/String.cfh | 4 +-
runtime/core/Clownfish/Test/TestObj.c | 10 +-
runtime/core/Clownfish/Test/TestVArray.c | 9 +-
runtime/example-lang/src/Clownfish/Class.c | 6 -
.../src/Clownfish/LockFreeRegistry.c | 28 ----
runtime/example-lang/src/Clownfish/Obj.c | 6 +-
.../perl/buildlib/Clownfish/Build/Binding.pm | 15 +++
runtime/perl/t/binding/019-obj.t | 41 +++---
runtime/perl/xs/XSBind.c | 130 ++++++++++++++-----
runtime/perl/xs/XSBind.h | 2 +-
27 files changed, 346 insertions(+), 367 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5646bf05/compiler/src/CFCBindCore.c
----------------------------------------------------------------------
[09/16] lucy-clownfish git commit: Superficial changes to
SUPER_DESTROY.
Posted by ma...@apache.org.
Superficial changes to SUPER_DESTROY.
Don't depend on Obj.h definitions.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/436a6850
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/436a6850
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/436a6850
Branch: refs/heads/master
Commit: 436a6850ffeecf0ad5b81aa2a0d50788ba15400f
Parents: e579491
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Feb 7 15:40:49 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Feb 7 15:40:49 2015 -0800
----------------------------------------------------------------------
runtime/core/Clownfish/Obj.cfh | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/436a6850/runtime/core/Clownfish/Obj.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Obj.cfh b/runtime/core/Clownfish/Obj.cfh
index 028d802..2feadfa 100644
--- a/runtime/core/Clownfish/Obj.cfh
+++ b/runtime/core/Clownfish/Obj.cfh
@@ -112,6 +112,11 @@ public class Clownfish::Obj {
}
__C__
+
+typedef void
+(*cfish_destroy_t)(void *vself);
+extern CFISH_VISIBLE size_t CFISH_Obj_Destroy_OFFSET;
+
/** Invoke the [](cfish:.Destroy) method found in `klass` on
* `self`.
*
@@ -121,8 +126,8 @@ static CFISH_INLINE void
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);
+ cfish_destroy_t super_destroy
+ = (cfish_destroy_t)cfish_super_method(klass, CFISH_Obj_Destroy_OFFSET);
super_destroy(self);
}
}
[02/16] lucy-clownfish git commit: Consolidate refcount manipulation
for "immortals".
Posted by ma...@apache.org.
Consolidate refcount manipulation for "immortals".
Instead of having the "immortal classes" override refcounting methods,
special-case them within a consolidated refcounting function.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/d1a20342
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/d1a20342
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/d1a20342
Branch: refs/heads/master
Commit: d1a20342781b2aff9f6c360590fc55856516ae90
Parents: 532c6d6
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Thu Feb 5 20:21:31 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Feb 7 07:40:07 2015 -0800
----------------------------------------------------------------------
runtime/c/src/Clownfish/Obj.c | 41 +++++++++++++++++++++++++++++++---
runtime/core/Clownfish/Class.c | 29 ------------------------
runtime/core/Clownfish/Class.cfh | 9 --------
runtime/core/Clownfish/Hash.c | 20 -----------------
runtime/core/Clownfish/Hash.cfh | 9 --------
runtime/core/Clownfish/Method.c | 18 ---------------
runtime/core/Clownfish/Method.cfh | 9 --------
runtime/core/Clownfish/Num.c | 11 ---------
runtime/core/Clownfish/Num.cfh | 6 -----
runtime/perl/xs/XSBind.c | 38 +++++++++++++++++++++++++++++--
10 files changed, 74 insertions(+), 116 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d1a20342/runtime/c/src/Clownfish/Obj.c
----------------------------------------------------------------------
diff --git a/runtime/c/src/Clownfish/Obj.c b/runtime/c/src/Clownfish/Obj.c
index 24cbfd1..e17feef 100644
--- a/runtime/c/src/Clownfish/Obj.c
+++ b/runtime/c/src/Clownfish/Obj.c
@@ -27,14 +27,44 @@ Obj_Get_RefCount_IMP(Obj *self) {
return self->refcount;
}
+static CFISH_INLINE bool
+SI_immortal(cfish_Class *klass) {
+ if (klass == CFISH_CLASS
+ || klass == CFISH_METHOD
+ || klass == CFISH_BOOLNUM
+ || klass == CFISH_HASHTOMBSTONE
+ ){
+ return true;
+ }
+ return false;
+}
+
+Obj*
+cfish_inc_refcount(void *vself) {
+ Obj *self = (Obj*)vself;
+ cfish_Class *const klass = self->klass;
+ if (SI_immortal(klass)) {
+ return self;
+ }
+ else {
+ self->refcount++;
+ return self;
+ }
+}
+
Obj*
Obj_Inc_RefCount_IMP(Obj *self) {
- self->refcount++;
- return self;
+ return cfish_inc_refcount(self);
}
uint32_t
-Obj_Dec_RefCount_IMP(Obj *self) {
+cfish_dec_refcount(void *vself) {
+ cfish_Obj *self = (Obj*)vself;
+ cfish_Class *klass = self->klass;
+ if (SI_immortal(klass)) {
+ return self->refcount;
+ }
+
uint32_t modified_refcount = INT32_MAX;
switch (self->refcount) {
case 0:
@@ -51,6 +81,11 @@ Obj_Dec_RefCount_IMP(Obj *self) {
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/d1a20342/runtime/core/Clownfish/Class.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Class.c b/runtime/core/Clownfish/Class.c
index 81c3138..b30b124 100644
--- a/runtime/core/Clownfish/Class.c
+++ b/runtime/core/Clownfish/Class.c
@@ -183,35 +183,6 @@ Class_Clone_IMP(Class *self) {
return twin;
}
-Obj*
-Class_Inc_RefCount_IMP(Class *self) {
- return (Obj*)self;
-}
-
-uint32_t
-Class_Dec_RefCount_IMP(Class *self) {
- UNUSED_VAR(self);
- return 1;
-}
-
-uint32_t
-Class_Get_RefCount_IMP(Class *self) {
- UNUSED_VAR(self);
- /* Class_Get_RefCount() lies to other Clownfish code about the refcount
- * because we don't want to have to synchronize access to the cached host
- * object to which we have delegated responsibility for keeping refcounts.
- * It always returns 1 because 1 is a positive number, and thus other
- * Clownfish code will be fooled into believing it never needs to take
- * action such as initiating a destructor.
- *
- * It's possible that the host has in fact increased the refcount of the
- * cached host object if there are multiple refs to it on the other side
- * of the Clownfish/host border, but returning 1 is good enough to fool
- * Clownfish code.
- */
- return 1;
-}
-
void
Class_Override_IMP(Class *self, cfish_method_t method, size_t offset) {
union { char *char_ptr; cfish_method_t *func_ptr; } pointer;
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d1a20342/runtime/core/Clownfish/Class.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Class.cfh b/runtime/core/Clownfish/Class.cfh
index e4dff41..23623b7 100644
--- a/runtime/core/Clownfish/Class.cfh
+++ b/runtime/core/Clownfish/Class.cfh
@@ -138,15 +138,6 @@ class Clownfish::Class inherits Clownfish::Obj {
public incremented Class*
Clone(Class *self);
- incremented Obj*
- Inc_RefCount(Class *self);
-
- uint32_t
- Dec_RefCount(Class *self);
-
- uint32_t
- Get_RefCount(Class *self);
-
void*
To_Host(Class *self);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d1a20342/runtime/core/Clownfish/Hash.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Hash.c b/runtime/core/Clownfish/Hash.c
index ac04562..9024624 100644
--- a/runtime/core/Clownfish/Hash.c
+++ b/runtime/core/Clownfish/Hash.c
@@ -353,23 +353,3 @@ Hash_get_tombstone() {
return TOMBSTONE;
}
-/***************************************************************************/
-
-uint32_t
-HashTombStone_Get_RefCount_IMP(HashTombStone* self) {
- UNUSED_VAR(self);
- return 1;
-}
-
-HashTombStone*
-HashTombStone_Inc_RefCount_IMP(HashTombStone* self) {
- return self;
-}
-
-uint32_t
-HashTombStone_Dec_RefCount_IMP(HashTombStone* self) {
- UNUSED_VAR(self);
- return 1;
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d1a20342/runtime/core/Clownfish/Hash.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Hash.cfh b/runtime/core/Clownfish/Hash.cfh
index 0b09785..cb65921 100644
--- a/runtime/core/Clownfish/Hash.cfh
+++ b/runtime/core/Clownfish/Hash.cfh
@@ -142,15 +142,6 @@ class Clownfish::Hash inherits Clownfish::Obj {
class Clownfish::Hash::HashTombStone
inherits Clownfish::Obj {
-
- uint32_t
- Get_RefCount(HashTombStone* self);
-
- incremented HashTombStone*
- Inc_RefCount(HashTombStone* self);
-
- uint32_t
- Dec_RefCount(HashTombStone* self);
}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d1a20342/runtime/core/Clownfish/Method.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Method.c b/runtime/core/Clownfish/Method.c
index d7a7327..bf76313 100644
--- a/runtime/core/Clownfish/Method.c
+++ b/runtime/core/Clownfish/Method.c
@@ -44,24 +44,6 @@ Method_Destroy_IMP(Method *self) {
THROW(ERR, "Insane attempt to destroy Method '%o'", self->name);
}
-Obj*
-Method_Inc_RefCount_IMP(Method *self) {
- return (Obj*)self;
-}
-
-uint32_t
-Method_Dec_RefCount_IMP(Method *self) {
- UNUSED_VAR(self);
- return 1;
-}
-
-uint32_t
-Method_Get_RefCount_IMP(Method *self) {
- UNUSED_VAR(self);
- // See comments in Class.c
- return 1;
-}
-
String*
Method_Get_Name_IMP(Method *self) {
return self->name;
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d1a20342/runtime/core/Clownfish/Method.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Method.cfh b/runtime/core/Clownfish/Method.cfh
index feab12f..57bc1ad 100644
--- a/runtime/core/Clownfish/Method.cfh
+++ b/runtime/core/Clownfish/Method.cfh
@@ -46,15 +46,6 @@ class Clownfish::Method inherits Clownfish::Obj {
incremented String*
Host_Name(Method *self);
- incremented Obj*
- Inc_RefCount(Method *self);
-
- uint32_t
- Dec_RefCount(Method *self);
-
- uint32_t
- Get_RefCount(Method *self);
-
public void
Destroy(Method *self);
}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d1a20342/runtime/core/Clownfish/Num.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Num.c b/runtime/core/Clownfish/Num.c
index 774e578..895be7e 100644
--- a/runtime/core/Clownfish/Num.c
+++ b/runtime/core/Clownfish/Num.c
@@ -382,14 +382,3 @@ Bool_Equals_IMP(BoolNum *self, Obj *other) {
return self == (BoolNum*)other;
}
-BoolNum*
-Bool_Inc_RefCount_IMP(BoolNum *self) {
- return self;
-}
-
-uint32_t
-Bool_Dec_RefCount_IMP(BoolNum *self) {
- UNUSED_VAR(self);
- return 1;
-}
-
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d1a20342/runtime/core/Clownfish/Num.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Num.cfh b/runtime/core/Clownfish/Num.cfh
index cd2780b..788a0bc 100644
--- a/runtime/core/Clownfish/Num.cfh
+++ b/runtime/core/Clownfish/Num.cfh
@@ -260,12 +260,6 @@ class Clownfish::BoolNum nickname Bool inherits Clownfish::IntNum {
public incremented String*
To_String(BoolNum *self);
-
- incremented BoolNum*
- Inc_RefCount(BoolNum *self);
-
- uint32_t
- Dec_RefCount(BoolNum *self);
}
__C__
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d1a20342/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index de8b310..ca58dfe 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -596,6 +596,18 @@ XSBind_allot_params(SV** stack, int32_t start, int32_t num_stack_elems, ...) {
/**************************** Clownfish::Obj *******************************/
+static CFISH_INLINE bool
+SI_immortal(cfish_Class *klass) {
+ if (klass == CFISH_CLASS
+ || klass == CFISH_METHOD
+ || klass == CFISH_BOOLNUM
+ || klass == CFISH_HASHTOMBSTONE
+ ){
+ return true;
+ }
+ return false;
+}
+
static void
S_lazy_init_host_obj(cfish_Obj *self) {
SV *inner_obj = newSV(0);
@@ -630,7 +642,13 @@ CFISH_Obj_Get_RefCount_IMP(cfish_Obj *self) {
}
cfish_Obj*
-CFISH_Obj_Inc_RefCount_IMP(cfish_Obj *self) {
+cfish_inc_refcount(void *vself) {
+ cfish_Obj *self = (cfish_Obj*)vself;
+ cfish_Class *const klass = self->klass;
+ if (SI_immortal(klass)) {
+ return self;
+ }
+
if (self->ref.count & XSBIND_REFCOUNT_FLAG) {
if (self->ref.count == XSBIND_REFCOUNT_FLAG) {
CFISH_THROW(CFISH_ERR, "Illegal refcount of 0");
@@ -643,8 +661,19 @@ CFISH_Obj_Inc_RefCount_IMP(cfish_Obj *self) {
return self;
}
+cfish_Obj*
+CFISH_Obj_Inc_RefCount_IMP(cfish_Obj *self) {
+ return cfish_inc_refcount(self);
+}
+
uint32_t
-CFISH_Obj_Dec_RefCount_IMP(cfish_Obj *self) {
+cfish_dec_refcount(void *vself) {
+ cfish_Obj *self = (cfish_Obj*)vself;
+ cfish_Class *klass = self->klass;
+ if (SI_immortal(klass)) {
+ return 1;
+ }
+
uint32_t modified_refcount = I32_MAX;
if (self->ref.count & XSBIND_REFCOUNT_FLAG) {
if (self->ref.count == XSBIND_REFCOUNT_FLAG) {
@@ -669,6 +698,11 @@ CFISH_Obj_Dec_RefCount_IMP(cfish_Obj *self) {
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); }
[11/16] lucy-clownfish git commit: Optimize special cases during
refcounting.
Posted by ma...@apache.org.
Optimize special cases during refcounting.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/2dab35a4
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/2dab35a4
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/2dab35a4
Branch: refs/heads/master
Commit: 2dab35a40af89271a193a6b6614968c8cfad96d3
Parents: 886c347
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Feb 7 17:06:53 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Feb 8 12:50:30 2015 -0800
----------------------------------------------------------------------
compiler/src/CFCBindCore.c | 2 ++
runtime/c/src/Clownfish/Obj.c | 67 +++++++++++++++++++++++++------------
runtime/core/Clownfish/Class.c | 13 ++++++-
runtime/perl/xs/XSBind.c | 47 +++++++++++++++++++-------
4 files changed, 94 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2dab35a4/compiler/src/CFCBindCore.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindCore.c b/compiler/src/CFCBindCore.c
index 80080b5..c4d7f91 100644
--- a/compiler/src/CFCBindCore.c
+++ b/compiler/src/CFCBindCore.c
@@ -296,6 +296,8 @@ S_write_parcel_h(CFCBindCore *self, CFCParcel *parcel) {
"#define CFISH_REFCOUNT_NN(_self) \\\n"
" cfish_get_refcount(_self)\n"
"\n"
+ "/* Flags for internal use. */\n"
+ "#define CFISH_fREFCOUNTSPECIAL 0x00000001\n"
;
const char *cfish_defs_2 =
"/* Structs for Class initialization.\n"
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2dab35a4/runtime/c/src/Clownfish/Obj.c
----------------------------------------------------------------------
diff --git a/runtime/c/src/Clownfish/Obj.c b/runtime/c/src/Clownfish/Obj.c
index 222b283..3db144f 100644
--- a/runtime/c/src/Clownfish/Obj.c
+++ b/runtime/c/src/Clownfish/Obj.c
@@ -15,20 +15,16 @@
*/
#define C_CFISH_OBJ
+#define C_CFISH_CLASS
#define CFISH_USE_SHORT_NAMES
#include "charmony.h"
#include "Clownfish/Obj.h"
+#include "Clownfish/Class.h"
#include "Clownfish/Err.h"
#include "Clownfish/String.h"
-uint32_t
-cfish_get_refcount(void *vself) {
- cfish_Obj *self = (cfish_Obj*)vself;
- return self->refcount;
-}
-
static CFISH_INLINE bool
SI_immortal(cfish_Class *klass) {
if (klass == CFISH_CLASS
@@ -42,39 +38,66 @@ SI_immortal(cfish_Class *klass) {
}
static CFISH_INLINE bool
-SI_is_string(cfish_Class *klass) {
+SI_is_string_type(cfish_Class *klass) {
if (klass == CFISH_STRING || klass == CFISH_STACKSTRING) {
return true;
}
return false;
}
+static CFISH_INLINE bool
+SI_threadsafe_but_not_immortal(cfish_Class *klass) {
+ if (klass == CFISH_LOCKFREEREGISTRY) {
+ return true;
+ }
+ return false;
+}
+
+uint32_t
+cfish_get_refcount(void *vself) {
+ cfish_Obj *self = (cfish_Obj*)vself;
+ return self->refcount;
+}
+
Obj*
cfish_inc_refcount(void *vself) {
Obj *self = (Obj*)vself;
+
+ // Handle special cases.
cfish_Class *const klass = self->klass;
- if (SI_immortal(klass)) {
- return self;
- }
- else if (SI_is_string(klass)
- && CFISH_Str_Is_Copy_On_IncRef((cfish_String*)self)
- ) {
- const char *utf8 = CFISH_Str_Get_Ptr8((cfish_String*)self);
- size_t size = CFISH_Str_Get_Size((cfish_String*)self);
- return (cfish_Obj*)cfish_Str_new_from_trusted_utf8(utf8, size);
- }
- else {
- self->refcount++;
- return self;
+ if (klass->flags & CFISH_fREFCOUNTSPECIAL) {
+ if (SI_is_string_type(klass)) {
+ // Only copy-on-incref Strings get special-cased. Ordinary
+ // strings fall through to the general case.
+ if (CFISH_Str_Is_Copy_On_IncRef((cfish_String*)self)) {
+ const char *utf8 = CFISH_Str_Get_Ptr8((cfish_String*)self);
+ size_t size = CFISH_Str_Get_Size((cfish_String*)self);
+ return (cfish_Obj*)cfish_Str_new_from_trusted_utf8(utf8, size);
+ }
+ }
+ else if (SI_immortal(klass)) {
+ return self;
+ }
+ else if (SI_threadsafe_but_not_immortal(klass)) {
+ // TODO: use atomic operation
+ }
}
+
+ self->refcount++;
+ return self;
}
uint32_t
cfish_dec_refcount(void *vself) {
cfish_Obj *self = (Obj*)vself;
cfish_Class *klass = self->klass;
- if (SI_immortal(klass)) {
- return self->refcount;
+ if (klass->flags & CFISH_fREFCOUNTSPECIAL) {
+ if (SI_immortal(klass)) {
+ return self->refcount;
+ }
+ else if (SI_threadsafe_but_not_immortal(klass)) {
+ // TODO: use atomic operation
+ }
}
uint32_t modified_refcount = INT32_MAX;
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2dab35a4/runtime/core/Clownfish/Class.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Class.c b/runtime/core/Clownfish/Class.c
index b30b124..478bd6c 100644
--- a/runtime/core/Clownfish/Class.c
+++ b/runtime/core/Clownfish/Class.c
@@ -93,10 +93,21 @@ Class_bootstrap(const ClassSpec *specs, size_t num_specs)
klass->parent = parent;
klass->parcel_id = parcel_id;
- klass->flags = 0;
klass->obj_alloc_size = ivars_offset + spec->ivars_size;
klass->class_alloc_size = class_alloc_size;
+ klass->flags = 0;
+ if (spec->klass == &CLASS
+ || spec->klass == &METHOD
+ || spec->klass == &BOOLNUM
+ || spec->klass == &HASHTOMBSTONE
+ || spec->klass == &STRING
+ || spec->klass == &STACKSTRING
+ || spec->klass == &LOCKFREEREGISTRY
+ ) {
+ klass->flags |= CFISH_fREFCOUNTSPECIAL;
+ }
+
if (parent) {
// Copy parent vtable.
size_t parent_vt_size = parent->class_alloc_size
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2dab35a4/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index d624ff7..659ab35 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -609,13 +609,21 @@ SI_immortal(cfish_Class *klass) {
}
static CFISH_INLINE bool
-SI_is_string(cfish_Class *klass) {
+SI_is_string_type(cfish_Class *klass) {
if (klass == CFISH_STRING || klass == CFISH_STACKSTRING) {
return true;
}
return false;
}
+static CFISH_INLINE bool
+SI_threadsafe_but_not_immortal(cfish_Class *klass) {
+ if (klass == CFISH_LOCKFREEREGISTRY) {
+ return true;
+ }
+ return false;
+}
+
static void
S_lazy_init_host_obj(cfish_Obj *self) {
SV *inner_obj = newSV(0);
@@ -653,16 +661,25 @@ cfish_get_refcount(void *vself) {
cfish_Obj*
cfish_inc_refcount(void *vself) {
cfish_Obj *self = (cfish_Obj*)vself;
+
+ // Handle special cases.
cfish_Class *const klass = self->klass;
- if (SI_immortal(klass)) {
- return self;
- }
- else if (SI_is_string(klass)
- && CFISH_Str_Is_Copy_On_IncRef((cfish_String*)self)
- ) {
- const char *utf8 = CFISH_Str_Get_Ptr8((cfish_String*)self);
- size_t size = CFISH_Str_Get_Size((cfish_String*)self);
- return (cfish_Obj*)cfish_Str_new_from_trusted_utf8(utf8, size);
+ if (klass->flags & CFISH_fREFCOUNTSPECIAL) {
+ if (SI_is_string_type(klass)) {
+ // Only copy-on-incref Strings get special-cased. Ordinary
+ // Strings fall through to the general case.
+ if (CFISH_Str_Is_Copy_On_IncRef((cfish_String*)self)) {
+ const char *utf8 = CFISH_Str_Get_Ptr8((cfish_String*)self);
+ size_t size = CFISH_Str_Get_Size((cfish_String*)self);
+ return (cfish_Obj*)cfish_Str_new_from_trusted_utf8(utf8, size);
+ }
+ }
+ else if (SI_immortal(klass)) {
+ return self;
+ }
+ else if (SI_threadsafe_but_not_immortal(klass)) {
+ // TODO: use atomic operation
+ }
}
if (self->ref.count & XSBIND_REFCOUNT_FLAG) {
@@ -680,9 +697,15 @@ cfish_inc_refcount(void *vself) {
uint32_t
cfish_dec_refcount(void *vself) {
cfish_Obj *self = (cfish_Obj*)vself;
+
cfish_Class *klass = self->klass;
- if (SI_immortal(klass)) {
- return 1;
+ if (klass->flags & CFISH_fREFCOUNTSPECIAL) {
+ if (SI_immortal(klass)) {
+ return 1;
+ }
+ else if (SI_threadsafe_but_not_immortal(klass)) {
+ // TODO: use atomic operation
+ }
}
uint32_t modified_refcount = I32_MAX;
[13/16] lucy-clownfish git commit: Fix race on fetching refcount.
Posted by ma...@apache.org.
Fix race on fetching refcount.
It's very unlikely, but possible that a host object could get cached by
another thread in between the check and the usage.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/afde943d
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/afde943d
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/afde943d
Branch: refs/heads/master
Commit: afde943d975456cd473e18732c0b620b4d86c082
Parents: 52b1f98
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sun Feb 8 21:04:36 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Feb 8 21:04:36 2015 -0800
----------------------------------------------------------------------
runtime/perl/xs/XSBind.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/afde943d/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index d29d1ec..ae5591a 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -673,9 +673,10 @@ S_lazy_init_host_obj(cfish_Obj *self) {
uint32_t
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);
+ cfish_ref_t ref = self->ref;
+ return ref.count & XSBIND_REFCOUNT_FLAG
+ ? ref.count >> XSBIND_REFCOUNT_SHIFT
+ : SvREFCNT((SV*)ref.host_obj);
}
cfish_Obj*
[06/16] lucy-clownfish git commit: Replace refcount method call for
test-only func.
Posted by ma...@apache.org.
Replace refcount method call for test-only func.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/d08401b7
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/d08401b7
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/d08401b7
Branch: refs/heads/master
Commit: d08401b74d5420292a356f7a34ca69e51111537f
Parents: a1155b3
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Feb 7 09:55:54 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Feb 7 09:56:33 2015 -0800
----------------------------------------------------------------------
runtime/perl/buildlib/Clownfish/Build/Binding.pm | 7 +++++++
runtime/perl/t/binding/019-obj.t | 11 ++++++-----
2 files changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d08401b7/runtime/perl/buildlib/Clownfish/Build/Binding.pm
----------------------------------------------------------------------
diff --git a/runtime/perl/buildlib/Clownfish/Build/Binding.pm b/runtime/perl/buildlib/Clownfish/Build/Binding.pm
index 049945c..232e223 100644
--- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm
+++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm
@@ -110,6 +110,13 @@ PPCODE:
cfish_Obj *obj = XSBind_sv_to_cfish_obj(sv, CFISH_OBJ, NULL);
cfish_String *str = CFISH_Obj_To_String(obj);
CFISH_DECREF(str);
+
+int
+refcount(obj)
+ cfish_Obj *obj;
+CODE:
+ RETVAL = (int)CFISH_REFCOUNT_NN(obj);
+OUTPUT: RETVAL
END_XS_CODE
my $binding = Clownfish::CFC::Binding::Perl::Class->new(
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d08401b7/runtime/perl/t/binding/019-obj.t
----------------------------------------------------------------------
diff --git a/runtime/perl/t/binding/019-obj.t b/runtime/perl/t/binding/019-obj.t
index 83134d9..0b4e80d 100644
--- a/runtime/perl/t/binding/019-obj.t
+++ b/runtime/perl/t/binding/019-obj.t
@@ -16,7 +16,7 @@
use strict;
use warnings;
-use Test::More tests => 22;
+use Test::More tests => 21;
package TestObj;
use base qw( Clownfish::Obj );
@@ -102,15 +102,16 @@ my $stringified_perl_obj = "$object";
require Clownfish::Hash;
my $hash = Clownfish::Hash->new;
$hash->store( foo => $object );
-is( $object->get_refcount, 2, "refcount increased via C code" );
-is( $object->get_refcount, 2, "refcount increased via C code" );
+is( Clownfish::Test::refcount($object), 2, "refcount increased via C code" );
undef $object;
$object = $hash->fetch("foo");
is( "$object", $stringified_perl_obj, "same perl object as before" );
-is( $object->get_refcount, 2, "correct refcount after retrieval" );
+is( Clownfish::Test::refcount($object),
+ 2, "correct refcount after retrieval" );
undef $hash;
-is( $object->get_refcount, 1, "correct refcount after destruction of ref" );
+is( Clownfish::Test::refcount($object),
+ 1, "correct refcount after destruction of ref" );
$object = SonOfTestObj->new;
like( $object->to_string, qr/STRING:.*?SonOfTestObj/,
[10/16] lucy-clownfish git commit: Move many Clownfish defs out of
Obj.cfh.
Posted by ma...@apache.org.
Move many Clownfish defs out of Obj.cfh.
Refcounting, SUPER dispatch, and so on belong to Clownfish as a whole --
not to Obj specifically.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/886c3472
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/886c3472
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/886c3472
Branch: refs/heads/master
Commit: 886c34726ace60bfbdc749eafe619f78e940e8d9
Parents: 436a685
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Feb 7 15:49:53 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Feb 7 15:49:53 2015 -0800
----------------------------------------------------------------------
compiler/src/CFCBindCore.c | 76 +++++++++++++++++++++++++++++++++++--
runtime/core/Clownfish/Obj.cfh | 76 -------------------------------------
2 files changed, 73 insertions(+), 79 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/886c3472/compiler/src/CFCBindCore.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindCore.c b/compiler/src/CFCBindCore.c
index 2bf6119..80080b5 100644
--- a/compiler/src/CFCBindCore.c
+++ b/compiler/src/CFCBindCore.c
@@ -185,7 +185,7 @@ S_write_parcel_h(CFCBindCore *self, CFCParcel *parcel) {
"#include \"cfish_hostdefs.h\"\n";
// Special definitions for Clownfish parcel.
- const char *cfish_defs =
+ const char *cfish_defs_1 =
"#define CFISH_UNUSED_VAR(var) ((void)var)\n"
"#define CFISH_UNREACHABLE_RETURN(type) return (type)0\n"
"\n"
@@ -234,6 +234,70 @@ S_write_parcel_h(CFCBindCore *self, CFCParcel *parcel) {
" return cfish_method(*parent_ptr, offset);\n"
"}\n"
"\n"
+ "typedef void\n"
+ "(*cfish_destroy_t)(void *vself);\n"
+ "extern CFISH_VISIBLE size_t CFISH_Obj_Destroy_OFFSET;\n"
+ "\n"
+ "/** Invoke the [](cfish:.Destroy) method found in `klass` on\n"
+ " * `self`.\n"
+ " *\n"
+ " * TODO: Eliminate this function if we can arrive at a proper SUPER syntax.\n"
+ " */\n"
+ "static CFISH_INLINE void\n"
+ "cfish_super_destroy(void *vself, cfish_Class *klass) {\n"
+ " cfish_Obj *self = (cfish_Obj*)vself;\n"
+ " if (self != NULL) {\n"
+ " cfish_destroy_t super_destroy\n"
+ " = (cfish_destroy_t)cfish_super_method(klass, CFISH_Obj_Destroy_OFFSET);\n"
+ " super_destroy(self);\n"
+ " }\n"
+ "}\n"
+ "\n"
+ "#define CFISH_SUPER_DESTROY(_self, _class) \\\n"
+ " cfish_super_destroy(_self, _class)\n"
+ "\n"
+ "extern CFISH_VISIBLE cfish_Obj*\n"
+ "cfish_inc_refcount(void *vself);\n"
+ "\n"
+ "/** NULL-safe invocation invocation of `cfish_inc_refcount`.\n"
+ " *\n"
+ " * @return NULL if `self` is NULL, otherwise the return value\n"
+ " * of `cfish_inc_refcount`.\n"
+ " */\n"
+ "static CFISH_INLINE cfish_Obj*\n"
+ "cfish_incref(void *vself) {\n"
+ " if (vself != NULL) { return cfish_inc_refcount(vself); }\n"
+ " else { return NULL; }\n"
+ "}\n"
+ "\n"
+ "#define CFISH_INCREF(_self) cfish_incref(_self)\n"
+ "#define CFISH_INCREF_NN(_self) cfish_inc_refcount(_self)\n"
+ "\n"
+ "extern CFISH_VISIBLE uint32_t\n"
+ "cfish_dec_refcount(void *vself);\n"
+ "\n"
+ "/** NULL-safe invocation of `cfish_dec_refcount`.\n"
+ " *\n"
+ " * @return NULL if `self` is NULL, otherwise the return value\n"
+ " * of `cfish_dec_refcount`.\n"
+ " */\n"
+ "static CFISH_INLINE uint32_t\n"
+ "cfish_decref(void *vself) {\n"
+ " if (vself != NULL) { return cfish_dec_refcount(vself); }\n"
+ " else { return 0; }\n"
+ "}\n"
+ "\n"
+ "#define CFISH_DECREF(_self) cfish_decref(_self)\n"
+ "#define CFISH_DECREF_NN(_self) cfish_dec_refcount(_self)\n"
+ "\n"
+ "extern CFISH_VISIBLE uint32_t\n"
+ "cfish_get_refcount(void *vself);\n"
+ "\n"
+ "#define CFISH_REFCOUNT_NN(_self) \\\n"
+ " cfish_get_refcount(_self)\n"
+ "\n"
+ ;
+ const char *cfish_defs_2 =
"/* Structs for Class initialization.\n"
" */\n"
"\n"
@@ -274,17 +338,23 @@ S_write_parcel_h(CFCBindCore *self, CFCParcel *parcel) {
" #define UNREACHABLE_RETURN CFISH_UNREACHABLE_RETURN\n"
" #define METHOD_PTR CFISH_METHOD_PTR\n"
" #define SUPER_METHOD_PTR CFISH_SUPER_METHOD_PTR\n"
+ " #define SUPER_DESTROY(_self, _class) CFISH_SUPER_DESTROY(_self, _class)\n"
+ " #define INCREF(_self) CFISH_INCREF(_self)\n"
+ " #define INCREF_NN(_self) CFISH_INCREF_NN(_self)\n"
+ " #define DECREF(_self) CFISH_DECREF(_self)\n"
+ " #define DECREF_NN(_self) CFISH_DECREF_NN(_self)\n"
+ " #define REFCOUNT_NN(_self) CFISH_REFCOUNT_NN(_self)\n"
"#endif\n"
"\n";
const char *extra_defs;
char *extra_includes;
if (strcmp(prefix, "cfish_") == 0) {
- extra_defs = cfish_defs;
+ extra_defs = CFCUtil_sprintf("%s%s", cfish_defs_1, cfish_defs_2);
extra_includes = CFCUtil_strdup(cfish_includes);
}
else {
- extra_defs = "";
+ extra_defs = CFCUtil_strdup("");
extra_includes = CFCUtil_strdup("");
// Include parcel.h of prerequisite parcels.
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/886c3472/runtime/core/Clownfish/Obj.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Obj.cfh b/runtime/core/Clownfish/Obj.cfh
index 2feadfa..7fcc894 100644
--- a/runtime/core/Clownfish/Obj.cfh
+++ b/runtime/core/Clownfish/Obj.cfh
@@ -111,79 +111,3 @@ public class Clownfish::Obj {
Mimic(Obj *self, Obj *other);
}
-__C__
-
-typedef void
-(*cfish_destroy_t)(void *vself);
-extern CFISH_VISIBLE size_t CFISH_Obj_Destroy_OFFSET;
-
-/** 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_super_destroy(void *vself, cfish_Class *klass) {
- cfish_Obj *self = (cfish_Obj*)vself;
- if (self != NULL) {
- cfish_destroy_t super_destroy
- = (cfish_destroy_t)cfish_super_method(klass, CFISH_Obj_Destroy_OFFSET);
- super_destroy(self);
- }
-}
-
-#define CFISH_SUPER_DESTROY(_self, _class) \
- cfish_super_destroy(_self, _class)
-
-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`.
- */
-static CFISH_INLINE cfish_Obj*
-cfish_incref(void *vself) {
- if (vself != NULL) { return cfish_inc_refcount(vself); }
- else { return NULL; }
-}
-
-#define CFISH_INCREF(_self) cfish_incref(_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`.
- *
- * @return NULL if `self` is NULL, otherwise the return value
- * of `cfish_dec_refcount`.
- */
-static CFISH_INLINE uint32_t
-cfish_decref(void *vself) {
- if (vself != NULL) { return cfish_dec_refcount(vself); }
- else { return 0; }
-}
-
-#define CFISH_DECREF(_self) cfish_decref(_self)
-#define CFISH_DECREF_NN(_self) cfish_dec_refcount(_self)
-
-extern CFISH_VISIBLE uint32_t
-cfish_get_refcount(void *vself);
-
-#define CFISH_REFCOUNT_NN(_self) \
- cfish_get_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__
-
-
[05/16] lucy-clownfish git commit: Use different method in nullable
binding test.
Posted by ma...@apache.org.
Use different method in nullable binding test.
Instead of calling `Inc_RefCount` from C-space, call `To_String`.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/a1155b37
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/a1155b37
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/a1155b37
Branch: refs/heads/master
Commit: a1155b3707b93631397b383adf9d58f7caf00c9f
Parents: cd6c304
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Feb 7 09:44:36 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Feb 7 09:44:36 2015 -0800
----------------------------------------------------------------------
.../perl/buildlib/Clownfish/Build/Binding.pm | 8 +++++++
runtime/perl/t/binding/019-obj.t | 22 ++++++++------------
2 files changed, 17 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a1155b37/runtime/perl/buildlib/Clownfish/Build/Binding.pm
----------------------------------------------------------------------
diff --git a/runtime/perl/buildlib/Clownfish/Build/Binding.pm b/runtime/perl/buildlib/Clownfish/Build/Binding.pm
index 98c7f0d..049945c 100644
--- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm
+++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm
@@ -102,6 +102,14 @@ CODE:
RETVAL = result;
OUTPUT: RETVAL
+
+void
+invoke_to_string(sv)
+ SV *sv;
+PPCODE:
+ cfish_Obj *obj = XSBind_sv_to_cfish_obj(sv, CFISH_OBJ, NULL);
+ cfish_String *str = CFISH_Obj_To_String(obj);
+ CFISH_DECREF(str);
END_XS_CODE
my $binding = Clownfish::CFC::Binding::Perl::Class->new(
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a1155b37/runtime/perl/t/binding/019-obj.t
----------------------------------------------------------------------
diff --git a/runtime/perl/t/binding/019-obj.t b/runtime/perl/t/binding/019-obj.t
index 06e3642..83134d9 100644
--- a/runtime/perl/t/binding/019-obj.t
+++ b/runtime/perl/t/binding/019-obj.t
@@ -32,14 +32,10 @@ use base qw( TestObj );
}
}
-package BadRefCount;
+package BadToString;
use base qw( Clownfish::Obj );
{
- sub inc_refcount {
- my $self = shift;
- $self->SUPER::inc_refcount;
- return;
- }
+ sub to_string {}
}
package ThawTestObj;
@@ -63,6 +59,7 @@ use base qw( Clownfish::Test::AliasTestObj );
package main;
use Storable qw( freeze thaw );
+use Clownfish::Test;
ok( defined $TestObj::version,
"Using base class should grant access to "
@@ -123,13 +120,12 @@ SKIP: {
skip( "Exception thrown within callback leaks", 2 )
if $ENV{LUCY_VALGRIND};
- # The Perl binding for VArray#store calls inc_refcount() from C space.
- # This test verifies that the Perl bindings generated by CFC handle
- # non-`nullable` return values correctly, by ensuring that the Perl
- # callback wrapper for inc_refcount() checks the return value and throws
- # an exception if a Perl-space implementation returns undef.
- my $array = Clownfish::VArray->new;
- eval { $array->store( 1, BadRefCount->new ); };
+ # Invoke To_String() from C space. This test verifies that the Perl
+ # bindings generated by CFC handle non-`nullable` return values correctly,
+ # by ensuring that the Perl callback wrapper for to_string() checks the
+ # return value and throws an exception if a Perl-space implementation
+ # returns undef.
+ eval { Clownfish::Test::invoke_to_string( BadToString->new ) };
like( $@, qr/NULL/,
"Don't allow methods without nullable return values to return NULL" );
[15/16] lucy-clownfish git commit: Use copy-on-incref Strings as
immortals.
Posted by ma...@apache.org.
Use copy-on-incref Strings as immortals.
Members variables of Class and Method are shared and need to be
threadsafe. Copy-on-incref Strings are effectively threadsafe, so use
those.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/c0b90906
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/c0b90906
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/c0b90906
Branch: refs/heads/master
Commit: c0b90906746d3825e3fc9fd41d023aa727e07b13
Parents: 55b19f4
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Feb 10 19:01:39 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Feb 10 19:01:39 2015 -0800
----------------------------------------------------------------------
runtime/core/Clownfish/Class.c | 18 +++++++++++++-----
runtime/core/Clownfish/Class.cfh | 1 +
runtime/core/Clownfish/Method.c | 22 +++++++++++++++++++++-
runtime/core/Clownfish/Method.cfh | 5 +++++
4 files changed, 40 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c0b90906/runtime/core/Clownfish/Class.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Class.c b/runtime/core/Clownfish/Class.c
index 478bd6c..6e87e49 100644
--- a/runtime/core/Clownfish/Class.c
+++ b/runtime/core/Clownfish/Class.c
@@ -152,23 +152,30 @@ Class_bootstrap(const ClassSpec *specs, size_t num_specs)
* Pass 3:
* - Inititalize name and method array.
* - Register class.
+ *
+ * We use a "wrapped" String for `name` because it's effectively
+ * threadsafe: the sole reference is owned by an immortal object and any
+ * INCREF spawns a copy.
*/
for (size_t i = 0; i < num_specs; ++i) {
const ClassSpec *spec = &specs[i];
Class *klass = *spec->klass;
- klass->name = Str_newf("%s", spec->name);
+ klass->name_internal = Str_newf("%s", spec->name);
+ klass->name
+ = Str_new_wrap_trusted_utf8(Str_Get_Ptr8(klass->name_internal),
+ Str_Get_Size(klass->name_internal));
klass->methods = (Method**)MALLOCATE((spec->num_novel_meths + 1)
* sizeof(Method*));
// Only store novel methods for now.
for (size_t i = 0; i < spec->num_novel_meths; ++i) {
const NovelMethSpec *mspec = &spec->novel_meth_specs[i];
- String *name = Str_newf("%s", mspec->name);
- Method *method = Method_new(name, mspec->callback_func,
+ StackString *name
+ = SSTR_WRAP_UTF8(mspec->name, strlen(mspec->name));
+ Method *method = Method_new((String*)name, mspec->callback_func,
*mspec->offset);
klass->methods[i] = method;
- DECREF(name);
}
klass->methods[spec->num_novel_meths] = NULL;
@@ -363,11 +370,12 @@ void
Class_Add_Host_Method_Alias_IMP(Class *self, const char *alias,
const char *meth_name) {
Method *method = S_find_method(self, meth_name);
+ StackString *alias_cf = SSTR_WRAP_UTF8(alias, strlen(alias));
if (!method) {
fprintf(stderr, "Method %s not found\n", meth_name);
abort();
}
- method->host_alias = Str_newf("%s", alias);
+ Method_Set_Host_Alias(method, (String*)alias_cf);
}
void
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c0b90906/runtime/core/Clownfish/Class.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Class.cfh b/runtime/core/Clownfish/Class.cfh
index 566f29f..8b966b7 100644
--- a/runtime/core/Clownfish/Class.cfh
+++ b/runtime/core/Clownfish/Class.cfh
@@ -27,6 +27,7 @@ class Clownfish::Class inherits Clownfish::Obj {
Class *parent;
String *name;
+ String *name_internal;
uint32_t flags;
int32_t parcel_id;
size_t obj_alloc_size;
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c0b90906/runtime/core/Clownfish/Method.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Method.c b/runtime/core/Clownfish/Method.c
index bf76313..931427b 100644
--- a/runtime/core/Clownfish/Method.c
+++ b/runtime/core/Clownfish/Method.c
@@ -31,11 +31,20 @@ Method_new(String *name, cfish_method_t callback_func, size_t offset) {
Method*
Method_init(Method *self, String *name, cfish_method_t callback_func,
size_t offset) {
- self->name = Str_Clone(name);
+ /* The `name` member which Method exposes via the `Get_Name` accessor uses
+ * a "wrapped" string because that is effectively threadsafe: an INCREF
+ * results in a copy and the only reference is owned by an immortal
+ * object. */
+ self->name_internal = Str_Clone(name);
+ self->name
+ = Str_new_wrap_trusted_utf8(Str_Get_Ptr8(self->name_internal),
+ Str_Get_Size(self->name_internal));
+
self->host_alias = NULL;
self->callback_func = callback_func;
self->offset = offset;
self->is_excluded = false;
+
return self;
}
@@ -49,6 +58,17 @@ Method_Get_Name_IMP(Method *self) {
return self->name;
}
+void
+Method_Set_Host_Alias_IMP(Method *self, String *name) {
+ if (self->host_alias) {
+ THROW(ERR, "Can't Set_Host_Alias more than once");
+ }
+ self->host_alias_internal = Str_Clone(name);
+ self->host_alias
+ = Str_new_wrap_trusted_utf8(Str_Get_Ptr8(self->host_alias_internal),
+ Str_Get_Size(self->host_alias_internal));
+}
+
String*
Method_Get_Host_Alias_IMP(Method *self) {
return self->host_alias;
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c0b90906/runtime/core/Clownfish/Method.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Method.cfh b/runtime/core/Clownfish/Method.cfh
index 57bc1ad..e71a549 100644
--- a/runtime/core/Clownfish/Method.cfh
+++ b/runtime/core/Clownfish/Method.cfh
@@ -22,7 +22,9 @@ parcel Clownfish;
class Clownfish::Method inherits Clownfish::Obj {
String *name;
+ String *name_internal;
String *host_alias;
+ String *host_alias_internal;
cfish_method_t callback_func;
size_t offset;
bool is_excluded;
@@ -37,6 +39,9 @@ class Clownfish::Method inherits Clownfish::Obj {
String*
Get_Name(Method *self);
+ void
+ Set_Host_Alias(Method *self, String *name);
+
nullable String*
Get_Host_Alias(Method *self);
[04/16] lucy-clownfish git commit: Consolidate String refcounting
routines.
Posted by ma...@apache.org.
Consolidate String refcounting routines.
Instead of having String override Inc_RefCount, special-case its
behavior within the main incref routine.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/cd6c304b
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/cd6c304b
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/cd6c304b
Branch: refs/heads/master
Commit: cd6c304bc96ed8d0bf3395327e6c281eafd564b7
Parents: 93c2bfd
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Feb 7 09:04:25 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Feb 7 09:04:25 2015 -0800
----------------------------------------------------------------------
runtime/c/src/Clownfish/Obj.c | 16 ++++++++++++++++
runtime/core/Clownfish/String.c | 15 +++------------
runtime/core/Clownfish/String.cfh | 4 ++--
runtime/perl/xs/XSBind.c | 15 +++++++++++++++
4 files changed, 36 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/cd6c304b/runtime/c/src/Clownfish/Obj.c
----------------------------------------------------------------------
diff --git a/runtime/c/src/Clownfish/Obj.c b/runtime/c/src/Clownfish/Obj.c
index e17feef..296192d 100644
--- a/runtime/c/src/Clownfish/Obj.c
+++ b/runtime/c/src/Clownfish/Obj.c
@@ -21,6 +21,7 @@
#include "Clownfish/Obj.h"
#include "Clownfish/Err.h"
+#include "Clownfish/String.h"
uint32_t
Obj_Get_RefCount_IMP(Obj *self) {
@@ -39,6 +40,14 @@ SI_immortal(cfish_Class *klass) {
return false;
}
+static CFISH_INLINE bool
+SI_is_string(cfish_Class *klass) {
+ if (klass == CFISH_STRING || klass == CFISH_STACKSTRING) {
+ return true;
+ }
+ return false;
+}
+
Obj*
cfish_inc_refcount(void *vself) {
Obj *self = (Obj*)vself;
@@ -46,6 +55,13 @@ cfish_inc_refcount(void *vself) {
if (SI_immortal(klass)) {
return self;
}
+ else if (SI_is_string(klass)
+ && CFISH_Str_Is_Copy_On_IncRef((cfish_String*)self)
+ ) {
+ const char *utf8 = CFISH_Str_Get_Ptr8((cfish_String*)self);
+ size_t size = CFISH_Str_Get_Size((cfish_String*)self);
+ return (cfish_Obj*)cfish_Str_new_from_trusted_utf8(utf8, size);
+ }
else {
self->refcount++;
return self;
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/cd6c304b/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/String.c b/runtime/core/Clownfish/String.c
index 55eec0c..3b7fe7b 100644
--- a/runtime/core/Clownfish/String.c
+++ b/runtime/core/Clownfish/String.c
@@ -169,18 +169,9 @@ S_new_substring(String *string, size_t byte_offset, size_t size) {
return self;
}
-Obj*
-Str_Inc_RefCount_IMP(String *self) {
- if (self->origin == NULL) {
- // Copy wrapped strings when the refcount is increased.
- String *copy = (String*)Class_Make_Obj(STRING);
- return (Obj*)Str_init_from_trusted_utf8(copy, self->ptr, self->size);
- }
- else {
- Str_Inc_RefCount_t super_incref
- = SUPER_METHOD_PTR(STRING, CFISH_Str_Inc_RefCount);
- return super_incref(self);
- }
+bool
+Str_Is_Copy_On_IncRef_IMP(String *self) {
+ return self->origin == NULL;
}
void
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/cd6c304b/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/String.cfh b/runtime/core/Clownfish/String.cfh
index 32f37a7..8fe7cc5 100644
--- a/runtime/core/Clownfish/String.cfh
+++ b/runtime/core/Clownfish/String.cfh
@@ -203,8 +203,8 @@ class Clownfish::String nickname Str
public incremented String*
Clone(String *self);
- incremented Obj*
- Inc_RefCount(String *self);
+ bool
+ Is_Copy_On_IncRef(String *self);
public void
Destroy(String *self);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/cd6c304b/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index ca58dfe..07e3fc6 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -608,6 +608,14 @@ SI_immortal(cfish_Class *klass) {
return false;
}
+static CFISH_INLINE bool
+SI_is_string(cfish_Class *klass) {
+ if (klass == CFISH_STRING || klass == CFISH_STACKSTRING) {
+ return true;
+ }
+ return false;
+}
+
static void
S_lazy_init_host_obj(cfish_Obj *self) {
SV *inner_obj = newSV(0);
@@ -648,6 +656,13 @@ cfish_inc_refcount(void *vself) {
if (SI_immortal(klass)) {
return self;
}
+ else if (SI_is_string(klass)
+ && CFISH_Str_Is_Copy_On_IncRef((cfish_String*)self)
+ ) {
+ const char *utf8 = CFISH_Str_Get_Ptr8((cfish_String*)self);
+ size_t size = CFISH_Str_Get_Size((cfish_String*)self);
+ return (cfish_Obj*)cfish_Str_new_from_trusted_utf8(utf8, size);
+ }
if (self->ref.count & XSBIND_REFCOUNT_FLAG) {
if (self->ref.count == XSBIND_REFCOUNT_FLAG) {