Ticket #1351: bignum.pmc.patch

File bignum.pmc.patch, 1.9 KB (added by jimmy, 12 years ago)
  • src/pmc/bignum.pmc

     
    153153 
    154154static void 
    155155bignum_init(PARROT_INTERP, PMC *self) { 
    156     Parrot_BigNum_attributes *attrs = 
    157         mem_allocate_zeroed_typed(Parrot_BigNum_attributes); 
    158156#ifdef PARROT_HAS_GMP 
    159     attrs->bn = mem_allocate_zeroed_typed(BIGNUM); 
    160     mpf_clear(attrs->bn->b); 
    161     mpf_init(attrs->bn->b); 
     157    BIGNUM * const bn = mem_allocate_zeroed_typed(BIGNUM); 
     158    SETATTR_BigNum_bn(interp, self, bn); 
     159    mpf_clear(bn->b); 
     160    mpf_init(bn->b); 
    162161#else 
    163     attrs->bn = NULL; 
     162    SETATTR_BigNum_bn(interp, SELF, NULL); 
    164163#endif 
    165     PMC_data(self) = attrs; 
    166164} 
    167165 
    168166 
     
    173171    GETATTR_BigNum_bn(interp, self, bn); 
    174172    mpf_clear(bn->b); 
    175173#endif 
     174    mem_sys_free(bn); 
    176175} 
    177176 
    178177 
     
    225224static void 
    226225bignum_set_bigint(PARROT_INTERP, PMC *self, struct BIGINT *value) { 
    227226    BIGNUM *bn; 
    228     struct BIGINT *bi; 
    229227    GETATTR_BigNum_bn(interp, self, bn); 
    230     bi->b = PARROT_BIGINT(value); 
    231     mpf_set(bn->b, (mpf_srcptr)bi->b); 
     228    mpf_set(bn->b, (mpf_srcptr)value->b); 
    232229} 
    233230#  endif 
    234231 
     
    243240bignum_set_self(PARROT_INTERP, PMC *self, BIGNUM *value) { 
    244241    BIGNUM *bn; 
    245242    GETATTR_BigNum_bn(interp, self, bn); 
    246     mpf_set(bn->b, (mpf_srcptr)((BIGNUM*)value)->b); 
     243    mpf_set(bn->b, (mpf_srcptr)(value)->b); 
    247244} 
    248245 
    249246static long 
     
    778775 
    779776#endif /* ifdef PARROT_HAS_GMP */ 
    780777 
    781 pmclass BigNum { 
     778pmclass BigNum auto_attrs { 
    782779    ATTR struct BIGNUM * bn; /*bignum val*/ 
    783780 
    784781/* 
     
    819816    } 
    820817 
    821818    VTABLE void destroy() { 
    822         BIGNUM                   *bn; 
    823         Parrot_BigNum_attributes *attrs; 
    824  
    825819        bignum_clear(INTERP, SELF); 
    826  
    827         attrs = (Parrot_BigNum_attributes*)PMC_data(SELF); 
    828 #ifdef PARROT_HAS_GMP 
    829         mem_sys_free(attrs->bn); 
    830 #endif 
    831         mem_sys_free(attrs); 
    832         PMC_data(SELF) = NULL; 
    833820    } 
    834821 
    835822/*