I'm trying to use libc to be able to do a directory listing, and and if I used the DATATYPE_CSTR I get a segfault, and if I use DATATYPE_STRING, I get a "returning unhandled string type in struct". I don't know if I'm doing the calls wrong or what since the documentation is vague in places. pdb crashes on launch, seg fault. I tried running parrot under gdb and gdb seg faulted. I'm not too familiar with gdb, though, but with the dump file I was able to get this.

Program received signal SIGSEGV, Segmentation fault.
0x283ce659 in strlen () from /lib/libc.so.5

Here's a backtrace...

#0  0x283ce659 in strlen () from /lib/libc.so.5
#1 0x081bda43 in ret_string (interpreter=0x827e000, p=0x84e0008 ".", type=-69)
    at unmanagedstruct.pmc:305
#2  0x081be35f in Parrot_UnManagedStruct_get_string_keyed (
    interpreter=0x827e000, pmc=0x84a2050, key=0x8476ee0)
    at unmanagedstruct.pmc:832
#3  0x080ee5f0 in Parrot_set_s_p_kc (cur_opcode=0x84c3e24,
    interpreter=0x827e000) at set.ops:511
#4  0x081549ac in runops_slow_core (interpreter=0x827e000, pc=0x84c3e24)
    at src/runops_cores.c:153
#5  0x081510d8 in runops_int (interpreter=0x827e000, offset=0)
    at src/interpreter.c:750
#6 0x081538c5 in runops (interpreter=0x827e000, offs=0) at src/inter_run.c:81
#7  0x080c0143 in Parrot_runcode (interpreter=0x827e000, argc=1,
    argv=0xbfbfec2c) at src/embed.c:869
#8  0x080bff9c in Parrot_runcode (interpreter=0x827e000, argc=1,
    argv=0xbfbfec2c) at src/embed.c:808
#9  0x0808308c in main (argc=1, argv=0xbfbfec2c) at imcc/main.c:647

Anyway, here's my pir file.

#!/opt/parrot/bin/parrot

.sub _main @MAIN
    .local pmc libc
    .local pmc opendir
    .local pmc readdir
    .local pmc closedir
    loadlib libc, "/usr/lib/libc.so"
    dlfunc opendir, libc, 'opendir', 'pt'
    dlfunc readdir, libc, 'readdir', 'pp'
    dlfunc closedir, libc, 'closedir', 'ip'
    store_global 'libc::opendir', opendir
    store_global 'libc::readdir', readdir
    store_global 'libc::closedir', closedir
    .local pmc curdir
    curdir = libc::opendir(".")
    .local OrderedHash entry
    entry = libc::readdir(curdir)

    .include "/opt/parrot/runtime/parrot/include/datatypes.pasm"
    new $P2, .OrderedHash
    set $P2["d_fileno"], .DATATYPE_INT
    push $P2, 0
    push $P2, 0
    set $P2["d_reclen"], .DATATYPE_SHORT
    push $P2, 0
    push $P2, 0
    set $P2["d_type"], .DATATYPE_CHAR
    push $P2, 0
    push $P2, 0
    set $P2["d_name"], .DATATYPE_CSTR
    #set $P2["d_name"], .DATATYPE_STRING
    push $P2, 0
    push $P2, 0
    assign entry, $P2

    $S0 = entry["d_name"]
    print $S0
.end

Reply via email to