diff options
author | Nicholas Clark <nick@ccl4.org> | 2010-10-13 13:56:38 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2010-10-13 13:56:38 +0100 |
commit | 05099f26a2ddd438807aa96853b7e317f8afc787 (patch) | |
tree | 458827afb8cb2960fc2bd95264189b3768eaa52d /universal.c | |
parent | 41e1f0ed87316699cf6574906797bee3dd759fb0 (diff) | |
download | perl-05099f26a2ddd438807aa96853b7e317f8afc787.tar.gz |
Consistent stack handling for XS_Tie_Hash_NamedCapture_*
This may also fix bugs for the (untested) cases where CALLREG_NAMED_BUFF_*
returned NULL, and the calling routine attempted XSRETURN_UNDEF.
It's fine to call sv_2mortal() on the immortals returned by
CALLREG_NAMED_BUFF_EXISTS()
Diffstat (limited to 'universal.c')
-rw-r--r-- | universal.c | 53 |
1 files changed, 19 insertions, 34 deletions
diff --git a/universal.c b/universal.c index e66e0db9da..f3fe05dc79 100644 --- a/universal.c +++ b/universal.c @@ -1280,18 +1280,14 @@ XS(XS_Tie_Hash_NamedCapture_FETCH) XSRETURN_UNDEF; SP -= items; + PUTBACK; flags = (U32)SvUV(SvRV(MUTABLE_SV(ST(0)))); ret = CALLREG_NAMED_BUFF_FETCH(rx, ST(1), flags); SPAGAIN; - - if (ret) { - mXPUSHs(ret); - PUTBACK; - return; - } - XSRETURN_UNDEF; + PUSHs(ret ? sv_2mortal(ret) : &PL_sv_undef); + XSRETURN(1); } XS(XS_Tie_Hash_NamedCapture_STORE) @@ -1311,6 +1307,7 @@ XS(XS_Tie_Hash_NamedCapture_STORE) } SP -= items; + PUTBACK; flags = (U32)SvUV(SvRV(MUTABLE_SV(ST(0)))); CALLREG_NAMED_BUFF_STORE(rx,ST(1), ST(2), flags); @@ -1334,10 +1331,12 @@ XS(XS_Tie_Hash_NamedCapture_DELETE) Perl_croak_no_modify(aTHX); SP -= items; + PUTBACK; flags = (U32)SvUV(SvRV(MUTABLE_SV(ST(0)))); ret = CALLREG_NAMED_BUFF_DELETE(rx, ST(1), flags); + SPAGAIN; PUSHs(ret ? sv_2mortal(ret) : &PL_sv_undef); XSRETURN(1); } @@ -1358,6 +1357,7 @@ XS(XS_Tie_Hash_NamedCapture_CLEAR) Perl_croak_no_modify(aTHX); SP -= items; + PUTBACK; flags = (U32)SvUV(SvRV(MUTABLE_SV(ST(0)))); CALLREG_NAMED_BUFF_CLEAR(rx, flags); @@ -1383,15 +1383,14 @@ XS(XS_Tie_Hash_NamedCapture_EXISTS) XSRETURN_UNDEF; SP -= items; + PUTBACK; flags = (U32)SvUV(SvRV(MUTABLE_SV(ST(0)))); ret = CALLREG_NAMED_BUFF_EXISTS(rx, ST(1), flags); SPAGAIN; - - XPUSHs(ret); - PUTBACK; - return; + PUSHs(ret ? sv_2mortal(ret) : &PL_sv_undef); + XSRETURN(1); } XS(XS_Tie_Hash_NamedCapture_FIRSTK) @@ -1411,19 +1410,14 @@ XS(XS_Tie_Hash_NamedCapture_FIRSTK) XSRETURN_UNDEF; SP -= items; + PUTBACK; flags = (U32)SvUV(SvRV(MUTABLE_SV(ST(0)))); ret = CALLREG_NAMED_BUFF_FIRSTKEY(rx, flags); SPAGAIN; - - if (ret) { - mXPUSHs(ret); - PUTBACK; - } else { - XSRETURN_UNDEF; - } - + PUSHs(ret ? sv_2mortal(ret) : &PL_sv_undef); + XSRETURN(1); } XS(XS_Tie_Hash_NamedCapture_NEXTK) @@ -1443,18 +1437,14 @@ XS(XS_Tie_Hash_NamedCapture_NEXTK) XSRETURN_UNDEF; SP -= items; + PUTBACK; flags = (U32)SvUV(SvRV(MUTABLE_SV(ST(0)))); ret = CALLREG_NAMED_BUFF_NEXTKEY(rx, ST(1), flags); SPAGAIN; - - if (ret) { - mXPUSHs(ret); - } else { - XSRETURN_UNDEF; - } - PUTBACK; + PUSHs(ret ? sv_2mortal(ret) : &PL_sv_undef); + XSRETURN(1); } XS(XS_Tie_Hash_NamedCapture_SCALAR) @@ -1474,19 +1464,14 @@ XS(XS_Tie_Hash_NamedCapture_SCALAR) XSRETURN_UNDEF; SP -= items; + PUTBACK; flags = (U32)SvUV(SvRV(MUTABLE_SV(ST(0)))); ret = CALLREG_NAMED_BUFF_SCALAR(rx, flags); SPAGAIN; - - if (ret) { - mXPUSHs(ret); - PUTBACK; - return; - } else { - XSRETURN_UNDEF; - } + PUSHs(ret ? sv_2mortal(ret) : &PL_sv_undef); + XSRETURN(1); } XS(XS_Tie_Hash_NamedCapture_flags) |