http://www.perlmonks.org?node_id=1061501

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Syntax check of the program (perl 5.16.3 64-bit (threaded or otherwise) & Tk 804.031 on CentOS 6 64-bit) causes core dump (but not when it is just run as in perl file) ...

use Tk; # Remove "BEGIN" and get no core dump. BEGIN { our $MW = MainWindow->new(); } __END__ test-tk.pl syntax OK . (1): 0 0x2ba31f0 NV f=00000002 undef(1) SV = IV(0x2ba31e0) at 0x2ba31f0 REFCNT = 1 FLAGS = () IV = 0

There is no problem with combinations of ...

... FWIW. Has anybody else seen the problem?

Replies are listed 'Best First'.
Re: perl 5.16.3 + Tk 804.031 core dumps on syntax check when a window is made in BEGIN block
by choroba (Cardinal) on Nov 07, 2013 at 00:00 UTC
    Appending
    $MW->destroy;

    into the BEGIN block makes the dump go away.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: perl 5.16.3 + Tk 804.031 core dumps on syntax check when a window is made in BEGIN block
by LanX (Saint) on Nov 07, 2013 at 00:04 UTC
    Can't reproduce it, but what happens if you put the use Tk within the BEGIN-block?

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      No change.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Earlier use Tk; was already in BEGIN block before the genesis of above test case.

      Moving destroy() inside BEGIN does avoid the core dump. Need to have, however, the MainWindow object to live beyond BEGIN block for other things.

      # Remove "BEGIN" and get no core dump. BEGIN { use Tk; our $MW = MainWindow->new(); # other method calls. } our $MW; # more changes to the window. # Being here does not avoid core dump. $MW->destroy();
      c

        BEGIN { use Tk; our $MW = MainWindow->new(); # other method calls. } our $MW;

        Perhaps you mean (not verified):

        our $MW; BEGIN { use Tk; $MW = MainWindow->new(); # other method calls. }
        Declare the window before the BEGIN block, and assign it within the BEGIN block. Update: I stand corrected.

        --MidLifeXis

Re: perl 5.16.3 + Tk 804.031 core dumps on syntax check when a window is made in BEGIN block
by Anonymous Monk on Nov 07, 2013 at 00:10 UTC
    FWIW, no "core dump" on win32 perl 5.16.1 Tk 804.030
Re: perl 5.16.3 + Tk 804.031 core dumps on syntax check when a window is made in BEGIN block
by sundialsvc4 (Abbot) on Nov 07, 2013 at 14:21 UTC

    Hmmm... my understanding of the BEGIN block is that it is run at compile time, and that it is typically (only ...?) used to make changes that will affect the subsequent compilation.   So, do you really intend to use this for the purpose of constructing a window?   (There is also, iirc, an INIT block available, which occurs after compilation but before the run.)   Based on my (limited) understanding of the feature, I am surprised that you are trying to do, what you are trying to do, here.   And not too surprised that something as extreme as a core-dump might be the result.   It could well be that this code is attempting to touch things that are not fully initialized yet.   Perhaps this statement should be done elsewhere in the code?

    (I was trying to stumble-upon the correct perldoc page ...)   Thank you... it’s perldoc perlmod.

      That would be perlmod. It's about halfway down the page, and states,
      The begincheck program makes it all clear, eventually:
      #!/usr/bin/perl # begincheck print " 8. Ordinary code runs at runtime.\n"; END { print "14. So this is the end of the tale.\n" } INIT { print " 5. INIT blocks run FIFO just before runtime.\n" } CHECK { print " 4. So this is the fourth line.\n" } print " 9. It runs in order, of course.\n"; BEGIN { print " 1. BEGIN blocks run FIFO during compilation.\n" } END { print "13. Read perlmod for the rest of the story.\n" } CHECK { print " 3. CHECK blocks run LIFO at compilation?s end.\n" } INIT { print " 6. Run this again, using Perl?s -c switch.\n" } print "10. This is anti-obfuscated code.\n"; END { print "12. END blocks run LIFO at quitting time.\n" } BEGIN { print " 2. So this line comes out second.\n" } INIT { print " 7. You?ll see the difference right away.\n" } print "11. It merely _looks_ like it should be confusing.\n" +;
Re: perl 5.16.3 + Tk 804.031 core dumps on syntax check when a window is made in BEGIN block
by eserte (Deacon) on Nov 07, 2013 at 13:20 UTC