Convert Perl reference-to-undef to NULL After cloning a Perl interpreter, most Clownfish objects end up as references to undef. Make sure they're converted to a NULL pointer.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/fd798480 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/fd798480 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/fd798480 Branch: refs/heads/master Commit: fd798480128b169c75d9455cbe7b7bb8ad73d308 Parents: 3ed5a19 Author: Nick Wellnhofer <[email protected]> Authored: Sun May 10 18:24:35 2015 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Tue May 12 20:15:25 2015 +0200 ---------------------------------------------------------------------- runtime/perl/xs/XSBind.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/fd798480/runtime/perl/xs/XSBind.c ---------------------------------------------------------------------- diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c index 4302f84..2902045 100644 --- a/runtime/perl/xs/XSBind.c +++ b/runtime/perl/xs/XSBind.c @@ -191,6 +191,8 @@ XSBind_perl_to_cfish(pTHX_ SV *sv) { cfish_Obj *retval = NULL; if (XSBind_sv_defined(aTHX_ sv)) { + bool is_undef = false; + if (SvROK(sv)) { // Deep conversion of references. SV *inner = SvRV(sv); @@ -209,11 +211,17 @@ XSBind_perl_to_cfish(pTHX_ SV *sv) { retval = INT2PTR(cfish_Obj*, tmp); (void)CFISH_INCREF(retval); } + else if (!XSBind_sv_defined(aTHX_ inner)) { + // Reference to undef. After cloning a Perl interpeter, + // most Clownfish objects look like this after they're + // CLONE_SKIPped. + is_undef = true; + } } // It's either a plain scalar or a non-Clownfish Perl object, so // stringify. - if (!retval) { + if (!retval && !is_undef) { STRLEN len; char *ptr = SvPVutf8(sv, len); retval = (cfish_Obj*)cfish_Str_new_from_trusted_utf8(ptr, len);
