# New Ticket Created by Tom Erdevig # Please include the string: [perl #53714] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=53714 >
Parrot segfaults running this: .sub _ :main null S0 loadlib P0, S0 .end Invoking loadlib with null library-name argument should set P0 to a ParrotLibrary pmc handle on the currently running program. This is useful for calling functions in the containing program from an embedded parrot. The segfault is caused by src/dynext.c:Parrot_load_lib setting its local lib_name variable to NULL and then passing it along to run_init_lib, and thence to store_lib_pmc, who tries to set the new library PMC's '_lib_name' property using this NULL, leading to the crash. The attached patch fixes this in Parrot_load_lib by setting lib_name to the empty string instead of NULL when there is no library name. I'm not sure if that's the best choice. The '_lib_name' library pmc property doesn't seem to be used for anything elsewhere in parrot (it gets copied if the library pmc gets cloned, but that's all). The empty string is innocuous but not very helpful if a human should happen to see it. So perhaps setting the _lib_name to something like "Not a library, this is the main program" would be better, but that feels like overkill. Change summary: src/dynext.c : one-line fix as described t/pmc/nci.t : add test that reproduces the problem and confirms fix Diffstat: CREDITS | 3 +++ src/dynext.c | 2 +- t/pmc/nci.t | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) Tom
Index: src/dynext.c =================================================================== --- src/dynext.c (revision 27323) +++ src/dynext.c (working copy) @@ -552,7 +552,7 @@ } else { wo_ext = string_from_literal(interp, ""); - lib_name = NULL; + lib_name = string_from_literal(interp, ""); ext = NULL; } Index: CREDITS =================================================================== --- CREDITS (revision 27323) +++ CREDITS (working copy) @@ -633,6 +633,9 @@ N: Tony Payne D: Example hanoi.pasm +N: Tom Erdevig +D: bugfix, test + N: Tom Hughes E: [EMAIL PROTECTED] Index: t/pmc/nci.t =================================================================== --- t/pmc/nci.t (revision 27323) +++ t/pmc/nci.t (working copy) @@ -6,7 +6,7 @@ use warnings; use lib qw( . lib ../lib ../../lib ); use Test::More; -use Parrot::Test tests => 65; +use Parrot::Test tests => 66; use Parrot::Config qw(%PConfig); =head1 NAME @@ -2645,6 +2645,20 @@ 3 OUTPUT +pir_output_is( << 'CODE', << 'OUTPUT', "dlfunc a function from main program" ); +.sub test :main + .local pmc main_program + .local string null_libname + loadlib main_program, null_libname + + .local pmc printf + printf = dlfunc main_program, 'printf', 'it' + printf( "printf this\n" ) +.end +CODE +printf this +OUTPUT + # Local Variables: # mode: cperl # cperl-indent-level: 4