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

perlcc: array becomes NULL if Visual Studio used for compilation #414

Open
rurban opened this issue Dec 30, 2017 · 1 comment
Open

perlcc: array becomes NULL if Visual Studio used for compilation #414

rurban opened this issue Dec 30, 2017 · 1 comment

Comments

@rurban
Copy link
Owner

rurban commented Dec 30, 2017

How to reproduce:

use Data::Dumper;
my $test;
$test = sub {
        my @arr;
        print Dumper \@arr;
        return defined $test;  # disables optimization?
};
$test->();

Compiled with perlcc --Wl="vcruntime.lib" test.pl.
Linux and Mingw-w64 versions of perlcc produce binary that prints $VAR1 = []; as interpreter does.
But if binary compiled with Visual Studio it prints $VAR1 = \undef; and causes null pointer exception on array operations.

@constantined
Copy link

constantined commented Jan 1, 2018

Maybe diff of Devel::Peek outputs will be helpful:

--- test-nobug.txt
+++ test-bug.txt
@@ -11,9 +11,10 @@
     GVGV::GV = <NUMBER>        "main" :: "__ANON__"
     FILE = "test.pl"
     DEPTH = 0
-    CVFLAGS = 0x1490 (ANON,WEAKOUTSIDE,CVGV_RC,DYNFILE)
+    CVFLAGS = 0x14c0 (ANON,CLONED,CVGV_RC,DYNFILE)
     OUTSIDE_SEQ = 119
     PADLIST = <NUMBER> [1]
     PADNAME = <NUMBER>(<NUMBER>) PAD = <NUMBER>(<NUMBER>)
        1. <NUMBER><1> (120,121) "@arr"
-    OUTSIDE = 0x3626a0 (MAIN)
+       2. 0x534720<2> FAKE "$test" flags=0x0 index=1
+    OUTSIDE = 0x0 (null)

nobug is the same code, but without the return defined $test; line.
Output of cperl -DXv test.pl:

Pad CV clone
  Proto: CV=0x282910 (ANON), OUTSIDE=0x2526f8 (MAIN)
    PADLIST = 0x296170
    PADNAME = 0x295270(0x296300) PAD = 0x290f80(0x2962b0)
         1. 0x0<0> (4294967248,4294967249) "@arr"
         2. 0x0<0> FAKE "$test" flags=0x0 index=1
  To: CV=0x252548 (ANON), OUTSIDE=0x0 (null)
    PADLIST = 0x244820
    PADNAME = 0x295270(0x296300) PAD = 0x252650(0x295f90)
         1. 0x2526b0<1> (4294967248,4294967249) "@arr"
         2. 0x282418<2> FAKE "$test" flags=0x0 index=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants