Implement Method#Clone
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/8598709b Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/8598709b Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/8598709b Branch: refs/heads/clone_class_registry Commit: 8598709b6b163f795df1f2b0a4a5de4a7f6b3335 Parents: a081f6b Author: Nick Wellnhofer <[email protected]> Authored: Sun Aug 3 14:19:35 2014 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Sun Aug 3 17:38:04 2014 +0200 ---------------------------------------------------------------------- runtime/core/Clownfish/Method.c | 15 ++++++++++++++- runtime/core/Clownfish/Method.cfh | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8598709b/runtime/core/Clownfish/Method.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Method.c b/runtime/core/Clownfish/Method.c index d7a7327..52ecd0d 100644 --- a/runtime/core/Clownfish/Method.c +++ b/runtime/core/Clownfish/Method.c @@ -31,7 +31,7 @@ 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); + self->name = (String*)INCREF(name); self->host_alias = NULL; self->callback_func = callback_func; self->offset = offset; @@ -39,6 +39,19 @@ Method_init(Method *self, String *name, cfish_method_t callback_func, return self; } +Method* +Method_Clone_IMP(Method *self) { + String *name = Str_Clone(self->name); + Method *twin = Method_new(name, self->callback_func, self->offset); + DECREF(name); + + if (self->host_alias) { + twin->host_alias = Str_Clone(self->host_alias); + } + + return twin; +} + void Method_Destroy_IMP(Method *self) { THROW(ERR, "Insane attempt to destroy Method '%o'", self->name); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8598709b/runtime/core/Clownfish/Method.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Method.cfh b/runtime/core/Clownfish/Method.cfh index feab12f..1294a7c 100644 --- a/runtime/core/Clownfish/Method.cfh +++ b/runtime/core/Clownfish/Method.cfh @@ -46,6 +46,9 @@ class Clownfish::Method inherits Clownfish::Obj { incremented String* Host_Name(Method *self); + public incremented Method* + Clone(Method *self); + incremented Obj* Inc_RefCount(Method *self);
