From: Gisle Aas Date: Tue, 21 Mar 2006 10:16:43 +0000 (+0000) Subject: Test croak(NULL) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7e7a3dfc0d3c74b10a066568a904a5a10013d5e4;p=p5sagit%2Fp5-mst-13.2.git Test croak(NULL) p4raw-id: //depot/perl@27560 --- diff --git a/ext/XS/APItest/APItest.xs b/ext/XS/APItest/APItest.xs index c8391c6..3a31ec9 100644 --- a/ext/XS/APItest/APItest.xs +++ b/ext/XS/APItest/APItest.xs @@ -461,10 +461,15 @@ exception(throw_e) RETVAL void -mycroak(pv) - const char* pv +mycroak(sv) + SV* sv CODE: - Perl_croak(aTHX_ "%s", pv); + if (SvOK(sv)) { + Perl_croak(aTHX_ "%s", SvPV_nolen(sv)); + } + else { + Perl_croak(aTHX_ NULL); + } SV* strtab() diff --git a/ext/XS/APItest/t/exception.t b/ext/XS/APItest/t/exception.t index 5341589..dc6d324 100644 --- a/ext/XS/APItest/t/exception.t +++ b/ext/XS/APItest/t/exception.t @@ -9,7 +9,7 @@ BEGIN { } } -use Test::More tests => 9; +use Test::More tests => 12; BEGIN { use_ok('XS::APItest') }; @@ -32,5 +32,10 @@ is($@, "boo\n"); ok(not defined $rv); is($XS::APItest::exception_caught, 1); -$rv = eval { mycroak("foobar\n") }; +$rv = eval { mycroak("foobar\n"); 1 }; is($@, "foobar\n", 'croak'); +ok(not defined $rv); + +$rv = eval { $@ = bless{}, "foo"; mycroak(undef); 1 }; +is(ref($@), "foo", 'croak(NULL)'); +ok(not defined $rv);