Don't cache override symbol
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/bfa43f3d Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/bfa43f3d Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/bfa43f3d Branch: refs/heads/master Commit: bfa43f3dad6f6eec3d25acf172899cbc64db0d64 Parents: ac313c1 Author: Nick Wellnhofer <[email protected]> Authored: Sat Jul 26 23:38:15 2014 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Thu May 7 21:13:59 2015 +0200 ---------------------------------------------------------------------- compiler/perl/lib/Clownfish/CFC.xs | 10 ++++------ compiler/src/CFCBindClass.c | 3 ++- compiler/src/CFCBindMethod.c | 8 ++++++-- compiler/src/CFCC.c | 3 ++- compiler/src/CFCMethod.c | 19 ++++++------------- compiler/src/CFCMethod.h | 4 ++-- compiler/src/CFCPerl.c | 2 +- compiler/src/CFCPerlMethod.c | 5 +++-- compiler/src/CFCPerlMethod.h | 2 +- 9 files changed, 27 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/bfa43f3d/compiler/perl/lib/Clownfish/CFC.xs ---------------------------------------------------------------------- diff --git a/compiler/perl/lib/Clownfish/CFC.xs b/compiler/perl/lib/Clownfish/CFC.xs index 02f7eaf..10b2a22 100644 --- a/compiler/perl/lib/Clownfish/CFC.xs +++ b/compiler/perl/lib/Clownfish/CFC.xs @@ -895,6 +895,7 @@ ALIAS: full_offset_sym = 3 short_typedef = 4 full_typedef = 5 + full_override_sym = 6 CODE: char *buf; switch (ix) { @@ -913,6 +914,9 @@ CODE: case 5: buf = CFCMethod_full_typedef(self, invoker); break; + case 6: + buf = CFCMethod_full_override_sym(self, invoker); + break; default: croak("Unexpected ix: %d", (int)ix); } RETVAL = newSVpvn(buf, strlen(buf)); @@ -923,7 +927,6 @@ void _set_or_get(self, ...) CFCMethod *self; ALIAS: - full_override_sym = 10 abstract = 12 novel = 14 final = 16 @@ -934,11 +937,6 @@ ALIAS: PPCODE: { START_SET_OR_GET_SWITCH - case 10: { - const char *value = CFCMethod_full_override_sym(self); - retval = newSVpvn(value, strlen(value)); - } - break; case 12: retval = newSViv(CFCMethod_abstract(self)); break; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/bfa43f3d/compiler/src/CFCBindClass.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCBindClass.c b/compiler/src/CFCBindClass.c index 6faf67d..a5ccfc2 100644 --- a/compiler/src/CFCBindClass.c +++ b/compiler/src/CFCBindClass.c @@ -666,7 +666,7 @@ S_override_decs(CFCBindClass *self) { if (CFCMethod_final(method) || !CFCMethod_novel(method)) { continue; } - const char *override_sym = CFCMethod_full_override_sym(method); + char *override_sym = CFCMethod_full_override_sym(method, self->client); CFCType *return_type = CFCMethod_get_return_type(method); CFCParamList *param_list = CFCMethod_get_param_list(method); const char *ret_type_str = CFCType_to_c(return_type); @@ -678,6 +678,7 @@ S_override_decs(CFCBindClass *self) { = CFCUtil_sprintf(pattern, ret_type_str, override_sym, params); decs = CFCUtil_cat(decs, callback_dec, NULL); FREEMEM(callback_dec); + FREEMEM(override_sym); nulls = CFCUtil_cat(nulls, "#define ", override_sym, " NULL\n", NULL); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/bfa43f3d/compiler/src/CFCBindMethod.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCBindMethod.c b/compiler/src/CFCBindMethod.c index a205861..f98a7bd 100644 --- a/compiler/src/CFCBindMethod.c +++ b/compiler/src/CFCBindMethod.c @@ -139,9 +139,12 @@ char* CFCBindMeth_novel_spec_def(CFCMethod *method, CFCClass *klass) { const char *meth_name = CFCMethod_get_name(method); - const char *full_override_sym = "NULL"; + char *full_override_sym; if (!CFCMethod_final(method)) { - full_override_sym = CFCMethod_full_override_sym(method); + full_override_sym = CFCMethod_full_override_sym(method, klass); + } + else { + full_override_sym = CFCUtil_strdup("NULL"); } char *imp_func = CFCMethod_imp_func(method, klass); @@ -160,6 +163,7 @@ CFCBindMeth_novel_spec_def(CFCMethod *method, CFCClass *klass) { FREEMEM(full_offset_sym); FREEMEM(imp_func); + FREEMEM(full_override_sym); return def; } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/bfa43f3d/compiler/src/CFCC.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCC.c b/compiler/src/CFCC.c index 48d3128..f676ad3 100644 --- a/compiler/src/CFCC.c +++ b/compiler/src/CFCC.c @@ -91,9 +91,10 @@ S_callback_decs(CFCClass *klass) { // Define callback to NULL. if (CFCMethod_novel(method) && !CFCMethod_final(method)) { - const char *override_sym = CFCMethod_full_override_sym(method); + char *override_sym = CFCMethod_full_override_sym(method, klass); cb_decs = CFCUtil_cat(cb_decs, "#define ", override_sym, " NULL\n", NULL); + FREEMEM(override_sym); } } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/bfa43f3d/compiler/src/CFCMethod.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCMethod.c b/compiler/src/CFCMethod.c index 8ee3e9c..f8d1e76 100644 --- a/compiler/src/CFCMethod.c +++ b/compiler/src/CFCMethod.c @@ -37,7 +37,6 @@ struct CFCMethod { CFCCallable callable; CFCMethod *novel_method; - char *full_override_sym; char *host_alias; int is_final; int is_abstract; @@ -121,7 +120,6 @@ CFCMethod_init(CFCMethod *self, CFCParcel *parcel, const char *exposure, } self->novel_method = NULL; - self->full_override_sym = NULL; self->host_alias = NULL; self->is_final = is_final; self->is_abstract = is_abstract; @@ -142,7 +140,6 @@ CFCMethod_resolve_types(CFCMethod *self) { void CFCMethod_destroy(CFCMethod *self) { CFCBase_decref((CFCBase*)self->novel_method); - FREEMEM(self->full_override_sym); FREEMEM(self->host_alias); CFCCallable_destroy((CFCCallable*)self); } @@ -356,16 +353,12 @@ CFCMethod_full_typedef(CFCMethod *self, CFCClass *invoker) { return S_full_method_sym(self, invoker, "_t"); } -const char* -CFCMethod_full_override_sym(CFCMethod *self) { - if (!self->full_override_sym) { - const char *Prefix = CFCMethod_get_Prefix(self); - const char *nickname = CFCMethod_get_class_nickname(self); - const char *name = CFCMethod_get_name(self); - self->full_override_sym - = CFCUtil_sprintf("%s%s_%s_OVERRIDE", Prefix, nickname, name); - } - return self->full_override_sym; +char* +CFCMethod_full_override_sym(CFCMethod *self, CFCClass *klass) { + const char *Prefix = CFCClass_get_Prefix(klass); + const char *nickname = CFCClass_get_nickname(klass); + const char *name = CFCMethod_get_name(self); + return CFCUtil_sprintf("%s%s_%s_OVERRIDE", Prefix, nickname, name); } int http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/bfa43f3d/compiler/src/CFCMethod.h ---------------------------------------------------------------------- diff --git a/compiler/src/CFCMethod.h b/compiler/src/CFCMethod.h index e57eb5c..8ac6395 100644 --- a/compiler/src/CFCMethod.h +++ b/compiler/src/CFCMethod.h @@ -175,8 +175,8 @@ CFCMethod_full_typedef(CFCMethod *self, struct CFCClass *invoker); * callback to the host in the event that a host method has been defined which * overrides this method, e.g. "crust_LobClaw_pinch_OVERRIDE". */ -const char* -CFCMethod_full_override_sym(CFCMethod *self); +char* +CFCMethod_full_override_sym(CFCMethod *self, struct CFCClass *klass); int CFCMethod_final(CFCMethod *self); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/bfa43f3d/compiler/src/CFCPerl.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPerl.c b/compiler/src/CFCPerl.c index 6947542..e537226 100644 --- a/compiler/src/CFCPerl.c +++ b/compiler/src/CFCPerl.c @@ -616,7 +616,7 @@ S_write_callbacks_c(CFCPerl *self) { // Define callback. if (CFCMethod_novel(method) && !CFCMethod_final(method)) { - char *cb_def = CFCPerlMethod_callback_def(method); + char *cb_def = CFCPerlMethod_callback_def(method, klass); content = CFCUtil_cat(content, cb_def, "\n", NULL); FREEMEM(cb_def); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/bfa43f3d/compiler/src/CFCPerlMethod.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPerlMethod.c b/compiler/src/CFCPerlMethod.c index cfc474a..08d01a6 100644 --- a/compiler/src/CFCPerlMethod.c +++ b/compiler/src/CFCPerlMethod.c @@ -411,7 +411,7 @@ S_xsub_def_positional_args(CFCPerlMethod *self, CFCClass *klass) { } char* -CFCPerlMethod_callback_def(CFCMethod *method) { +CFCPerlMethod_callback_def(CFCMethod *method, CFCClass *klass) { CFCType *return_type = CFCMethod_get_return_type(method); char *callback_body = NULL; @@ -445,7 +445,7 @@ CFCPerlMethod_callback_def(CFCMethod *method) { FREEMEM(refcount_mods); } - const char *override_sym = CFCMethod_full_override_sym(method); + char *override_sym = CFCMethod_full_override_sym(method, klass); CFCParamList *param_list = CFCMethod_get_param_list(method); const char *params = CFCParamList_to_c(param_list); @@ -462,6 +462,7 @@ CFCPerlMethod_callback_def(CFCMethod *method) { callback_body); FREEMEM(callback_body); + FREEMEM(override_sym); return callback_def; } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/bfa43f3d/compiler/src/CFCPerlMethod.h ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPerlMethod.h b/compiler/src/CFCPerlMethod.h index 2e5b7f3..72cd286 100644 --- a/compiler/src/CFCPerlMethod.h +++ b/compiler/src/CFCPerlMethod.h @@ -63,7 +63,7 @@ CFCPerlMethod_xsub_def(CFCPerlMethod *self, struct CFCClass *klass); * class. */ char* -CFCPerlMethod_callback_def(struct CFCMethod *method); +CFCPerlMethod_callback_def(struct CFCMethod *method, struct CFCClass *klass); #ifdef __cplusplus }
