SOLVED -- see below
Here is the Perl code in question:
# basic init
my $myhtml = myhtml_create();
myhtml_init($myhtml, 0, 1, 0);
# init tree
my $tree = myhtml_tree_create();
myhtml_tree_init($tree, $myhtml);
# parse html
myhtml_parse_fragment($tree, 0, $html.encode, $html.encode.bytes, 0x02a, 0x01);
# get first DIV from index
my $tag-idx = myhtml_tree_get_tag_index($tree);
my $idx-node = myhtml_tag_index_first($tag-idx, 0x02a);
my $node = myhtml_tag_index_tree_node($idx-node);
# print original tree
say "Original tree:";
# XXX -- Crashes here --- XXX
myhtml_tree_print_node_childs(
$tree,
myhtml_tree_get_document($tree),
FILE.fd(1),
0
);
And here is the backtrace:
Program received signal SIGSEGV, Segmentation fault.
_IO_new_fdopen (fd=1, mode=0x0) at iofdopen.c:65
65 iofdopen.c: No such file or directory.
(gdb) bt full
#0 _IO_new_fdopen (fd=1, mode=0x0) at iofdopen.c:65
read_write = <optimized out>
new_f = <optimized out>
i = <optimized out>
use_mmap = 0
do_seek = false
fd_flags = <optimized out>
#1 0xb7db50e3 in dcCall_x86_cdecl ()
from /home/cbwood/.rakudobrew/moar-nom/install/lib/libmoar.so
No symbol table info available.
#2 0xb7db4a8a in dc_callvm_call_x86_cdecl ()
from /home/cbwood/.rakudobrew/moar-nom/install/lib/libmoar.so
No symbol table info available.
#3 0xb7db474a in dcCallPointer ()
from /home/cbwood/.rakudobrew/moar-nom/install/lib/libmoar.so
No symbol table info available.
#4 0xb7d0cd2e in MVM_nativecall_invoke ()
from /home/cbwood/.rakudobrew/moar-nom/install/lib/libmoar.so
No symbol table info available.
#5 0xb7cef598 in MVM_interp_run ()
from /home/cbwood/.rakudobrew/moar-nom/install/lib/libmoar.so
No symbol table info available.
#6 0xb7db1b2d in MVM_vm_run_file ()
from /home/cbwood/.rakudobrew/moar-nom/install/lib/libmoar.so
No symbol table info available.
#7 0x08048c53 in main ()
No symbol table info available.
The obvious culprit looks to be in frame #0 (mode=0x0), but that is odd because the Perl6 code is clearly passing a value:
from Raw.pm6
class FILE is repr<CPointer> is export {
sub fdopen(int64, Str) returns FILE is native { * }
sub fopen(Str, Str) returns FILE is native { * }
sub setvbuf(FILE, Blob, size_t) returns int64 is native { * }
method fd(Int $fd) {
my $fh = fdopen($fd, "w+");
setvbuf($fh, Blob, 2) if $fd == 1;
return $fh;
}
method path(Str $path) { fopen($path, "w+") }
}
So how did the "w+" on line 68 get passed as NULL?
In some cases FILE.fd(1) may not be available, so you have to go directly to /dev/stdout. I didn't need to do this on my Ubuntu 16.04 host, as it worked without modification. However on my Debian VM (Windows Host), this was fixed by the following:
# USED to crash, here
myhtml_tree_print_node_childs(
$tree,
myhtml_tree_get_document($tree),
FILE.path('/dev/stdout'),
0
);
MadcapJake++ for the solution.