Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception in DESTROY in global destruction is “swallowed” confusingly #18063

Closed
FGasper opened this issue Aug 14, 2020 · 3 comments · Fixed by #18064
Closed

exception in DESTROY in global destruction is “swallowed” confusingly #18063

FGasper opened this issue Aug 14, 2020 · 3 comments · Fixed by #18064

Comments

@FGasper
Copy link
Contributor

FGasper commented Aug 14, 2020

Module: core

Description

perl -Mstrict -w -e'package Foo; sub DESTROY { die "nono" }; package main; our $wut = bless [], "Foo"'

gives:

(in cleanup) (in cleanup)  at -e line 1 during global destruction.

Expected behavior
Ideally nono should print to STDERR. At the very minimum, though, it seems confusing that (in cleanup) shows twice and makes it look like something confused perl.

Perl configuration
5.30.0, 5.26.3

@atoomic
Copy link
Member

atoomic commented Aug 14, 2020

Note that in perl5.22.4 the output is different

> perl5.22.4 -Mstrict -w -e'package Foo; sub DESTROY { die "nono" }; package main; our $wut = bless [], "Foo"'

	(in cleanup) nono at -e line 1 during global destruction.

@atoomic
Copy link
Member

atoomic commented Aug 14, 2020

The behavior was changed in v5.25.3 by 8c86f02

@atoomic
Copy link
Member

atoomic commented Aug 14, 2020

Here is a suggestion to restore the previous behavior only during global destruction

diff --git a/pp_ctl.c b/pp_ctl.c
index 5a66e267a7..ffb0506f47 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1654,7 +1654,11 @@ Perl_die_unwind(pTHX_ SV *msv)
     if (in_eval) {
        I32 cxix;

-        exceptsv = sv_2mortal(SvREFCNT_inc_simple_NN(exceptsv));
+        if (PL_phase == PERL_PHASE_DESTRUCT) {
+            exceptsv = sv_mortalcopy(exceptsv);
+        } else {
+            exceptsv = sv_2mortal(SvREFCNT_inc_simple_NN(exceptsv));
+        }

        /*
         * Historically, perl used to set ERRSV ($@) early in the die

atoomic added a commit to atoomic/perl5 that referenced this issue Aug 14, 2020
Fix Perl#18063

During global destruction make sure we preserve
the string by using mortalcopy.

This is an update on 8c86f02
change which avoided sv_mortalcopy in favor of sv_2mortal.
atoomic added a commit to atoomic/perl5 that referenced this issue Aug 14, 2020
Fix Perl#18063

During global destruction make sure we preserve
the string by using mortalcopy.

This is an update on 8c86f02
change which avoided sv_mortalcopy in favor of sv_2mortal.
atoomic added a commit that referenced this issue Aug 21, 2020
Fix #18063

During global destruction make sure we preserve
the string by using mortalcopy.

This is an update on 8c86f02
change which avoided sv_mortalcopy in favor of sv_2mortal.
steve-m-hay pushed a commit that referenced this issue Jan 6, 2021
Fix #18063

During global destruction make sure we preserve
the string by using mortalcopy.

This is an update on 8c86f02
change which avoided sv_mortalcopy in favor of sv_2mortal.

(cherry picked from commit 042abef)
atoomic added a commit to atoomic/perl5 that referenced this issue Mar 30, 2022
Fix Perl#18063

During global destruction make sure we preserve
the string by using mortalcopy.

This is an update on 8c86f02
change which avoided sv_mortalcopy in favor of sv_2mortal.

(cherry picked from commit 042abef)
Signed-off-by: ℕicolas ℝochelemagne <rochelemagne@cpanel.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants