I spent more time tracking down the segfaults in Tcl (specifically the one with an invalid string passed to string_equals()). The problem appears to be in thawing bytecode, specifically in the ParrotInterpreter PMC and its thawfinish().
The code there attempts to reconstruct specific bytecode elements which represent .HLL directives -- what's the particular namespace, which op and PMC libraries to load if any, and which dynpmc types map to builtins. When IMCC encounters these directives, it calls functions in src/hll.c, which fill in a PMC-based data structure which hangs off of interpreter->HLL_info. This is a constant array full of constant PMCs. (They're constant so that the garbage collector won't eat them.) IMCC knows nothing about PBC though, so reconstructing a program from its PBC doesn't go through IMCC. That's fine... except that the thawfinish() I mentioned doesn't use the functions in src/hll.c. Worse, the thaw replaces the top-level constant array PMC stuck in interpreter->HLL_info. (It's constant, so it will hang out in memory. Yay for leaks.) After tracing back from the segfault and annotating the source a little while, I see some really weird garbage in the array, and only after thawing PBC with .HLL directives. Here's a patch which cleans up the issue somewhat, but doesn't fix up the typemaps. I wonder if adding logic to iterate through any typemap PMC and register types for the appropriate HLL id would fix everything else. Certainly this breaks PBCs spectacularly, but I think it's closer to correct. Is anyone sufficiently more familiar with the thawing code willing to look at the code? -- c
=== src/pmc/parrotinterpreter.pmc ================================================================== --- src/pmc/parrotinterpreter.pmc (revision 5223) +++ src/pmc/parrotinterpreter.pmc (local) @@ -605,50 +605,48 @@ } void thawfinish(visit_info *info) { - INTVAL i, n, m; - PMC *hll_info, *entry, *lib_pmc, *new_info, *ns_hash; - STRING *lib_name, *hll_name; + PMC *hll_info = INTERP->HLL_info; + PMC *new_info = PMC_pmc_val(SELF); + INTVAL n = VTABLE_elements(INTERP, hll_info); + INTVAL m = VTABLE_elements(INTERP, new_info); - hll_info = INTERP->HLL_info; - n = VTABLE_elements(INTERP, hll_info); - new_info = PMC_pmc_val(SELF); + INTVAL i; + PMC_pmc_val(SELF) = NULL; - m = VTABLE_elements(INTERP, new_info); /* merge new_info */ /* TODO compare old entries */ + for (i = n; i < m; ++i) { - entry = VTABLE_get_pmc_keyed_int(INTERP, new_info, i); - lib_pmc = VTABLE_get_pmc_keyed_int(INTERP, entry, 1); + PMC *entry = VTABLE_get_pmc_keyed_int(INTERP, new_info, i); + PMC *lib_pmc = VTABLE_get_pmc_keyed_int(INTERP, entry, e_HLL_lib); + PMC *name_pmc = VTABLE_get_pmc_keyed_int(INTERP, entry, e_HLL_name); + + STRING *lib_name = NULL; + STRING *hll_name = NULL; + if (!PMC_IS_NULL(lib_pmc)) { lib_name = VTABLE_get_string(INTERP, lib_pmc); - if (lib_name->strlen) - Parrot_load_lib(INTERP, lib_name, NULL); + PObj_constant_SET(lib_name); } - entry = VTABLE_get_pmc_keyed_int(INTERP, entry, 0); - if (!PMC_IS_NULL(entry)) { + + if (!PMC_IS_NULL(name_pmc)) { hll_name = VTABLE_get_string(INTERP, entry); - /* create HLL namespace */ - hll_name = string_downcase(INTERP, hll_name); + PObj_constant_SET(hll_name); + } - /* HLL type mappings aren't yet created, we can't create - * a namespace in HLL's flavor yet - maybe promote the - * ns_hash to another type later, if mappings provide one? - * XXX - FIXME - */ - ns_hash = - Parrot_make_namespace_keyed_str(interp, - interp->root_namespace, - hll_name); + if (hll_name || lib_name) { + INTVAL id = Parrot_register_HLL(INTERP, hll_name, lib_name); + PMC *typemap = + VTABLE_get_pmc_keyed_int(INTERP, entry, e_HLL_typemap); + PMC *hll_info = + VTABLE_get_pmc_keyed_int(INTERP, INTERP->HLL_info, id); - /* cache HLLs toplevel namespace */ - VTABLE_set_pmc_keyed_int(INTERP, - INTERP->HLL_namespace, i, ns_hash); + fprintf( stderr, "Storing typemap for HLL %d\n", id ); + dod_register_pmc(INTERP, typemap); + VTABLE_set_pmc_keyed_int(INTERP, hll_info, e_HLL_typemap, + typemap); } } - - /* TODO destruct old HLL_info are constants */ - if (m > n) - INTERP->HLL_info = new_info; } METHOD void run_gc() {