On Mon, May 18, 2015 at 4:29 AM, Nick Wellnhofer <[email protected]> wrote:

> But the only caller of S_lazy_init_host_obj is CFISH_Obj_To_Host_IMP and
> this method needs the outer object.

Ah!  Since that's now true, then yes, it should return the outer object.

>     https://github.com/nwellnhof/lucy-clownfish/commits/sv_bless

After a few compatibility tweaks, that branch passes tests on Perl 5.12.5.
The only problem I see is here:

         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
+            SvREFCNT_dec(outer_obj);
+            return newRV_inc((SV*)self->ref.host_obj);
         }

That "unblessing" code guards against two Perl objects (in different threads)
taking ownership of the same Clownfish object.  Without the unblessing,
DESTROY will be invoked immediately when outer_obj is decref'd and all
subsequent usage of the Clownfish object will be invalid.

Marvin Humphrey

Reply via email to