> In src/objects.c:Parrot_add_attribute() there is the todo item: > > /* TODO escape NUL char */ > > I think this applies to calling real_exception just afterwards.
According a discussion in #parrot this function and some related parts is dead code. The attached patch removes it. -- Salu2
Index: src/oo.c =================================================================== --- src/oo.c (revisión: 27376) +++ src/oo.c (copia de trabajo) @@ -768,116 +768,6 @@ /* -=item C<PMC * Parrot_single_subclass> - -Subclass a class. Single parent class, nice and straightforward. If -C<child_class> is C<NULL>, this is an anonymous subclass we're creating, -function. - -=cut - -*/ - -PARROT_API -PARROT_WARN_UNUSED_RESULT -PARROT_CANNOT_RETURN_NULL -PMC * -Parrot_single_subclass(PARROT_INTERP, ARGIN(PMC *base_class), ARGIN_NULLOK(PMC *name)) -{ - PMC *child_class, *parents, *temp_pmc, *mro; - SLOTTYPE *child_class_array; - int parent_is_class; - - /* Set the classname, if we have one */ - if (!PMC_IS_NULL(name)) { - fail_if_type_exists(interp, name); - } - else { - /* RT#45975 not really threadsafe but good enough for now */ - static int anon_count; - STRING * const child_class_name = - Parrot_sprintf_c(interp, "%c%canon_%d", 0, 0, ++anon_count); - name = pmc_new(interp, enum_class_String); - VTABLE_set_string_native(interp, name, child_class_name); - } - - /* ParrotClass is the baseclass anyway, so build just a new class */ - if (base_class == interp->vtables[enum_class_Class]->pmc_class) - return pmc_new_init(interp, enum_class_Class, name); - - parent_is_class = PObj_is_class_TEST(base_class); - child_class = pmc_new(interp, enum_class_Class); - - /* Hang an array off the data pointer */ - set_attrib_array_size(child_class, PCD_MAX); - child_class_array = PMC_data_typed(child_class, SLOTTYPE *); - set_attrib_flags(child_class); - - /* We will have five entries in this array */ - - /* We have the same number of attributes as our parent */ - CLASS_ATTRIB_COUNT(child_class) = parent_is_class ? - CLASS_ATTRIB_COUNT(base_class) : 0; - - /* Our parent class array has a single member in it */ - parents = pmc_new(interp, enum_class_ResizablePMCArray); - - VTABLE_set_integer_native(interp, parents, 1); - VTABLE_set_pmc_keyed_int(interp, parents, 0, base_class); - - set_attrib_num(child_class, child_class_array, PCD_PARENTS, parents); - set_attrib_num(child_class, child_class_array, PCD_CLASS_NAME, name); - - /* Our mro list is a clone of our parent's mro list, - * with our self unshifted onto the beginning */ - mro = VTABLE_clone(interp, base_class->vtable->mro); - VTABLE_unshift_pmc(interp, mro, child_class); - - /* But we have no attributes of our own. Yet */ - temp_pmc = pmc_new(interp, enum_class_ResizablePMCArray); - set_attrib_num(child_class, child_class_array, PCD_CLASS_ATTRIBUTES, - temp_pmc); - - parrot_class_register(interp, name, child_class, base_class, mro); - rebuild_attrib_stuff(interp, child_class); - - if (!parent_is_class) { - /* we append one attribute to hold the PMC */ - Parrot_add_attribute(interp, child_class, - CONST_STRING(interp, "__value")); - /* - * then create a vtable derived from ParrotObject and - * deleg_pmc - the ParrotObject vtable is already built - */ - create_deleg_pmc_vtable(interp, child_class, 1); - } - else { - /* - * if any parent isa PMC, then still individual vtables might - * be overridden in this subclass - */ - int i; - int any_pmc_parent = 0; - const int n = VTABLE_elements(interp, mro); - - /* 0 = this, 1 = parent (handled above), 2 = grandpa */ - for (i = 2; i < n; ++i) { - const PMC * const parent = VTABLE_get_pmc_keyed_int(interp, mro, i); - if (!PObj_is_class_TEST(parent)) { - any_pmc_parent = 1; - break; - } - } - if (any_pmc_parent) - create_deleg_pmc_vtable(interp, child_class, 0); - } - - return child_class; -} - - -/* - =item C<PMC * Parrot_class_lookup> Looks for the class named C<class_name> and returns it if it exists. @@ -1798,59 +1688,6 @@ } -/* - -=item C<INTVAL Parrot_add_attribute> - -Adds the attribute C<attr> to the class. - - Life is ever so much easier if a class keeps its attributes at the - end of the attribute array, since we don't have to insert and - reorder attributes. Inserting's no big deal, especially since we're - going to break horribly if you insert into a class that's been - subclassed, but it'll do for now. - -=cut - -*/ - -PARROT_API -INTVAL -Parrot_add_attribute(PARROT_INTERP, ARGIN(PMC *_class), ARGIN(STRING *attr)) -{ - STRING *full_attr_name; - SLOTTYPE * const class_array = (SLOTTYPE *)PMC_data(_class); - STRING * const class_name = VTABLE_get_string(interp, - get_attrib_num(class_array, PCD_CLASS_NAME)); - PMC * const attr_array = get_attrib_num(class_array, PCD_CLASS_ATTRIBUTES); - PMC * const attr_hash = get_attrib_num(class_array, PCD_ATTRIBUTES); - INTVAL idx = VTABLE_elements(interp, attr_array); - - VTABLE_set_integer_native(interp, attr_array, idx + 1); - VTABLE_set_string_keyed_int(interp, attr_array, idx, attr); - - full_attr_name = string_concat(interp, class_name, - string_from_cstring(interp, "\0", 1), 0); - - full_attr_name = string_concat(interp, full_attr_name, attr, 0); - - /* RT#45989 escape NUL char */ - if (VTABLE_exists_keyed_str(interp, attr_hash, full_attr_name)) - real_exception(interp, NULL, 1, - "Attribute '%Ss' already exists", full_attr_name); - - /* - * RT#45993 check if someone is trying to add attributes to a parent class - * while there are already child class attrs - */ - idx = CLASS_ATTRIB_COUNT(_class)++; - VTABLE_set_integer_keyed_str(interp, attr_hash, attr, idx); - VTABLE_set_integer_keyed_str(interp, attr_hash, full_attr_name, idx); - - return idx; -} - - /* ************************************************************************ */ /* ********* BELOW HERE IS NEW PPD15 IMPLEMENTATION RELATED STUFF ********* */ /* ************************************************************************ */ Index: src/ops/object.ops =================================================================== --- src/ops/object.ops (revisión: 27376) +++ src/ops/object.ops (copia de trabajo) @@ -469,12 +469,9 @@ inline op addattribute(invar PMC, in STR) :object_classes { STRING * const class_name = string_from_literal(interp, "Class"); - STRING * const pclass_name = string_from_literal(interp, "ParrotClass"); if (VTABLE_isa(interp, $1, class_name)) VTABLE_add_attribute(interp, $1, $2, PMCNULL); - else if (VTABLE_isa(interp, $1, pclass_name)) - Parrot_add_attribute(interp, $1, $2); else real_exception(interp, NULL, INVALID_OPERATION, "Cannot add attribute to non-class");