Avoid unwanted calls to To_Host Make sure that Perl constructors and XSBind_cfish_obj_to_sv don't invoke To_Host but always return a reference to a Clownfish::Obj.
Don't call To_Host when mortalizing objects converted from Perl arrays and hashes. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/7a4aeb99 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/7a4aeb99 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/7a4aeb99 Branch: refs/heads/master Commit: 7a4aeb9989c9b15e23cec8298233aac2ba355b22 Parents: e702b27 Author: Nick Wellnhofer <[email protected]> Authored: Fri May 29 13:49:42 2015 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Fri May 29 17:44:47 2015 +0200 ---------------------------------------------------------------------- compiler/src/CFCPerlConstructor.c | 2 +- runtime/perl/xs/XSBind.c | 23 +++++++++++++++-------- runtime/perl/xs/XSBind.h | 11 +++++------ 3 files changed, 21 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/7a4aeb99/compiler/src/CFCPerlConstructor.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPerlConstructor.c b/compiler/src/CFCPerlConstructor.c index c1b9839..9dfce1f 100644 --- a/compiler/src/CFCPerlConstructor.c +++ b/compiler/src/CFCPerlConstructor.c @@ -133,7 +133,7 @@ CFCPerlConstructor_xsub_def(CFCPerlConstructor *self, CFCClass *klass) { "\n" " retval = %s(%s);\n" " if (retval) {\n" - " ST(0) = (SV*)CFISH_Obj_To_Host((cfish_Obj*)retval);\n" + " ST(0) = CFISH_OBJ_TO_SV(retval);\n" " CFISH_DECREF_NN(retval);\n" " }\n" " else {\n" http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/7a4aeb99/runtime/perl/xs/XSBind.c ---------------------------------------------------------------------- diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c index ab2d8ae..fa571f9 100644 --- a/runtime/perl/xs/XSBind.c +++ b/runtime/perl/xs/XSBind.c @@ -130,7 +130,7 @@ XSBind_maybe_sv_to_cfish_obj(pTHX_ SV *sv, cfish_Class *klass, // Mortalize the converted object -- which is somewhat // dangerous, but is the only way to avoid requiring that the // caller take responsibility for a refcount. - SV *mortal = (SV*)CFISH_Obj_To_Host(retval); + SV *mortal = XSBind_cfish_obj_to_sv(aTHX_ retval); CFISH_DECREF(retval); sv_2mortal(mortal); } @@ -757,20 +757,21 @@ cfish_dec_refcount(void *vself) { return modified_refcount; } -void* -CFISH_Obj_To_Host_IMP(cfish_Obj *self) { - dTHX; +SV* +XSBind_cfish_obj_to_sv(pTHX_ cfish_Obj *obj) { + if (obj == NULL) { return newSV(0); } + SV *perl_obj; - if (self->ref.count & XSBIND_REFCOUNT_FLAG) { - perl_obj = S_lazy_init_host_obj(aTHX_ self); + if (obj->ref.count & XSBIND_REFCOUNT_FLAG) { + perl_obj = S_lazy_init_host_obj(aTHX_ obj); } else { - perl_obj = newRV_inc((SV*)self->ref.host_obj); + perl_obj = newRV_inc((SV*)obj->ref.host_obj); } // Enable overloading for Perl 5.8.x #if PERL_VERSION <= 8 - HV *stash = SvSTASH((SV*)self->ref.host_obj); + HV *stash = SvSTASH((SV*)obj->ref.host_obj); if (Gv_AMG(stash)) { SvAMAGIC_on(perl_obj); } @@ -779,6 +780,12 @@ CFISH_Obj_To_Host_IMP(cfish_Obj *self) { return perl_obj; } +void* +CFISH_Obj_To_Host_IMP(cfish_Obj *self) { + dTHX; + return XSBind_cfish_obj_to_sv(aTHX_ self); +} + /*************************** Clownfish::Class ******************************/ cfish_Obj* http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/7a4aeb99/runtime/perl/xs/XSBind.h ---------------------------------------------------------------------- diff --git a/runtime/perl/xs/XSBind.h b/runtime/perl/xs/XSBind.h index 976d3da..e75b948 100644 --- a/runtime/perl/xs/XSBind.h +++ b/runtime/perl/xs/XSBind.h @@ -80,15 +80,14 @@ cfish_XSBind_maybe_sv_to_cfish_obj(pTHX_ SV *sv, cfish_Class *klass, /** Derive an SV from a Clownfish object. If the Clownfish object is NULL, the SV - * will be undef. + * will be undef. Doesn't invoke To_Host and always returns a reference to a + * Clownfish::Obj. * * The new SV has single refcount for which the caller must take * responsibility. */ -static CFISH_INLINE SV* -cfish_XSBind_cfish_obj_to_sv(pTHX_ cfish_Obj *obj) { - return obj ? (SV*)CFISH_Obj_To_Host(obj) : newSV(0); -} +CFISH_VISIBLE SV* +cfish_XSBind_cfish_obj_to_sv(pTHX_ cfish_Obj *obj); /** XSBind_cfish_obj_to_sv, with a cast. */ @@ -103,7 +102,7 @@ static CFISH_INLINE SV* cfish_XSBind_cfish_obj_to_sv_noinc(pTHX_ cfish_Obj *obj) { SV *retval; if (obj) { - retval = (SV*)CFISH_Obj_To_Host(obj); + retval = cfish_XSBind_cfish_obj_to_sv(aTHX_ obj); CFISH_DECREF_NN(obj); } else {
