Change 30067 by [EMAIL PROTECTED] on 2007/01/29 20:05:52
BEGIN blocks in XS should work. (Given that CHECK, INIT and END all do)
Affected files ...
... //depot/perl/MANIFEST#1515 edit
... //depot/perl/ext/XS/APItest/APItest.pm#17 edit
... //depot/perl/ext/XS/APItest/APItest.xs#34 edit
... //depot/perl/ext/XS/APItest/t/xs_special_subs.t#1 add
... //depot/perl/op.c#885 edit
Differences ...
==== //depot/perl/MANIFEST#1515 (text) ====
Index: perl/MANIFEST
--- perl/MANIFEST#1514~30012~ 2007-01-26 07:21:37.000000000 -0800
+++ perl/MANIFEST 2007-01-29 12:05:52.000000000 -0800
@@ -1230,6 +1230,7 @@
ext/XS/APItest/t/printf.t XS::APItest extension
ext/XS/APItest/t/push.t XS::APItest extension
ext/XS/APItest/t/svsetsv.t Test behaviour of sv_setsv with/without
PERL_CORE
+ext/XS/APItest/t/xs_special_subs.t Test that XS BEGIN/CHECK/INIT/END work
ext/XS/Typemap/Makefile.PL XS::Typemap extension
ext/XS/Typemap/README XS::Typemap extension
ext/XS/Typemap/stdio.c XS::Typemap extension
==== //depot/perl/ext/XS/APItest/APItest.pm#17 (text) ====
Index: perl/ext/XS/APItest/APItest.pm
--- perl/ext/XS/APItest/APItest.pm#16~29248~ 2006-11-12 12:22:28.000000000
-0800
+++ perl/ext/XS/APItest/APItest.pm 2007-01-29 12:05:52.000000000 -0800
@@ -35,9 +35,17 @@
sub G_NODEBUG() { 32 }
sub G_METHOD() { 64 }
-our $VERSION = '0.11';
+our $VERSION = '0.12';
-bootstrap XS::APItest $VERSION;
+use vars '$WARNINGS_ON_BOOTSTRAP';
+if ($WARNINGS_ON_BOOTSTRAP) {
+ bootstrap XS::APItest $VERSION;
+} else {
+ local $^W;
+ # Need $W false by default, as some tests run under -w, and under -w we
+ # can get warnings about "Too late to run CHECK" block (and INIT block)
+ bootstrap XS::APItest $VERSION;
+}
1;
__END__
==== //depot/perl/ext/XS/APItest/APItest.xs#34 (text) ====
Index: perl/ext/XS/APItest/APItest.xs
--- perl/ext/XS/APItest/APItest.xs#33~29284~ 2006-11-15 09:32:24.000000000
-0800
+++ perl/ext/XS/APItest/APItest.xs 2007-01-29 12:05:52.000000000 -0800
@@ -566,3 +566,28 @@
bool
sv_setsv_cow_hashkey_notcore()
+
+void
+BEGIN()
+ CODE:
+ sv_inc(get_sv("XS::APItest::BEGIN_called", GV_ADD|GV_ADDMULTI));
+
+void
+CHECK()
+ CODE:
+ sv_inc(get_sv("XS::APItest::CHECK_called", GV_ADD|GV_ADDMULTI));
+
+void
+UNITCHECK()
+ CODE:
+ sv_inc(get_sv("XS::APItest::CHECK_called", GV_ADD|GV_ADDMULTI));
+
+void
+INIT()
+ CODE:
+ sv_inc(get_sv("XS::APItest::INIT_called", GV_ADD|GV_ADDMULTI));
+
+void
+END()
+ CODE:
+ sv_inc(get_sv("XS::APItest::END_called", GV_ADD|GV_ADDMULTI));
==== //depot/perl/ext/XS/APItest/t/xs_special_subs.t#1 (text) ====
Index: perl/ext/XS/APItest/t/xs_special_subs.t
--- /dev/null 2007-01-16 11:55:45.526841103 -0800
+++ perl/ext/XS/APItest/t/xs_special_subs.t 2007-01-29 12:05:52.000000000
-0800
@@ -0,0 +1,84 @@
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+ push @INC, "::lib:$MacPerl::Architecture:" if $^O eq 'MacOS';
+ require Config; import Config;
+ if ($Config{'extensions'} !~ /\bXS\/APItest\b/) {
+ print "1..0 # Skip: XS::APItest was not built\n";
+ exit 0;
+ }
+}
+
+use strict;
+use warnings;
+use Test::More tests => 40;
+
+# Doing this longhand cut&paste makes it clear
+# BEGIN and INIT are FIFO, CHECK and END are LIFO
+BEGIN {
+ is($XS::APItest::BEGIN_called, undef, "BEGIN not yet called");
+ is($XS::APItest::CHECK_called, undef, "CHECK not yet called");
+ is($XS::APItest::INIT_called, undef, "INIT not yet called");
+ is($XS::APItest::END_called, undef, "END not yet called");
+}
+
+CHECK {
+ is($XS::APItest::BEGIN_called, 1, "BEGIN called");
+ is($XS::APItest::CHECK_called, 1, "CHECK called");
+ is($XS::APItest::INIT_called, undef, "INIT not yet called");
+ is($XS::APItest::END_called, undef, "END not yet called");
+}
+
+INIT {
+ is($XS::APItest::BEGIN_called, 1, "BEGIN called");
+ is($XS::APItest::CHECK_called, 1, "CHECK called");
+ is($XS::APItest::INIT_called, undef, "INIT not yet called");
+ is($XS::APItest::END_called, undef, "END not yet called");
+}
+
+END {
+ is($XS::APItest::BEGIN_called, 1, "BEGIN called");
+ is($XS::APItest::CHECK_called, 1, "CHECK called");
+ is($XS::APItest::INIT_called, 1, "INIT called");
+ is($XS::APItest::END_called, 1, "END called");
+}
+
+is($XS::APItest::BEGIN_called, 1, "BEGIN called");
+is($XS::APItest::CHECK_called, 1, "CHECK called");
+is($XS::APItest::INIT_called, 1, "INIT called");
+is($XS::APItest::END_called, undef, "END not yet called");
+
+use XS::APItest;
+
+is($XS::APItest::BEGIN_called, 1, "BEGIN called");
+is($XS::APItest::CHECK_called, 1, "CHECK called");
+is($XS::APItest::INIT_called, 1, "INIT called");
+is($XS::APItest::END_called, undef, "END not yet called");
+
+BEGIN {
+ is($XS::APItest::BEGIN_called, 1, "BEGIN called");
+ is($XS::APItest::CHECK_called, undef, "CHECK not yet called");
+ is($XS::APItest::INIT_called, undef, "INIT not yet called");
+ is($XS::APItest::END_called, undef, "END not yet called");
+}
+
+CHECK {
+ is($XS::APItest::BEGIN_called, 1, "BEGIN called");
+ is($XS::APItest::CHECK_called, undef, "CHECK not yet called");
+ is($XS::APItest::INIT_called, undef, "INIT not yet called");
+ is($XS::APItest::END_called, undef, "END not yet called");
+}
+
+INIT {
+ is($XS::APItest::BEGIN_called, 1, "BEGIN called");
+ is($XS::APItest::CHECK_called, 1, "CHECK called");
+ is($XS::APItest::INIT_called, 1, "INIT called");
+ is($XS::APItest::END_called, undef, "END not yet called");
+}
+
+END {
+ is($XS::APItest::BEGIN_called, 1, "BEGIN called");
+ is($XS::APItest::CHECK_called, 1, "CHECK called");
+ is($XS::APItest::INIT_called, 1, "INIT called");
+ is($XS::APItest::END_called, undef, "END not yet called");
+}
==== //depot/perl/op.c#885 (text) ====
Index: perl/op.c
--- perl/op.c#884~30064~ 2007-01-29 10:28:16.000000000 -0800
+++ perl/op.c 2007-01-29 12:05:52.000000000 -0800
@@ -5638,8 +5638,18 @@
goto done;
if (strEQ(s, "BEGIN")) {
+ const I32 oldscope = PL_scopestack_ix;
+ ENTER;
+ SAVECOPFILE(&PL_compiling);
+ SAVECOPLINE(&PL_compiling);
+
Perl_av_create_and_push(aTHX_ &PL_beginav, (SV*)cv);
GvCV(gv) = 0; /* cv has been hijacked */
+ call_list(oldscope, PL_beginav);
+
+ PL_curcop = &PL_compiling;
+ CopHINTS_set(&PL_compiling, PL_hints);
+ LEAVE;
}
else if (strEQ(s, "END")) {
Perl_av_create_and_unshift_one(aTHX_ &PL_endav, (SV*)cv);
End of Patch.