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

Cardinal crashes on "require Test" #1

Closed
tadzik opened this issue Jan 4, 2011 · 3 comments
Closed

Cardinal crashes on "require Test" #1

tadzik opened this issue Jan 4, 2011 · 3 comments

Comments

@tadzik
Copy link

tadzik commented Jan 4, 2011

Turns out a lex_lookup may return something that triggers a NULL PMC Access when trying to check its value. Here's a piece of code I added to actions.pm

src/gen_diff --git a/src/parser/actions.pm b/src/parser/actions.pm
index cd49492..f706b95 100644
--- a/src/parser/actions.pm
+++ b/src/parser/actions.pm
@@ -905,6 +905,9 @@ sub is_a_sub($name) {
         }
     }
     my $lex := lex_lookup($name);
+    print("is_a_sub('"); print($name); print("'), here we crash\n");
+    if $lex { print("lex ok\n"); }
+    print("never happens\n");
     if $lex && ~lookup_class($lex) eq 'Sub' { return 1; }
     return 0;
 }

Running ./installable_cardinal t/02-functions.t results in:

is_a_sub('Test'), here we crash
Null PMC access in get_bool()
current instr.: 'cardinal;cardinal;Grammar;Actions;is_a_sub' pc 64437 (src/gen_grammar.pir:288)
called from Sub 'cardinal;cardinal;Grammar;Actions;variable' pc 68543 (src/gen_grammar.pir:1720)
called from Sub 'cardinal;cardinal;Grammar;variable' pc 34593 (src/classes/File.pir:8150)
called from Sub 'cardinal;cardinal;Grammar;basic_primary' pc 36938 (src/classes/FileStat.pir:9021)
called from Sub 'cardinal;cardinal;Grammar;primary' pc 37455 (src/classes/Dir.pir:9206)
called from Sub 'cardinal;PGE;OPTable;parse' pc 1940 (compilers/pge/PGE/OPTable.pir:566)
called from Sub 'cardinal;cardinal;Grammar;args' pc 35975 (src/classes/FileStat.pir:8665)
called from Sub 'cardinal;cardinal;Grammar;call_args' pc 29791 (src/classes/Kernel.pir:6346)
called from Sub 'cardinal;cardinal;Grammar;post_primary_expr' pc 37995 (src/classes/Dir.pir:9406)
called from Sub 'cardinal;cardinal;Grammar;primary' pc 37567 (src/classes/Dir.pir:9246)
called from Sub 'cardinal;PGE;OPTable;parse' pc 1940 (compilers/pge/PGE/OPTable.pir:566)
called from Sub 'cardinal;cardinal;Grammar;expr' pc 20368 (src/classes/Array.pir:2777)
called from Sub 'cardinal;cardinal;Grammar;basic_stmt' pc 17591 (src/classes/Array.pir:1717)
called from Sub 'cardinal;cardinal;Grammar;stmt' pc 18974 (src/classes/Array.pir:2227)
called from Sub 'cardinal;cardinal;Grammar;stmts' pc 14166 (src/classes/Array.pir:448)
called from Sub 'cardinal;cardinal;Grammar;comp_stmt' pc 13647 (src/classes/Array.pir:249)
called from Sub 'cardinal;cardinal;Grammar;TOP' pc 13302 (src/classes/Array.pir:115)
called from Sub 'cardinal;PCT;HLLCompiler;parse' pc 826 (compilers/pct/src/PCT/HLLCompiler.pir:463)
called from Sub 'cardinal;PCT;HLLCompiler;compile' pc 464 (compilers/pct/src/PCT/HLLCompiler.pir:331)
called from Sub 'cardinal;PCT;HLLCompiler;eval' pc 1081 (compilers/pct/src/PCT/HLLCompiler.pir:582)
called from Sub 'cardinal;PCT;HLLCompiler;evalfiles' pc 1501 (compilers/pct/src/PCT/HLLCompiler.pir:764)
called from Sub 'cardinal;PCT;HLLCompiler;command_line' pc 1712 (compilers/pct/src/PCT/HLLCompiler.pir:873)
called from Sub 'cardinal;cardinal;Compiler;main' pc 78706 (src/gen_grammar.pir:5354)

@bluescreen10
Copy link

the following patch works for me

diff --git a/src/parser/actions.pm b/src/parser/actions.pm
index cd49492..8102303 100644
--- a/src/parser/actions.pm
+++ b/src/parser/actions.pm
@@ -905,7 +905,7 @@ sub is_a_sub($name) {
         }
     }
     my $lex := lex_lookup($name);
-    if $lex && ~lookup_class($lex) eq 'Sub' { return 1; }
+    if defined($lex) && ~lookup_class($lex) eq 'Sub' { return 1; }
     return 0;
 }

@tadzik
Copy link
Author

tadzik commented Jan 5, 2011

Thanks bluescreen, it fixes the issue. Cardinal is now usable.

@gerd
Copy link

gerd commented Jan 5, 2011

I applied the patch from "bluescreen10". Thanks for the help!

This issue was closed.
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

3 participants