# New Ticket Created by "Alek Storm" # Please include the string: [perl #42406] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=42406 >
This patch fixes the bug in which the "init" vtable method override is called instead of "init_pmc" when init=NULL is passed to Parrot_instantiate_object_init, instead of init=PMCNULL. The choice of which method to call rested on an C<if(init)> statement, which can incorrectly return true if init == PMCNULL. -- Alek Storm
Index: src/objects.c =================================================================== --- src/objects.c (revision 18044) +++ src/objects.c (working copy) @@ -763,7 +763,7 @@ static void -do_initcall(Interp *interp, PMC* class, PMC *object, PMC *init) +do_initcall(Interp *interp, PMC* class, PMC *object, PMC *init, int init_param) { PMC * const classsearch_array = class->vtable->mro; PMC *parent_class; @@ -780,7 +780,7 @@ int default_meth; if (meth) { - if (init) + if (init_param) Parrot_run_meth_fromc_args(interp, meth, object, meth_str, "vP", init); else @@ -829,7 +829,7 @@ STRING *meth_str_v; /* use __init or __init_pmc (depending on if an argument was passed) * as fallback constructor method, if it exists */ - if (init) { + if (init_param) { meth_str = CONST_STRING(interp, "__init_pmc"); meth_str_v = CONST_STRING(interp, "init_pmc"); } @@ -850,7 +850,7 @@ else default_meth = 0; if (meth) { - if (init) + if (init_param) Parrot_run_meth_fromc_args(interp, meth, object, meth_str, "vP", init); else @@ -868,7 +868,7 @@ /* =item C<void -Parrot_instantiate_object(Interp *interp, PMC *object, PMC *init)> +Parrot_instantiate_object(Interp *interp, PMC *object, PMC *init, int init_param)> Creates a Parrot object. Takes a passed-in class PMC that has sufficient information to describe the layout of the object and, well, makes the @@ -878,23 +878,23 @@ */ -static void instantiate_object(Interp*, PMC *object, PMC *init); +static void instantiate_object(Interp*, PMC *object, PMC *init, int init_param); void Parrot_instantiate_object_init(Interp *interp, PMC *object, PMC *init) { - instantiate_object(interp, object, init); + instantiate_object(interp, object, init, 1); } void Parrot_instantiate_object(Interp *interp, PMC *object) { - instantiate_object(interp, object, NULL); + instantiate_object(interp, object, PMCNULL, 0); } static void -instantiate_object(Interp *interp, PMC *object, PMC *init) +instantiate_object(Interp *interp, PMC *object, PMC *init, int init_param) { SLOTTYPE *new_object_array; INTVAL attrib_count, i; @@ -928,7 +928,7 @@ /* We really ought to call the class init routines here... * this assumes that an object isa delegate */ - do_initcall(interp, class, object, init); + do_initcall(interp, class, object, init, init_param); } /*