On Tuesday 20 May 2008 07:07:53 Patrick R.Michaud wrote:

> Here's the lower method itself:
>
>     METHOD lower() {
>         STRING * const s   = string_downcase(INTERP,
>             VTABLE_get_string(INTERP, SELF));
>         PMC * const    ret = pmc_new_noinit(INTERP,
> SELF->vtable->base_type); PMC_str_val(ret)   = s;
>
>         PObj_custom_mark_SET(ret);
>
>         RETURN(PMC *ret);
>     }
>
> I'm guessing the problem is the C< PMC_str_val(ret) > assignment,
> where C<ret> is being generated with the same type as the invocant.
> If the invocant is a String, great, but if it's a subclass of String
> then we have a problem.

Actually, it's the pmc_new_noinit() call which is the problem.  This method in 
this case needs to return an Object, which has PMC data.  Unfortunately, 
calling pmc_new_noinit() does *not* call any PMC initializer, which in this 
case allocates and assigns the PMC data to the object.

Without that data pointer, any other vtable entry or method which tries to 
access PMC data will dereference a null pointer.

> However, since our calling conventions now handle autoboxing,
> perhaps an even better solution would be to skip creating a
> return value PMC at all, but let the autoboxer handle it:
>
>     METHOD lower() {
>         STRING * const s   = string_downcase(INTERP,
>             VTABLE_get_string(INTERP, SELF));
>         RETURN(STRING *s);
>     }

This fixes the segfault.  I'm running coretest now to see what happens.

-- c

Reply via email to