On Monday 05 May 2008 13:50:51 NotFound wrote:
> On Mon, May 5, 2008 at 2:52 AM, via RT Tom Erdevig
>
> <[EMAIL PROTECTED]> wrote:
> > Parrot segfaults running this:
> > .sub _ :main
> > null S0
> > loadlib P0, S0
> > .end
> > 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 tried another way. The segfault is at
> pmc/string.pmc:set_string_native. If I insert an assertion od
> non-nullness of the 'value' parameter of this function parrot does not
> build, then I suppose the function must accept a NULL value. All
> intermediate functions have also his corresponding parameter not
> declared as nonnull, so I assume that the NULL argument must be
> allowed.
>
> The failed line is:
>
> if (PObj_constant_TEST(SELF) && !PObj_constant_TEST(value)) {
>
> If I change it to:
>
> if (PObj_constant_TEST(SELF) && (value && !PObj_constant_TEST(value))) {
>
> The segfault disappear and all tests pass.
>
> The attached patch contains this change.
I prefer this patch. It fixes the problem closer to its source. Does it work
for you?
-- c
=== src/dynext.c
==================================================================
--- src/dynext.c (revision 27341)
+++ src/dynext.c (local)
@@ -140,8 +140,10 @@
/* remember path/file in props */
set_cstring_prop(interp, lib_pmc, "_filename", path); /* XXX */
set_cstring_prop(interp, lib_pmc, "_type", type);
- set_cstring_prop(interp, lib_pmc, "_lib_name", lib_name);
+ if (lib_name)
+ set_cstring_prop(interp, lib_pmc, "_lib_name", lib_name);
+
VTABLE_set_pmc_keyed_str(interp, dyn_libs, path, lib_pmc);
}