From: gfx Date: Sun, 31 Jan 2010 07:44:43 +0000 (+0900) Subject: Fix magic handling in type constraints (reported by sunnavy) X-Git-Tag: 0.48~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=85a74fcf70600193f68dca0ca705bcf01e937d69;p=gitmo%2FMouse.git Fix magic handling in type constraints (reported by sunnavy) --- diff --git a/t/001_mouse/066-magic.t b/t/001_mouse/066-magic.t new file mode 100644 index 0000000..b4460d0 --- /dev/null +++ b/t/001_mouse/066-magic.t @@ -0,0 +1,42 @@ +#!perl +use strict; +use warnings; +use Test::More tests => 3; + +use Tie::Scalar; + +{ + package MyClass; + use Mouse; + + has foo => ( + is => 'rw', + isa => 'Int', + ); + has bar => ( + is => 'rw', + isa => 'Maybe[Int]', + ); +} + +sub ts_init { + tie $_[0], 'Tie::StdScalar', $_[1]; +} + +ts_init(my $x, 10); + +my $o = MyClass->new(); +is(eval{ $o->foo($x) }, 10) + or diag("Error: $@"); + +ts_init($x, 'foo'); + +eval{ + $o->bar($x); +}; +isnt $@, ''; + +ts_init $x, 42; +is(eval{ $o->bar($x) }, 42) + or diag("Error: $@"); + diff --git a/xs-src/MouseTypeConstraints.xs b/xs-src/MouseTypeConstraints.xs index 08df0e8..8b94c85 100644 --- a/xs-src/MouseTypeConstraints.xs +++ b/xs-src/MouseTypeConstraints.xs @@ -16,11 +16,15 @@ typedef int (*check_fptr_t)(pTHX_ SV* const data, SV* const sv); +/* + NOTE: mouse_tc_check() handles GETMAGIC +*/ int mouse_tc_check(pTHX_ SV* const tc_code, SV* const sv) { CV* const cv = (CV*)SvRV(tc_code); assert(SvTYPE(cv) == SVt_PVCV); + SvGETMAGIC(sv); if(CvXSUB(cv) == XS_Mouse_constraint_check){ /* built-in type constraints */ MAGIC* const mg = (MAGIC*)CvXSUBANY(cv).any_ptr; @@ -244,7 +248,6 @@ mouse_parameterized_ArrayRef(pTHX_ SV* const param, SV* const sv) { I32 i; for(i = 0; i < len; i++){ SV* const value = *av_fetch(av, i, TRUE); - SvGETMAGIC(value); if(!mouse_tc_check(aTHX_ param, value)){ return FALSE; } @@ -263,7 +266,6 @@ mouse_parameterized_HashRef(pTHX_ SV* const param, SV* const sv) { hv_iterinit(hv); while((he = hv_iternext(hv))){ SV* const value = hv_iterval(hv, he); - SvGETMAGIC(value); if(!mouse_tc_check(aTHX_ param, value)){ hv_iterinit(hv); /* reset */ return FALSE;