Changeset 32548 in project


Ignore:
Timestamp:
07/05/15 20:12:24 (5 years ago)
Author:
sjamaan
Message:

numbers: Don't try to be clever with "reusing" closures; this may cause trouble if the closure has moved to the heap while the bignum we stick in it is still on the stack (we don't go through the mutator)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/numbers/trunk/numbers-c.c

    r32547 r32548  
    31363136                          k, x, y, return_q, return_r);
    31373137    } else if (C_truep(return_q)) {
    3138       C_word kab[C_SIZEOF_CLOSURE(8)], *ka = kab, k2;
    3139       k2 = C_closure(&ka, 8, (C_word)bignum_divide_2_unsigned, k, x, y,
    3140                      return_q, return_r, r_negp,
    3141                      /* Will be filled in later */ C_SCHEME_UNDEFINED);
     3138      C_word kab[C_SIZEOF_CLOSURE(6)], *ka = kab, k2;
     3139      k2 = C_closure(&ka, 6, (C_word)bignum_divide_2_unsigned, k,
     3140                     x, y, return_r, r_negp);
    31423141      size = C_fix(C_bignum_size(x) + 1 - C_bignum_size(y));
    31433142      C_allocate_bignum(5, (C_word)NULL, k2, size, q_negp, C_SCHEME_FALSE);
    31443143    } else { /* We can skip bignum_divide_2_unsigned if we need no quotient */
    3145       C_word kab[C_SIZEOF_CLOSURE(8)], *ka = kab, k2;
    3146       k2 = C_closure(&ka, 8, (C_word)bignum_divide_2_unsigned_2, k, x, y,
    3147                      return_q, return_r, r_negp,
    3148                      /* Will be filled in later */ C_SCHEME_UNDEFINED);
     3144      C_word kab[C_SIZEOF_CLOSURE(7)], *ka = kab, k2;
     3145      k2 = C_closure(&ka, 7, (C_word)bignum_divide_2_unsigned_2, k,
     3146                     x, y, return_q, return_r, C_SCHEME_UNDEFINED);
    31493147      size = C_fix(C_bignum_size(x) + 1); /* May need to be normalized */
    31503148      C_allocate_bignum(5, (C_word)NULL, k2, size, r_negp, C_SCHEME_FALSE);
     
    32513249bignum_divide_2_unsigned(C_word c, C_word self, C_word quotient)
    32523250{
    3253   C_word numerator = C_block_item(self, 2),
    3254          remainder_negp = C_block_item(self, 6),
    3255          size = C_fix(C_bignum_size(numerator) + 1);
    3256 
    3257   /* Nice: We can recycle the current closure */
    3258   C_set_block_item(self, 0, (C_word)bignum_divide_2_unsigned_2);
    3259   C_set_block_item(self, 7, quotient);
    3260   C_allocate_bignum(5, (C_word)NULL, self, size, remainder_negp, C_SCHEME_FALSE);
     3251  C_word k = C_block_item(self, 1),
     3252         x = C_block_item(self, 2),
     3253         y = C_block_item(self, 3),
     3254         size = C_fix(C_bignum_size(x) + 1),
     3255         return_r = C_block_item(self, 4),
     3256         r_negp = C_block_item(self, 5),
     3257         kab[C_SIZEOF_CLOSURE(7)], *ka = kab, k2;
     3258
     3259  k2 = C_closure(&ka, 7, (C_word)bignum_divide_2_unsigned_2, k,
     3260                 x, y, C_SCHEME_TRUE, return_r, quotient);
     3261  C_allocate_bignum(5, (C_word)NULL, k2, size, r_negp, C_SCHEME_FALSE);
    32613262}
    32623263
     
    32833284         return_quotient = C_block_item(self, 4),
    32843285         return_remainder = C_block_item(self, 5),
    3285          /* This one may be overwritten with the remainder */
    3286          /* remainder_negp = C_block_item(self, 6), */
    3287          quotient = C_block_item(self, 7),
     3286         quotient = C_block_item(self, 6),
    32883287         length = C_bignum_size(denominator);
    32893288  C_uword d1 = *(C_bignum_digits(denominator) + length - 1),
Note: See TracChangeset for help on using the changeset viewer.