From: gfx Date: Mon, 16 Nov 2009 12:17:43 +0000 (+0900) Subject: Fix default and weak stuff X-Git-Tag: 0.40_07~28 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3f2c3dc70ab19ea75f2bb67af78f60d31134f725;p=gitmo%2FMouse.git Fix default and weak stuff --- diff --git a/lib/Mouse/Meta/Method/Accessor.pm b/lib/Mouse/Meta/Method/Accessor.pm index a71266a..2f03b9d 100755 --- a/lib/Mouse/Meta/Method/Accessor.pm +++ b/lib/Mouse/Meta/Method/Accessor.pm @@ -104,6 +104,9 @@ sub _generate_accessor{ else{ $accessor .= "$slot = $value;\n"; } + if ($is_weak) { + $accessor .= "Scalar::Util::weaken($slot) if ref $slot;\n"; + } $accessor .= "}\n"; } diff --git a/xs-src/MouseAttribute.xs b/xs-src/MouseAttribute.xs index 62b2593..a7bb4d4 100644 --- a/xs-src/MouseAttribute.xs +++ b/xs-src/MouseAttribute.xs @@ -142,6 +142,9 @@ mouse_xa_set_default(pTHX_ AV* const xa, SV* const object) { U16 const flags = (U16)MOUSE_xa_flags(xa); SV* value; + ENTER; + SAVETMPS; + /* get default value by $attr->builder or $attr->default */ if(flags & MOUSEf_ATTR_HAS_BUILDER){ SV* const builder = mcall0s(MOUSE_xa_attribute(xa), "builder"); @@ -162,11 +165,13 @@ mouse_xa_set_default(pTHX_ AV* const xa, SV* const object) { /* store value to slot */ value = set_slot(object, MOUSE_xa_slot(xa), value); - if(flags & MOUSEf_ATTR_IS_WEAK_REF && SvROK(value)){ weaken_slot(object, MOUSE_xa_slot(xa)); } + FREETMPS; + LEAVE; + return value; }