Ticket #1351 (closed patch: fixed)

Opened 12 years ago

Last modified 12 years ago

[patch]changed bignum.pmc to use GET_ATTR syntax

Reported by: jimmy Owned by:
Priority: normal Milestone:
Component: core Version: 1.8.0
Severity: medium Keywords:
Cc: Language:
Patch status: new Platform:

Description

changed bignum.pmc to use GET_ATTR syntax

Index: src/pmc/bignum.pmc
===================================================================
--- src/pmc/bignum.pmc	(版本 42868)
+++ src/pmc/bignum.pmc	(工作副本)
@@ -153,16 +153,14 @@
 
 static void
 bignum_init(PARROT_INTERP, PMC *self) {
-    Parrot_BigNum_attributes *attrs =
-        mem_allocate_zeroed_typed(Parrot_BigNum_attributes);
 #ifdef PARROT_HAS_GMP
-    attrs->bn = mem_allocate_zeroed_typed(BIGNUM);
-    mpf_clear(attrs->bn->b);
-    mpf_init(attrs->bn->b);
+    BIGNUM * const bn = mem_allocate_zeroed_typed(BIGNUM);
+    SETATTR_BigNum_bn(interp, self, bn);
+    mpf_clear(bn->b);
+    mpf_init(bn->b);
 #else
-    attrs->bn = NULL;
+    SETATTR_BigNum_bn(interp, SELF, NULL);
 #endif
-    PMC_data(self) = attrs;
 }
 
 
@@ -173,6 +171,7 @@
     GETATTR_BigNum_bn(interp, self, bn);
     mpf_clear(bn->b);
 #endif
+    mem_sys_free(bn);
 }
 
 
@@ -225,10 +224,8 @@
 static void
 bignum_set_bigint(PARROT_INTERP, PMC *self, struct BIGINT *value) {
     BIGNUM *bn;
-    struct BIGINT *bi;
     GETATTR_BigNum_bn(interp, self, bn);
-    bi->b = PARROT_BIGINT(value);
-    mpf_set(bn->b, (mpf_srcptr)bi->b);
+    mpf_set(bn->b, (mpf_srcptr)value->b);
 }
 #  endif
 
@@ -243,7 +240,7 @@
 bignum_set_self(PARROT_INTERP, PMC *self, BIGNUM *value) {
     BIGNUM *bn;
     GETATTR_BigNum_bn(interp, self, bn);
-    mpf_set(bn->b, (mpf_srcptr)((BIGNUM*)value)->b);
+    mpf_set(bn->b, (mpf_srcptr)(value)->b);
 }
 
 static long
@@ -778,7 +775,7 @@
 
 #endif /* ifdef PARROT_HAS_GMP */
 
-pmclass BigNum {
+pmclass BigNum auto_attrs {
     ATTR struct BIGNUM * bn; /*bignum val*/
 
 /*
@@ -819,17 +816,7 @@
     }
 
     VTABLE void destroy() {
-        BIGNUM                   *bn;
-        Parrot_BigNum_attributes *attrs;
-
         bignum_clear(INTERP, SELF);
-
-        attrs = (Parrot_BigNum_attributes*)PMC_data(SELF);
-#ifdef PARROT_HAS_GMP
-        mem_sys_free(attrs->bn);
-#endif
-        mem_sys_free(attrs);
-        PMC_data(SELF) = NULL;
     }
 
 /*

Attachments

bignum.pmc.patch Download (1.9 KB) - added by jimmy 12 years ago.

Change History

Changed 12 years ago by jimmy

in reply to: ↑ description   Changed 12 years ago by jkeenan

Replying to jimmy:

changed bignum.pmc to use GET_ATTR syntax

As noted in  this comment on TT #1348, I've been looking at whether your patches work with one another, "work" meaning "does not prevent Parrot from completing make successfully".

This patch works with:

* the Vtable.pm patch submitted in TT #1354

* the arrayiterator.pmc patch submitted in TT #1349

* the bigint.pmc patch submitted in TT #1350

Have not yet run make test.

  Changed 12 years ago by jkeenan

  • component changed from none to core
  • patch set to new

  Changed 12 years ago by cotto

  • status changed from new to closed
  • resolution set to fixed

This patch looks sane and causes no test failures. I've committed it as r42971. Thanks!

Note: See TracTickets for help on using tickets.