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

I can't HAS stub? #2965

Closed
kazcw opened this issue Jun 7, 2019 · 4 comments
Closed

I can't HAS stub? #2965

kazcw opened this issue Jun 7, 2019 · 4 comments

Comments

@kazcw
Copy link
Contributor

kazcw commented Jun 7, 2019

use NativeCall;
class MyStub is repr(CStruct) { ... }
class SpecialDelivery:«💣» is repr(CStruct) {
    HAS MyStub $.stubby;
}

Segmentation fault

@kazcw
Copy link
Contributor Author

kazcw commented Jun 7, 2019

I could understand the compiler not being happy with what I was trying to do 🐟, but segfaulting seems a bit much

@kazcw
Copy link
Contributor Author

kazcw commented Jun 7, 2019

This is probably for the same reason:

use NativeCall;
class Oops is repr(CStruct) { HAS Oops $.more; }

Segmentation fault

@MasterDuke17
Copy link
Contributor

dan@hermes:~/p6$ pg6 -e 'use NativeCall;
> 
> class Oops is repr(「CStruct」) { HAS Oops $.more; }'
================================================================================================
This is Rakudo Perl 6 running in the  debugger, which often allows the user to generate useful back-
traces to debug or report issues in Rakudo, the MoarVM backend or the currently running code.

This Rakudo version is 2019.03.1.574.gee.2.f.2.d.2.df built on MoarVM version 2019.05.36.ge.865.f.43.df,
running on ubuntu (19.04.Disco.Dingo) / linux (17.Ubuntu.SMP.Wed.May.15.10.52.21.UTC.2019)

Type `bt full` to generate a backtrace if applicable, type `q` to quit or `help` for help.
------------------------------------------------------------------------------------------------
Reading symbols from /home/dan/Source/perl6/install/bin/perl6-m...
Starting program: /home/dan/Source/perl6/install/bin/perl6-m -e use\ NativeCall\;'
''
'class\ Oops\ is\ repr\(「CStruct」\)\ \{\ HAS\ Oops\ \$.more\;\ \}
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff6ff6700 (LWP 21302)]

Thread 1 "perl6-m" received signal SIGSEGV, Segmentation fault.
compute_allocation_strategy (st=<optimized out>, repr_data=<optimized out>, repr_info=<optimized out>, tc=0x55555555ae90) at src/6model/reprs/CStruct.c:263
263                             bits                                      = cppstruct_repr_data->struct_size * 8;
(gdb) bt
#0  compute_allocation_strategy (st=<optimized out>, repr_data=<optimized out>, repr_info=<optimized out>, tc=0x55555555ae90) at src/6model/reprs/CStruct.c:263
#1  compose (tc=0x55555555ae90, st=0x7fffefad87f0, repr_info=<optimized out>) at src/6model/reprs/CStruct.c:382
#2  0x00007ffff798af0d in MVM_interp_run (tc=tc@entry=0x55555555ae90, initial_invoke=0x0, invoke_data=0x2) at src/core/interp.c:2527
#3  0x00007ffff7a88895 in MVM_vm_run_file (instance=0x55555555a430, filename=<optimized out>) at src/moar.c:444
#4  0x0000555555555698 in main (argc=<optimized out>, argv=0x7fffffffde98) at src/vm/moar/runner/main.c:363
(gdb) call MVM_dump_backtrace(tc)
   at gen/moar/Metamodel.nqp:1674  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/Metamodel.moarvm:compose_repr)
 from gen/moar/Metamodel.nqp:3431  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/Metamodel.moarvm:compose)
 from src/Perl6/World.nqp:3289  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/World.moarvm:)
 from src/Perl6/World.nqp:5350  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/World.moarvm:)
 from src/Perl6/World.nqp:5346  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/World.moarvm:ex-handle)
 from src/Perl6/World.nqp:3288  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/World.moarvm:pkg_compose)
 from gen/moar/Perl6-Actions.nqp:3239  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/Actions.moarvm:package_def)
 from gen/moar/stage2/QRegex.nqp:1598  (/home/dan/Source/perl6/install/share/nqp/lib/QRegex.moarvm:!cursor_pass)
 from gen/moar/Perl6-Grammar.nqp:2174  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/Grammar.moarvm:package_def)
 from <unknown>:1  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/Grammar.moarvm:package_declarator:sym<class>)
 from gen/moar/stage2/QRegex.nqp:1697  (/home/dan/Source/perl6/install/share/nqp/lib/QRegex.moarvm:!protoregex)
 from <unknown>:1  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/Grammar.moarvm:package_declarator)
 from <unknown>:1  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/Grammar.moarvm:term:sym<package_declarator>)
 from gen/moar/stage2/QRegex.nqp:1697  (/home/dan/Source/perl6/install/share/nqp/lib/QRegex.moarvm:!protoregex)
 from <unknown>:1  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/Grammar.moarvm:term)
 from gen/moar/Perl6-Grammar.nqp:3639  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/Grammar.moarvm:termish)
 from gen/moar/stage2/NQPHLL.nqp:1056  (/home/dan/Source/perl6/install/share/nqp/lib/NQPHLL.moarvm:EXPR)
 from gen/moar/Perl6-Grammar.nqp:3675  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/Grammar.moarvm:EXPR)
 from gen/moar/Perl6-Grammar.nqp:956  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/Grammar.moarvm:statement)
 from gen/moar/Perl6-Grammar.nqp:884  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/Grammar.moarvm:statementlist)
 from gen/moar/stage2/NQPHLL.nqp:1278  (/home/dan/Source/perl6/install/share/nqp/lib/NQPHLL.moarvm:LANG)
 from gen/moar/Perl6-Grammar.nqp:1320  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/Grammar.moarvm:FOREIGN_LANG)
 from gen/moar/Perl6-Grammar.nqp:826  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/Grammar.moarvm:comp_unit)
 from gen/moar/Perl6-Grammar.nqp:555  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/Grammar.moarvm:TOP)
 from gen/moar/stage2/QRegex.nqp:2302  (/home/dan/Source/perl6/install/share/nqp/lib/QRegex.moarvm:parse)
 from gen/moar/stage2/NQPHLL.nqp:2099  (/home/dan/Source/perl6/install/share/nqp/lib/NQPHLL.moarvm:parse)
 from gen/moar/stage2/NQPHLL.nqp:2019  (/home/dan/Source/perl6/install/share/nqp/lib/NQPHLL.moarvm:execute_stage)
 from gen/moar/stage2/NQPHLL.nqp:2052  (/home/dan/Source/perl6/install/share/nqp/lib/NQPHLL.moarvm:run)
 from gen/moar/stage2/NQPHLL.nqp:2044  (/home/dan/Source/perl6/install/share/nqp/lib/NQPHLL.moarvm:)
 from gen/moar/stage2/NQPHLL.nqp:2039  (/home/dan/Source/perl6/install/share/nqp/lib/NQPHLL.moarvm:compile)
 from gen/moar/stage2/NQPHLL.nqp:1729  (/home/dan/Source/perl6/install/share/nqp/lib/NQPHLL.moarvm:eval)
 from gen/moar/stage2/NQPHLL.nqp:1862  (/home/dan/Source/perl6/install/share/nqp/lib/NQPHLL.moarvm:)
 from gen/moar/stage2/NQPHLL.nqp:1861  (/home/dan/Source/perl6/install/share/nqp/lib/NQPHLL.moarvm:command_eval)
 from src/Perl6/Compiler.nqp:52  (/home/dan/Source/perl6/install/share/perl6/lib/Perl6/Compiler.moarvm:command_eval)
 from gen/moar/stage2/NQPHLL.nqp:1842  (/home/dan/Source/perl6/install/share/nqp/lib/NQPHLL.moarvm:command_line)
 from gen/moar/main.nqp:82  (/home/dan/Source/perl6/install/share/perl6/runtime/perl6.moarvm:MAIN)
 from gen/moar/main.nqp:47  (/home/dan/Source/perl6/install/share/perl6/runtime/perl6.moarvm:<mainline>)
 from <unknown>:1  (/home/dan/Source/perl6/install/share/perl6/runtime/perl6.moarvm:<main>)
 from <unknown>:1  (/home/dan/Source/perl6/install/share/perl6/runtime/perl6.moarvm:<entry>)
(gdb)
================================================================================================
This is Rakudo Perl 6 running in valgrind, a tool for debugging and profiling programs.
Running a program in valgrind usually takes *a lot* more time than running it directly,
so please be patient.
Valgrind options can be added with MVM_VALGRIND_OPTS environment variable.

This Rakudo version is 2019.03.1.574.gee.2.f.2.d.2.df built on MoarVM version 2019.05.36.ge.865.f.43.df,
running on ubuntu (19.04.Disco.Dingo) / linux (17.Ubuntu.SMP.Wed.May.15.10.52.21.UTC.2019)
------------------------------------------------------------------------------------------------
==21403== Memcheck, a memory error detector
==21403== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==21403== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==21403== Command: /home/dan/Source/perl6/install/bin/perl6-m -e use\ NativeCall;\ class\ Oops\ is\ repr(___CStruct___)\ {\ HAS\ Oops\ $.more;\ }
==21403== 
==21403== Invalid read of size 4
==21403==    at 0x4AA047F: compute_allocation_strategy (CStruct.c:263)
==21403==    by 0x4AA047F: compose (CStruct.c:382)
==21403==    by 0x4A2CF0C: MVM_interp_run (interp.c:2527)
==21403==    by 0x4B2A894: MVM_vm_run_file (moar.c:444)
==21403==    by 0x109697: main (main.c:363)
==21403==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==21403== 
==21403== 
==21403== Process terminating with default action of signal 11 (SIGSEGV)
==21403==  Access not within mapped region at address 0x0
==21403==    at 0x4AA047F: compute_allocation_strategy (CStruct.c:263)
==21403==    by 0x4AA047F: compose (CStruct.c:382)
==21403==    by 0x4A2CF0C: MVM_interp_run (interp.c:2527)
==21403==    by 0x4B2A894: MVM_vm_run_file (moar.c:444)
==21403==    by 0x109697: main (main.c:363)
==21403==  If you believe this happened as a result of a stack
==21403==  overflow in your program's main thread (unlikely but
==21403==  possible), you can try to increase the size of the
==21403==  main thread stack using the --main-stacksize= flag.
==21403==  The main thread stack size used in this run was 8388608.
==21403== 
==21403== HEAP SUMMARY:
==21403==     in use at exit: 71,027,333 bytes in 232,926 blocks
==21403==   total heap usage: 343,326 allocs, 110,400 frees, 163,248,863 bytes allocated
==21403== 
==21403== LEAK SUMMARY:
==21403==    definitely lost: 96 bytes in 2 blocks
==21403==    indirectly lost: 88 bytes in 5 blocks
==21403==      possibly lost: 237,032 bytes in 4,232 blocks
==21403==    still reachable: 70,790,117 bytes in 228,687 blocks
==21403==         suppressed: 0 bytes in 0 blocks
==21403== Rerun with --leak-check=full to see details of leaked memory
==21403== 
==21403== For counts of detected and suppressed errors, rerun with: -v
==21403== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

kazcw added a commit to kazcw/MoarVM that referenced this issue Jun 8, 2019
You can't HAS a type before it's defined
@kazcw
Copy link
Contributor Author

kazcw commented Jun 8, 2019

Is there documentation on the runtime way to define a class? The MOP page is pretty light. I'm trying to write a test case, but "passing" means throwing an exception when the type is composed (rather than segfaulting), so I need to do the equivalent of this:

class OopsUnion is repr(「CUnion」) { HAS OopsUnion $.more; }
class OopsStruct is repr(「CStruct」) { HAS OopsStruct $.more; }
class OopsPPStruct is repr(「CPPStruct」) { HAS OopsPPStruct $.more; }

but at runtime so I can catch the exception...

kazcw added a commit to kazcw/rakudo that referenced this issue Jun 8, 2019
This will segfault until it's built on MoarVM/MoarVM#1116
kazcw added a commit to kazcw/rakudo that referenced this issue Jun 8, 2019
This will segfault until it's built on MoarVM/MoarVM#1116
jnthn added a commit to MoarVM/MoarVM that referenced this issue Jun 9, 2019
kazcw added a commit to kazcw/rakudo that referenced this issue Jun 9, 2019
This will segfault until it's built on MoarVM/MoarVM#1116
ugexe pushed a commit that referenced this issue Jun 9, 2019
This will segfault until it's built on MoarVM/MoarVM#1116
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