From: Artur Bergman Date: Mon, 3 Sep 2001 10:47:11 +0000 (+0000) Subject: Document the changes with regards to running of END blocks. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d95b23b2631584416599fb5570272be851d76e05;p=p5sagit%2Fp5-mst-13.2.git Document the changes with regards to running of END blocks. And DESTROY on global objects are called in perl_destruct()! p4raw-id: //depot/perl@11839 --- diff --git a/pod/perl572delta.pod b/pod/perl572delta.pod index 13d5690..6b0a644 100644 --- a/pod/perl572delta.pod +++ b/pod/perl572delta.pod @@ -163,6 +163,14 @@ C now works. VMS now works under PerlIO. +=item * + +END blocks are now run even if you exit/die in a BEGIN block. +The execution of END blocks is now controlled by +PL_exit_flags & PERL_EXIT_DESTRUCT_END. This enables the new +behaviour for perl embedders. This will default in 5.10. See +L. + =back =head1 Modules and Pragmata diff --git a/pod/perlembed.pod b/pod/perlembed.pod index ecbe1f6..1a08a77 100644 --- a/pod/perlembed.pod +++ b/pod/perlembed.pod @@ -185,6 +185,7 @@ version of I containing the essentials of embedding: { my_perl = perl_alloc(); perl_construct(my_perl); + PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl_parse(my_perl, NULL, argc, argv, (char **)NULL); perl_run(my_perl); perl_destruct(my_perl); @@ -238,6 +239,7 @@ That's shown below, in a program I'll call I. perl_construct(my_perl); perl_parse(my_perl, NULL, argc, argv, NULL); + PL_exit_flags |= PERL_EXIT_DESTRUCT_END; /*** skipping perl_run() ***/ @@ -270,10 +272,9 @@ yielding the number of seconds that elapsed between January 1, 1970 (the beginning of the Unix epoch), and the moment I began writing this sentence. -In this particular case we don't have to call I, but in -general it's considered good practice to ensure proper initialization -of library code, including execution of all object C methods -and package C blocks. +In this particular case we don't have to call I, as we set +the PL_exit_flag PERL_EXIT_DESTRUCT_END which executes END blocks in +perl_destruct. If you want to pass arguments to the Perl subroutine, you can add strings to the C-terminated C list passed to @@ -311,6 +312,7 @@ the first, a C from the second, and a C from the third. perl_construct( my_perl ); perl_parse(my_perl, NULL, 3, embedding, NULL); + PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl_run(my_perl); /** Treat $a as an integer **/ @@ -488,6 +490,7 @@ been wrapped here): perl_construct(my_perl); perl_parse(my_perl, NULL, 3, embedding, NULL); + PL_exit_flags |= PERL_EXIT_DESTRUCT_END; sv_setpv(text, "When he is at a convenience store and the bill comes to some amount like 76 cents, Maynard is aware that there is something he *should* do, something that will enable him to get back a quarter, but he has no idea *what*. He fumbles through his red squeezey changepurse and gives the boy three extra pennies with his dollar, hoping that he might luck into the correct amount. The boy gives him back two of his own pennies and then the big shiny quarter that is his prize. -RICHH"); @@ -612,6 +615,7 @@ deep breath... perl_construct( my_perl ); perl_parse(my_perl, NULL, 2, my_argv, (char **)NULL); + PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl_run(my_perl); PerlPower(3, 4); /*** Compute 3 ** 4 ***/ @@ -761,7 +765,7 @@ with L whenever possible. perl_construct(perl); exitstatus = perl_parse(perl, NULL, 2, embedding, NULL); - + PL_exit_flags |= PERL_EXIT_DESTRUCT_END; if(!exitstatus) { exitstatus = perl_run(perl); @@ -808,6 +812,14 @@ Now run: foo says: hello Enter file name: ^C +=head2 Execution of END blocks + +Traditionally END blocks have been executed at the end of the perl_run. +This causes problems for applications that never call perl_run. Since +perl 5.7.2 you can specify C +to get the new behaviour. This also enables the running of END blocks if +the perl_prase fails and C will return the exit value. + =head2 Maintaining multiple interpreter instances Some rare applications will need to create more than one interpreter