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

NullPointerException for same CStruct in CStruct #3713

Open
p6rt opened this issue Mar 3, 2015 · 11 comments
Open

NullPointerException for same CStruct in CStruct #3713

p6rt opened this issue Mar 3, 2015 · 11 comments
Labels
JVM Related to Rakudo-JVM

Comments

@p6rt
Copy link

p6rt commented Mar 3, 2015

Migrated from rt.perl.org#123969 (status was 'open')

Searchable as RT123969$

@p6rt
Copy link
Author

p6rt commented Mar 3, 2015

From @FROGGS

$ perl6-m -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has
Foo $.bar }'

$ perl6-j --ll-exception -e 'class Foo is repr<CStruct> { has int32
$.idontcare; has Foo $.bar }'
java.lang.NullPointerException
  in compose_repr (gen/jvm/Metamodel.nqp​:1440)
  in compose (gen/jvm/Metamodel.nqp​:2770)
  in pkg_compose (src/Perl6/World.nqp​:1938)
  in package_def (gen/jvm/Perl6-Actions.nqp​:1956)
  in !reduce (gen/jvm/stage2/QRegex.nqp​:1241)
  in !cursor_pass (gen/jvm/stage2/QRegex.nqp​:1202)
  in package_def (src/Perl6/Grammar.nqp​:2445)
  in package_declarator​:sym<class> (src/Perl6/Grammar.nqp)
  in !protoregex (gen/jvm/stage2/QRegex.nqp​:1278)
  in package_declarator (src/Perl6/Grammar.nqp)
  in term​:sym<package_declarator> (src/Perl6/Grammar.nqp)
  in !protoregex (gen/jvm/stage2/QRegex.nqp​:1278)
  in term (src/Perl6/Grammar.nqp)
  in termish (src/Perl6/Grammar.nqp​:3724)
  in EXPR (gen/jvm/stage2/NQPHLL.nqp​:558)
  in EXPR (src/Perl6/Grammar.nqp​:3755)
  in statement (src/Perl6/Grammar.nqp​:1338)
  in statementlist (src/Perl6/Grammar.nqp​:1270)
  in LANG (gen/jvm/stage2/NQPHLL.nqp​:771)
  in FOREIGN_LANG (src/Perl6/Grammar.nqp​:1681)
  in comp_unit (src/Perl6/Grammar.nqp​:1128)
  in TOP (src/Perl6/Grammar.nqp​:368)
  in parse (gen/jvm/stage2/QRegex.nqp​:1872)
  in parse (gen/jvm/stage2/NQPHLL.nqp​:1440)
  in compile (gen/jvm/stage2/NQPHLL.nqp​:1396)
  in eval (gen/jvm/stage2/NQPHLL.nqp​:1138)
  in (gen/jvm/stage2/NQPHLL.nqp​:1244)
  in command_eval (gen/jvm/stage2/NQPHLL.nqp​:1241)
  in command_eval (src/Perl6/Compiler.nqp​:17)
  in command_line (gen/jvm/stage2/NQPHLL.nqp​:1226)
  in MAIN (gen/jvm/main.nqp​:39)
  in <mainline> (gen/jvm/main.nqp​:35)
  in (gen/jvm/main.nqp)

@p6rt
Copy link
Author

p6rt commented Mar 13, 2015

From @usev6

The class definition no longer results in a NullPointerException​:

$ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; say "alive"'
alive

But it's not possible to create an object of class Foo (works on MoarVM)​:

$ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; my $a = Foo.new; say "alive"'
java.lang.NoClassDefFoundError​: L__CStruct__1;
  in method bless at gen/jvm/CORE.setting​:949
  in method new at gen/jvm/CORE.setting​:935
  in block <unit> at -e​:1

1 similar comment
@p6rt
Copy link
Author

p6rt commented Mar 13, 2015

From @usev6

The class definition no longer results in a NullPointerException​:

$ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; say "alive"'
alive

But it's not possible to create an object of class Foo (works on MoarVM)​:

$ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; my $a = Foo.new; say "alive"'
java.lang.NoClassDefFoundError​: L__CStruct__1;
  in method bless at gen/jvm/CORE.setting​:949
  in method new at gen/jvm/CORE.setting​:935
  in block <unit> at -e​:1

@p6rt
Copy link
Author

p6rt commented Mar 13, 2015

@usev6 - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jun 29, 2015

From @usev6

At first sight this looks good now​:

$ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; my $a = Foo.new; say "alive"'
alive

Unfortunatly, another NullPointerException surfaces when looking at the newly created $a​:

$ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; my $a = Foo.new; say $a.bar'
java.lang.NullPointerException
  in block <unit> at -e​:1

Compare with rakudo.moar​:

$ perl6-m -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; my $a = Foo.new; say $a.bar'
(Foo)

1 similar comment
@p6rt
Copy link
Author

p6rt commented Jun 29, 2015

From @usev6

At first sight this looks good now​:

$ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; my $a = Foo.new; say "alive"'
alive

Unfortunatly, another NullPointerException surfaces when looking at the newly created $a​:

$ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; my $a = Foo.new; say $a.bar'
java.lang.NullPointerException
  in block <unit> at -e​:1

Compare with rakudo.moar​:

$ perl6-m -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; my $a = Foo.new; say $a.bar'
(Foo)

@p6rt
Copy link
Author

p6rt commented Jun 30, 2015

From @usev6

On Mon Jun 29 14​:21​:31 2015, bartolin@​gmx.de wrote​:

Unfortunatly, another NullPointerException surfaces when looking at
the newly created $a​:

$ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has
Foo $.bar }; my $a = Foo.new; say $a.bar'
java.lang.NullPointerException
in block <unit> at -e​:1

I tried to look at this NPE, but was unable to find a fix. However, here is what I suspect -- maybe it is useful for someone else​:

I think the NPE happens in
nqp/src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/CStructInstance.java​:95 (within public SixModelObject get_attribute_boxed) with the following code​:

  o = (Object)Structure.newInstance(structClass, ((Pointer)o));

Four lines above 'o' is created with

  Object o = storage.readField(name);

but 'storage.readField(name)' seems to be 'null'. Maybe this is not filled properly when the Perl 6 object is created?

1 similar comment
@p6rt
Copy link
Author

p6rt commented Jun 30, 2015

From @usev6

On Mon Jun 29 14​:21​:31 2015, bartolin@​gmx.de wrote​:

Unfortunatly, another NullPointerException surfaces when looking at
the newly created $a​:

$ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has
Foo $.bar }; my $a = Foo.new; say $a.bar'
java.lang.NullPointerException
in block <unit> at -e​:1

I tried to look at this NPE, but was unable to find a fix. However, here is what I suspect -- maybe it is useful for someone else​:

I think the NPE happens in
nqp/src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/CStructInstance.java​:95 (within public SixModelObject get_attribute_boxed) with the following code​:

  o = (Object)Structure.newInstance(structClass, ((Pointer)o));

Four lines above 'o' is created with

  Object o = storage.readField(name);

but 'storage.readField(name)' seems to be 'null'. Maybe this is not filled properly when the Perl 6 object is created?

@p6rt
Copy link
Author

p6rt commented Oct 30, 2015

From @coke

On Tue Jun 30 13​:41​:37 2015, bartolin@​gmx.de wrote​:

On Mon Jun 29 14​:21​:31 2015, bartolin@​gmx.de wrote​:

Unfortunatly, another NullPointerException surfaces when looking at
the newly created $a​:

$ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has
Foo $.bar }; my $a = Foo.new; say $a.bar'
java.lang.NullPointerException
in block <unit> at -e​:1

I tried to look at this NPE, but was unable to find a fix. However,
here is what I suspect -- maybe it is useful for someone else​:

I think the NPE happens in
nqp/src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/CStructInstance.java​:95
(within public SixModelObject get_attribute_boxed) with the following
code​:

o = (Object)Structure.newInstance(structClass, ((Pointer)o));

Four lines above 'o' is created with

Object o = storage.readField(name);

but 'storage.readField(name)' seems to be 'null'. Maybe this is not
filled properly when the Perl 6 object is created?

This appears to be working now; closable with tests​:

09​:57 < [Coke]> r​: class Foo is repr<CStruct> { has int32 $.idontcare; has Foo
  $.bar }; my $a = Foo.new; say 42;
09​:57 <+camelia> rakudo-{moar,jvm} ba7027​: OUTPUT«42␤»

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Oct 30, 2015

From @usev6

Hmm, actually the second NPE is still there​:

$ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; my $a = Foo.new; say $a.bar'
java.lang.NullPointerException
  in block <unit> at -e​:1

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 30, 2015

From @usev6

Hmm, actually the second NPE is still there​:

$ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; my $a = Foo.new; say $a.bar'
java.lang.NullPointerException
  in block <unit> at -e​:1

@p6rt p6rt added the JVM Related to Rakudo-JVM label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JVM Related to Rakudo-JVM
Projects
None yet
Development

No branches or pull requests

1 participant