Ticket #895: TT_895_1.patch
File TT_895_1.patch, 12.9 KB (added by NotFound, 12 years ago) |
---|
-
src/gc/api.c
373 373 if (PObj_active_destroy_TEST(pmc)) 374 374 VTABLE_destroy(interp, pmc); 375 375 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 376 382 if (PObj_is_PMC_EXT_TEST(pmc)) 377 383 Parrot_gc_free_pmc_ext(interp, pmc); 378 384 -
src/pmc.c
240 240 241 241 /* Set the right vtable */ 242 242 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; 243 249 244 250 return pmc; 245 251 } … … 361 367 /* Do we have an extension area? */ 362 368 INTVAL const has_ext = (PObj_is_PMC_EXT_TEST(pmc) && pmc->pmc_ext); 363 369 370 if (PMC_data(pmc) && pmc->vtable->attr_size) 371 mem_sys_free(PMC_data(pmc)); 372 364 373 /* Do we need one? */ 365 374 if (flags & VTABLE_PMC_NEEDS_EXT) { 366 375 /* If we need an ext area, go allocate one */ … … 465 474 pmc = Parrot_gc_new_pmc_header(interp, flags); 466 475 pmc->vtable = vtable; 467 476 477 if (vtable->attr_size) { 478 PMC_data(pmc) = mem_sys_allocate_zeroed(vtable->attr_size); 479 } 480 468 481 #if GC_VERBOSE 469 482 if (Interp_flags_TEST(interp, PARROT_TRACE_FLAG)) { 470 483 /* XXX make a more verbose trace flag */ -
src/pmc/complex.pmc
217 217 } 218 218 219 219 220 pmclass Complex need_ext {220 pmclass Complex need_ext auto_attrs { 221 221 222 222 ATTR FLOATVAL re; /* real part */ 223 223 ATTR FLOATVAL im; /* imaginary part */ … … 340 340 */ 341 341 342 342 VTABLE void init() { 343 /* XXX should check if mem_sys_allocate failed */344 PMC_data(SELF) = mem_allocate_typed(Parrot_Complex_attributes);345 343 SET_ATTR_re(INTERP, SELF, 0.0); 346 344 SET_ATTR_im(INTERP, SELF, 0.0); 347 345 -
src/pmc/resizablepmcarray.pmc
23 23 #define PMC_array(x) ((Parrot_ResizablePMCArray_attributes *)PMC_data(x))->pmc_array 24 24 #define PMC_threshold(x) ((Parrot_ResizablePMCArray_attributes *)PMC_data(x))->resize_threshold 25 25 26 pmclass ResizablePMCArray extends FixedPMCArray need_ext provides array {26 pmclass ResizablePMCArray extends FixedPMCArray need_ext auto_attrs provides array { 27 27 ATTR INTVAL resize_threshold; /* max size before array needs resizing */ 28 28 29 29 … … 37 37 */ 38 38 39 39 VTABLE void init() { 40 Parrot_ResizablePMCArray_attributes *attrs =41 mem_allocate_zeroed_typed(Parrot_ResizablePMCArray_attributes);42 43 PMC_data(SELF) = attrs;44 40 PObj_custom_mark_destroy_SETALL(SELF); 45 41 } 46 42 -
src/pmc/fixedfloatarray.pmc
19 19 20 20 */ 21 21 22 pmclass FixedFloatArray need_ext provides array {22 pmclass FixedFloatArray need_ext auto_attrs provides array { 23 23 ATTR INTVAL size; 24 24 ATTR FLOATVAL *float_array; 25 25 … … 40 40 */ 41 41 42 42 VTABLE void init() { 43 Parrot_FixedFloatArray_attributes* attrs =44 mem_allocate_zeroed_typed(Parrot_FixedFloatArray_attributes);45 PMC_data(SELF) = attrs;46 43 } 47 44 48 45 /* -
src/pmc/parrotinterpreter.pmc
240 240 Parrot_ParrotInterpreter_attributes *attrs = 241 241 mem_allocate_zeroed_typed(Parrot_ParrotInterpreter_attributes); 242 242 PMC_data(SELF) = attrs; 243 } 244 if (!PMC_interp(SELF)) { 243 245 create_interp(SELF, INTERP); 244 PARROT_ASSERT(attrs->interp);245 246 } 246 247 PObj_active_destroy_SET(SELF); 247 248 } … … 261 262 VTABLE void init_pmc(PMC *parent) { 262 263 Parrot_Interp p = PMC_interp(parent); 263 264 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)) { 265 271 create_interp(SELF, p); 272 } 273 PObj_active_destroy_SET(SELF); 266 274 } 267 275 268 276 -
src/pmc/resizableintegerarray.pmc
20 20 21 21 */ 22 22 23 pmclass ResizableIntegerArray extends FixedIntegerArray need_ext provides array {23 pmclass ResizableIntegerArray extends FixedIntegerArray need_ext auto_attrs provides array { 24 24 ATTR INTVAL resize_threshold; /* max size before array needs to be resized */ 25 25 26 26 /* … … 33 33 34 34 */ 35 35 VTABLE void init() { 36 Parrot_ResizableIntegerArray_attributes* attrs =37 mem_allocate_zeroed_typed(Parrot_ResizableIntegerArray_attributes);38 PMC_data(SELF) = attrs;39 36 PObj_active_destroy_SET(SELF); 40 37 } 41 38 -
src/pmc/multisub.pmc
19 19 20 20 */ 21 21 22 pmclass MultiSub extends ResizablePMCArray need_ext provides array {22 pmclass MultiSub extends ResizablePMCArray need_ext auto_attrs provides array { 23 23 24 24 VTABLE void push_pmc(PMC *value) { 25 25 STRING * const _sub = CONST_STRING(interp, "Sub"); -
src/pmc/resizablefloatarray.pmc
20 20 21 21 */ 22 22 23 pmclass ResizableFloatArray extends FixedFloatArray need_ext provides array {23 pmclass ResizableFloatArray extends FixedFloatArray need_ext auto_attrs provides array { 24 24 ATTR INTVAL resize_threshold; /* max size before array needs resizing */ 25 25 26 26 … … 35 35 36 36 */ 37 37 VTABLE void init() { 38 Parrot_ResizableFloatArray_attributes* attrs =39 mem_allocate_zeroed_typed(Parrot_ResizableFloatArray_attributes);40 PMC_data(SELF) = attrs;41 38 } 42 39 43 40 /* -
src/pmc/resizablestringarray.pmc
18 18 19 19 */ 20 20 21 pmclass ResizableStringArray extends FixedStringArray need_ext provides array {21 pmclass ResizableStringArray extends FixedStringArray need_ext auto_attrs provides array { 22 22 ATTR UINTVAL resize_threshold; /*max capacity before resizing */ 23 23 24 24 /* … … 36 36 */ 37 37 38 38 VTABLE void init() { 39 Parrot_ResizableStringArray_attributes *attrs =40 mem_allocate_zeroed_typed(Parrot_ResizableStringArray_attributes);41 42 PMC_data(SELF) = attrs;43 44 39 PObj_custom_mark_destroy_SETALL(SELF); 45 40 } 46 41 -
src/pmc/fixedpmcarray.pmc
27 27 #define PMC_size(x) ((Parrot_FixedPMCArray_attributes *)PMC_data(x))->size 28 28 #define PMC_array(x) ((Parrot_FixedPMCArray_attributes *)PMC_data(x))->pmc_array 29 29 30 pmclass FixedPMCArray need_ext provides array {30 pmclass FixedPMCArray need_ext auto_attrs provides array { 31 31 ATTR INTVAL size; /* number of elements in the array */ 32 32 ATTR PMC **pmc_array; /* pointer to PMC array */ 33 33 … … 65 65 */ 66 66 67 67 VTABLE void init() { 68 Parrot_FixedPMCArray_attributes *attrs =69 mem_allocate_zeroed_typed(Parrot_FixedPMCArray_attributes);70 71 PMC_data(SELF) = attrs;72 68 PObj_custom_mark_destroy_SETALL(SELF); 73 69 } 74 70 … … 83 79 */ 84 80 85 81 VTABLE void destroy() { 86 if (PMC_array(SELF)) {87 mem_sys_free(PMC_array(SELF));88 }89 82 mem_sys_free(PMC_data(SELF)); 90 83 PMC_data(SELF) = NULL; 91 84 } … … 138 131 */ 139 132 140 133 VTABLE INTVAL elements() { 141 return PMC_size(SELF); 134 INTVAL size; 135 GET_ATTR_size(INTERP, SELF, size); 136 return size; 142 137 } 143 138 144 139 /* -
src/pmc/fixedintegerarray.pmc
19 19 20 20 */ 21 21 22 pmclass FixedIntegerArray need_ext provides array {22 pmclass FixedIntegerArray need_ext auto_attrs provides array { 23 23 ATTR INTVAL size; /* number of INTVALs stored in this array */ 24 24 ATTR INTVAL * int_array; /* INTVALs are stored here */ 25 25 … … 40 40 */ 41 41 42 42 VTABLE void init() { 43 Parrot_FixedIntegerArray_attributes* attrs =44 mem_allocate_zeroed_typed(Parrot_FixedIntegerArray_attributes);45 PMC_data(SELF) = attrs;46 43 PObj_active_destroy_SET(SELF); 47 44 } 48 45 -
src/pmc/resizablebooleanarray.pmc
30 30 /* Convert a size in bits to a size in bytes */ 31 31 #define BITS_TO_BYTES(size) ((size) / BITS_PER_CHAR) 32 32 33 pmclass ResizableBooleanArray extends FixedBooleanArray need_ext provides array {33 pmclass ResizableBooleanArray extends FixedBooleanArray need_ext auto_attrs provides array { 34 34 /* RBA uses the same attributes as FBA, but in RBA they're used as follows: 35 35 size: position of the last element (a.k.a tail_pos) 36 36 resize_threshold: position of the first element (a.k.a. head_pos) */ -
src/pmc/fixedbooleanarray.pmc
23 23 24 24 #define BITS_PER_CHAR 8 25 25 26 pmclass FixedBooleanArray need_ext provides array {26 pmclass FixedBooleanArray need_ext auto_attrs provides array { 27 27 ATTR UINTVAL size; /* # of bits this fba holds */ 28 28 ATTR UINTVAL resize_threshold; /* max capacity before resizing */ 29 29 ATTR unsigned char * bit_array; /* where the bits go */ … … 45 45 */ 46 46 47 47 VTABLE void init() { 48 Parrot_FixedBooleanArray_attributes* attrs =49 mem_allocate_zeroed_typed(Parrot_FixedBooleanArray_attributes);50 51 PMC_data(SELF) = attrs;52 48 PObj_active_destroy_SET(SELF); 53 49 } 54 50 -
lib/Parrot/Vtable.pm
170 170 INTVAL base_type; /* 'type' value for MMD */ 171 171 STRING *whoami; /* Name of class this vtable is for */ 172 172 UINTVAL flags; /* Flags. Duh */ 173 UINTVAL attr_size; /* Size of the attributes struct */ 173 174 STRING *provides_str; /* space-separated list of interfaces */ 174 175 Hash *isa_hash; /* Hash of class names */ 175 176 PMC *pmc_class; /* for PMCs: a PMC of that type -
lib/Parrot/Pmc2c/PMCEmitter.pm
458 458 $enum_name, /* base_type */ 459 459 NULL, /* whoami */ 460 460 $vtbl_flag, /* flags */ 461 0, /* attr size */ 461 462 NULL, /* provides_str */ 462 463 NULL, /* isa_hash */ 463 464 NULL, /* class */ … … 601 602 602 603 EOC 603 604 605 if ( @{$attributes} && $self->{flags}{auto_attrs} ) { 606 $cout .= <<"EOC"; 607 vt->attr_size = sizeof(Parrot_${classname}_attributes); 608 EOC 609 } 610 604 611 # init vtable slot 605 612 if ( $self->is_dynamic ) { 606 613 $cout .= <<"EOC"; … … 640 647 vt_${k} = Parrot_${classname}_${k}_get_vtable(interp); 641 648 vt_${k}->base_type = $enum_name; 642 649 vt_${k}->flags = $k_flags; 650 EOC 651 if ( @{$attributes} && $self->{flags}{auto_attrs} ) { 652 $cout .= <<"EOC"; 653 vt_${k}->attr_size = sizeof(Parrot_${classname}_attributes); 654 EOC 655 } 656 $cout .= <<"EOC"; 657 643 658 vt_${k}->attribute_defs = attr_defs; 644 659 645 660 vt_${k}->base_type = entry;