Ticket #895: TT_895_1.patch

File TT_895_1.patch, 12.9 KB (added by NotFound, 12 years ago)
  • src/gc/api.c

     
    373373    if (PObj_active_destroy_TEST(pmc)) 
    374374        VTABLE_destroy(interp, pmc); 
    375375 
     376    if (PMC_data(pmc) && pmc->vtable->attr_size) { 
     377        mem_sys_free(PMC_data(pmc)); 
     378        PMC_data(pmc) = NULL; 
     379    } 
     380    PARROT_ASSERT(NULL == PMC_data(pmc)); 
     381 
    376382    if (PObj_is_PMC_EXT_TEST(pmc)) 
    377383        Parrot_gc_free_pmc_ext(interp, pmc); 
    378384 
  • src/pmc.c

     
    240240 
    241241    /* Set the right vtable */ 
    242242    pmc->vtable = new_vtable; 
     243    if (PMC_data(pmc) && pmc->vtable->attr_size) 
     244       mem_sys_free(PMC_data(pmc)); 
     245    if (new_vtable->attr_size) 
     246        PMC_data(pmc) = mem_sys_allocate_zeroed(new_vtable->attr_size); 
     247    else 
     248        PMC_data(pmc) = NULL; 
    243249 
    244250    return pmc; 
    245251} 
     
    361367    /* Do we have an extension area? */ 
    362368    INTVAL const has_ext = (PObj_is_PMC_EXT_TEST(pmc) && pmc->pmc_ext); 
    363369 
     370    if (PMC_data(pmc) && pmc->vtable->attr_size) 
     371        mem_sys_free(PMC_data(pmc)); 
     372 
    364373    /* Do we need one? */ 
    365374    if (flags & VTABLE_PMC_NEEDS_EXT) { 
    366375        /* If we need an ext area, go allocate one */ 
     
    465474    pmc            = Parrot_gc_new_pmc_header(interp, flags); 
    466475    pmc->vtable    = vtable; 
    467476 
     477    if (vtable->attr_size) { 
     478        PMC_data(pmc) = mem_sys_allocate_zeroed(vtable->attr_size); 
     479    } 
     480 
    468481#if GC_VERBOSE 
    469482    if (Interp_flags_TEST(interp, PARROT_TRACE_FLAG)) { 
    470483        /* XXX make a more verbose trace flag */ 
  • src/pmc/complex.pmc

     
    217217} 
    218218 
    219219 
    220 pmclass Complex need_ext { 
     220pmclass Complex need_ext auto_attrs { 
    221221 
    222222    ATTR FLOATVAL re; /* real part */ 
    223223    ATTR FLOATVAL im; /* imaginary part */ 
     
    340340*/ 
    341341 
    342342    VTABLE void init() { 
    343         /* XXX should check if mem_sys_allocate failed */ 
    344         PMC_data(SELF) = mem_allocate_typed(Parrot_Complex_attributes); 
    345343        SET_ATTR_re(INTERP, SELF, 0.0); 
    346344        SET_ATTR_im(INTERP, SELF, 0.0); 
    347345 
  • src/pmc/resizablepmcarray.pmc

     
    2323#define PMC_array(x)     ((Parrot_ResizablePMCArray_attributes *)PMC_data(x))->pmc_array 
    2424#define PMC_threshold(x) ((Parrot_ResizablePMCArray_attributes *)PMC_data(x))->resize_threshold 
    2525 
    26 pmclass ResizablePMCArray extends FixedPMCArray need_ext provides array { 
     26pmclass ResizablePMCArray extends FixedPMCArray need_ext auto_attrs provides array { 
    2727    ATTR INTVAL resize_threshold; /* max size before array needs resizing */ 
    2828 
    2929 
     
    3737*/ 
    3838 
    3939    VTABLE void init() { 
    40         Parrot_ResizablePMCArray_attributes *attrs = 
    41             mem_allocate_zeroed_typed(Parrot_ResizablePMCArray_attributes); 
    42  
    43         PMC_data(SELF) = attrs; 
    4440        PObj_custom_mark_destroy_SETALL(SELF); 
    4541    } 
    4642 
  • src/pmc/fixedfloatarray.pmc

     
    1919 
    2020*/ 
    2121 
    22 pmclass FixedFloatArray need_ext provides array { 
     22pmclass FixedFloatArray need_ext auto_attrs provides array { 
    2323    ATTR INTVAL    size; 
    2424    ATTR FLOATVAL *float_array; 
    2525 
     
    4040*/ 
    4141 
    4242    VTABLE void init() { 
    43         Parrot_FixedFloatArray_attributes* attrs = 
    44             mem_allocate_zeroed_typed(Parrot_FixedFloatArray_attributes); 
    45         PMC_data(SELF) = attrs; 
    4643    } 
    4744 
    4845/* 
  • src/pmc/parrotinterpreter.pmc

     
    240240            Parrot_ParrotInterpreter_attributes *attrs = 
    241241                mem_allocate_zeroed_typed(Parrot_ParrotInterpreter_attributes); 
    242242            PMC_data(SELF) = attrs; 
     243        } 
     244        if (!PMC_interp(SELF)) { 
    243245            create_interp(SELF, INTERP); 
    244             PARROT_ASSERT(attrs->interp); 
    245246        } 
    246247        PObj_active_destroy_SET(SELF); 
    247248    } 
     
    261262    VTABLE void init_pmc(PMC *parent) { 
    262263        Parrot_Interp p = PMC_interp(parent); 
    263264 
    264         if (!PMC_interp(SELF)) 
     265        if (!PMC_data(SELF)) { 
     266            Parrot_ParrotInterpreter_attributes *attrs = 
     267                mem_allocate_zeroed_typed(Parrot_ParrotInterpreter_attributes); 
     268            PMC_data(SELF) = attrs; 
     269        } 
     270        if (!PMC_interp(SELF)) { 
    265271            create_interp(SELF, p); 
     272        } 
     273        PObj_active_destroy_SET(SELF); 
    266274    } 
    267275 
    268276 
  • src/pmc/resizableintegerarray.pmc

     
    2020 
    2121*/ 
    2222 
    23 pmclass ResizableIntegerArray extends FixedIntegerArray need_ext provides array { 
     23pmclass ResizableIntegerArray extends FixedIntegerArray need_ext auto_attrs provides array { 
    2424    ATTR INTVAL resize_threshold; /* max size before array needs to be resized */ 
    2525 
    2626/* 
     
    3333 
    3434*/ 
    3535    VTABLE void init() { 
    36         Parrot_ResizableIntegerArray_attributes* attrs = 
    37             mem_allocate_zeroed_typed(Parrot_ResizableIntegerArray_attributes); 
    38         PMC_data(SELF) = attrs; 
    3936        PObj_active_destroy_SET(SELF); 
    4037    } 
    4138 
  • src/pmc/multisub.pmc

     
    1919 
    2020*/ 
    2121 
    22 pmclass MultiSub extends ResizablePMCArray need_ext provides array { 
     22pmclass MultiSub extends ResizablePMCArray need_ext auto_attrs provides array { 
    2323 
    2424    VTABLE void push_pmc(PMC *value) { 
    2525        STRING * const _sub = CONST_STRING(interp, "Sub"); 
  • src/pmc/resizablefloatarray.pmc

     
    2020 
    2121*/ 
    2222 
    23 pmclass ResizableFloatArray extends FixedFloatArray need_ext provides array { 
     23pmclass ResizableFloatArray extends FixedFloatArray need_ext auto_attrs provides array { 
    2424    ATTR INTVAL resize_threshold; /* max size before array needs resizing */ 
    2525 
    2626 
     
    3535 
    3636*/ 
    3737    VTABLE void init() { 
    38         Parrot_ResizableFloatArray_attributes* attrs = 
    39             mem_allocate_zeroed_typed(Parrot_ResizableFloatArray_attributes); 
    40         PMC_data(SELF) = attrs; 
    4138    } 
    4239 
    4340/* 
  • src/pmc/resizablestringarray.pmc

     
    1818 
    1919*/ 
    2020 
    21 pmclass ResizableStringArray extends FixedStringArray need_ext provides array { 
     21pmclass ResizableStringArray extends FixedStringArray need_ext auto_attrs provides array { 
    2222    ATTR UINTVAL resize_threshold; /*max capacity before resizing */ 
    2323 
    2424/* 
     
    3636*/ 
    3737 
    3838    VTABLE void init() { 
    39         Parrot_ResizableStringArray_attributes *attrs = 
    40             mem_allocate_zeroed_typed(Parrot_ResizableStringArray_attributes); 
    41  
    42         PMC_data(SELF)   = attrs; 
    43  
    4439        PObj_custom_mark_destroy_SETALL(SELF); 
    4540    } 
    4641 
  • src/pmc/fixedpmcarray.pmc

     
    2727#define PMC_size(x)  ((Parrot_FixedPMCArray_attributes *)PMC_data(x))->size 
    2828#define PMC_array(x) ((Parrot_FixedPMCArray_attributes *)PMC_data(x))->pmc_array 
    2929 
    30 pmclass FixedPMCArray need_ext provides array { 
     30pmclass FixedPMCArray need_ext auto_attrs provides array { 
    3131    ATTR INTVAL   size;      /* number of elements in the array */ 
    3232    ATTR PMC    **pmc_array; /* pointer to PMC array */ 
    3333 
     
    6565*/ 
    6666 
    6767    VTABLE void init() { 
    68         Parrot_FixedPMCArray_attributes *attrs = 
    69             mem_allocate_zeroed_typed(Parrot_FixedPMCArray_attributes); 
    70  
    71         PMC_data(SELF) = attrs; 
    7268        PObj_custom_mark_destroy_SETALL(SELF); 
    7369    } 
    7470 
     
    8379*/ 
    8480 
    8581    VTABLE void destroy() { 
    86         if (PMC_array(SELF)) { 
    87             mem_sys_free(PMC_array(SELF)); 
    88         } 
    8982        mem_sys_free(PMC_data(SELF)); 
    9083        PMC_data(SELF) = NULL; 
    9184    } 
     
    138131*/ 
    139132 
    140133    VTABLE INTVAL elements() { 
    141         return PMC_size(SELF); 
     134        INTVAL size; 
     135        GET_ATTR_size(INTERP, SELF, size); 
     136        return size; 
    142137    } 
    143138 
    144139/* 
  • src/pmc/fixedintegerarray.pmc

     
    1919 
    2020*/ 
    2121 
    22 pmclass FixedIntegerArray need_ext provides array { 
     22pmclass FixedIntegerArray need_ext auto_attrs provides array { 
    2323    ATTR INTVAL   size;  /* number of INTVALs stored in this array */ 
    2424    ATTR INTVAL * int_array; /* INTVALs are stored here */ 
    2525 
     
    4040*/ 
    4141 
    4242    VTABLE void init() { 
    43         Parrot_FixedIntegerArray_attributes* attrs = 
    44             mem_allocate_zeroed_typed(Parrot_FixedIntegerArray_attributes); 
    45         PMC_data(SELF) = attrs; 
    4643        PObj_active_destroy_SET(SELF); 
    4744    } 
    4845 
  • src/pmc/resizablebooleanarray.pmc

     
    3030/* Convert a size in bits to a size in bytes */ 
    3131#define BITS_TO_BYTES(size) ((size) / BITS_PER_CHAR) 
    3232 
    33 pmclass ResizableBooleanArray extends FixedBooleanArray need_ext provides array { 
     33pmclass ResizableBooleanArray extends FixedBooleanArray need_ext auto_attrs provides array { 
    3434    /* RBA uses the same attributes as FBA, but in RBA they're used as follows: 
    3535       size:             position of the last element (a.k.a tail_pos) 
    3636       resize_threshold: position of the first element (a.k.a. head_pos) */ 
  • src/pmc/fixedbooleanarray.pmc

     
    2323 
    2424#define BITS_PER_CHAR 8 
    2525 
    26 pmclass FixedBooleanArray need_ext provides array { 
     26pmclass FixedBooleanArray need_ext auto_attrs provides array { 
    2727    ATTR UINTVAL         size;             /* # of bits this fba holds */ 
    2828    ATTR UINTVAL         resize_threshold; /* max capacity before resizing */ 
    2929    ATTR unsigned char * bit_array;        /* where the bits go */ 
     
    4545*/ 
    4646 
    4747    VTABLE void init() { 
    48         Parrot_FixedBooleanArray_attributes* attrs = 
    49             mem_allocate_zeroed_typed(Parrot_FixedBooleanArray_attributes); 
    50  
    51         PMC_data(SELF) = attrs; 
    5248        PObj_active_destroy_SET(SELF); 
    5349    } 
    5450 
  • lib/Parrot/Vtable.pm

     
    170170    INTVAL  base_type;      /* 'type' value for MMD */ 
    171171    STRING *whoami;         /* Name of class this vtable is for */ 
    172172    UINTVAL flags;          /* Flags. Duh */ 
     173    UINTVAL attr_size;      /* Size of the attributes struct */ 
    173174    STRING *provides_str;   /* space-separated list of interfaces */ 
    174175    Hash   *isa_hash;       /* Hash of class names */ 
    175176    PMC    *pmc_class;      /* for PMCs: a PMC of that type 
  • lib/Parrot/Pmc2c/PMCEmitter.pm

     
    458458        $enum_name, /* base_type */ 
    459459        NULL,       /* whoami */ 
    460460        $vtbl_flag, /* flags */ 
     461        0,          /* attr size */ 
    461462        NULL,       /* provides_str */ 
    462463        NULL,       /* isa_hash */ 
    463464        NULL,       /* class */ 
     
    601602 
    602603EOC 
    603604 
     605    if ( @{$attributes} && $self->{flags}{auto_attrs} ) { 
     606    $cout .= <<"EOC"; 
     607        vt->attr_size = sizeof(Parrot_${classname}_attributes); 
     608EOC 
     609    } 
     610 
    604611    # init vtable slot 
    605612    if ( $self->is_dynamic ) { 
    606613        $cout .= <<"EOC"; 
     
    640647            vt_${k}                 = Parrot_${classname}_${k}_get_vtable(interp); 
    641648            vt_${k}->base_type      = $enum_name; 
    642649            vt_${k}->flags          = $k_flags; 
     650EOC 
     651        if ( @{$attributes}  && $self->{flags}{auto_attrs} ) { 
     652            $cout .= <<"EOC"; 
     653            vt_${k}->attr_size = sizeof(Parrot_${classname}_attributes); 
     654EOC 
     655            } 
     656        $cout .= <<"EOC"; 
     657 
    643658            vt_${k}->attribute_defs = attr_defs; 
    644659 
    645660            vt_${k}->base_type           = entry;