Changeset 31573 in project


Ignore:
Timestamp:
10/04/14 19:52:00 (5 years ago)
Author:
sjamaan
Message:

numbers: Another attempt at fixing the strlcat compat code

File:
1 edited

Legend:

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

    r31572 r31573  
    9696static void bignum_destructive_divide_normalized(C_word u, C_word v, C_word q);
    9797static C_word bignum_divide_and_subtract(C_word *v_start, C_word *v_end, C_word guess, C_word *u_start);
    98 static C_word bignum_normalize_shifted(C_word bignum, C_word shift_right);
     98static C_word bignum_simplify_shifted(C_word bignum, C_word shift_right);
    9999
    100100static void barf(int code, char *loc, ...) C_noret;
     
    632632
    633633    *scan_r = 0; /* Ensure trimming works.  TODO: set length directly? */
    634     C_kontinue(k, C_bignum_normalize(result));
     634    C_kontinue(k, C_bignum_simplify(result));
    635635  }
    636636}
     
    732732    (*scan_r++) = (*scan_x++);
    733733
    734   C_kontinue(k, C_bignum_normalize(result));
     734  C_kontinue(k, C_bignum_simplify(result));
    735735}
    736736
     
    967967      }
    968968      bignum_destructive_divide_normalized(tmp_x, y, C_SCHEME_UNDEFINED);
    969       tmp_x = C_bignum_normalize(tmp_x);
     969      tmp_x = C_bignum_simplify(tmp_x);
    970970    } else {
    971971      bignum_destructive_normalize(tmp_x, x, shift); /* OK even if tmp_x = x! */
    972972      bignum_destructive_normalize(tmp_y, y, shift); /* OK even if tmp_y = y! */
    973973      bignum_destructive_divide_normalized(tmp_x, tmp_y, C_SCHEME_UNDEFINED);
    974       tmp_x = bignum_normalize_shifted(tmp_x, shift);
    975       tmp_y = bignum_normalize_shifted(tmp_y, shift);
     974      tmp_x = bignum_simplify_shifted(tmp_x, shift);
     975      tmp_y = bignum_simplify_shifted(tmp_y, shift);
    976976      assert(C_block_item(k, 0) != 0);
    977977    }
     
    11701170         old_big = C_block_item(self, 2);
    11711171  bignum_digits_destructive_copy(new_big, old_big);
    1172   C_kontinue(k, C_bignum_normalize(new_big));
     1172  C_kontinue(k, C_bignum_simplify(new_big));
    11731173}
    11741174
     
    15101510}
    15111511
    1512 /* Normalization: scan trailing zeroes, then return a fixnum if the
     1512/* Simplification: scan trailing zeroes, then return a fixnum if the
    15131513 * value fits, or trim the bignum's length. */
    15141514C_word C_ccall
    1515 C_bignum_normalize(C_word big)
     1515C_bignum_simplify(C_word big)
    15161516{
    15171517  C_word *start = C_bignum_digits(big);
     
    16621662       r = bignum_digits_destructive_scale_up_with_carry(d, d+2, absx, 0);
    16631663       assert(r == 0); /* Should never result in a carry; y is big enough */
    1664        return C_bignum_normalize(y);
     1664       return C_bignum_simplify(y);
    16651665     }
    16661666  } else if (C_fitsinbignumhalfdigitp(absy)) {
     
    16761676       r = bignum_digits_destructive_scale_up_with_carry(d, d+2, absy, 0);
    16771677       assert(r == 0); /* Should never result in a carry; x is big enough */
    1678        return C_bignum_normalize(x);
     1678       return C_bignum_simplify(x);
    16791679     }
    16801680  } else {
     
    16831683    r = C_bignum4(ptr, negp != 0, 0, 0, 0, 0);
    16841684    bignum_digits_multiply(x, y, r);
    1685     return C_bignum_normalize(r);
     1685    return C_bignum_simplify(r);
    16861686  }
    16871687}
     
    17381738  *end_digit = bignum_digits_destructive_scale_up_with_carry(digits, end_digit,
    17391739                                                             C_unfix(fixy), 0);
    1740   C_kontinue(k, C_bignum_normalize(new_big));
     1740  C_kontinue(k, C_bignum_simplify(new_big));
    17411741}
    17421742
     
    18231823
    18241824  bignum_digits_multiply(x, y, result);
    1825   C_kontinue(k, C_bignum_normalize(result));
     1825  C_kontinue(k, C_bignum_simplify(result));
    18261826}
    18271827
     
    19061906  if (carry) (*last_digit++) = carry; /* Move end */
    19071907
    1908   C_kontinue(k, C_bignum_normalize(result));
     1908  C_kontinue(k, C_bignum_simplify(result));
    19091909}
    19101910
     
    20572057  if(C_isnan(f)) {
    20582058    /* XXX Back-compat support for CHICKENS older than 4.9.0 */
    2059 #ifdef C_strlcpy
     2059#if defined(HAVE_STRLCPY) || !defined(C_strcpy)
    20602060    C_strlcpy(buffer, C_text("+nan.0"), sizeof(buffer));
    20612061#else
     
    20802080        *buffer = '+';
    20812081    }
    2082 #ifdef C_strlcat
     2082#if defined(HAVE_STRLCAT) || !defined(C_strcat)
    20832083    else if(buffer[ 1 ] != 'i') C_strlcat(buffer, C_text(".0"), sizeof(buffer)); /* negative infinity? */
    20842084#else
     
    22602260    (*--scan) = 0;
    22612261
    2262   C_kontinue(k, C_bignum_normalize(result));
     2262  C_kontinue(k, C_bignum_simplify(result));
    22632263}
    22642264
     
    24122412    *scanr =  (*scanx++ & C_BIGNUM_DIGIT_MASK) >> bit_offset;
    24132413  }
    2414   C_kontinue(k, C_bignum_normalize(result));
     2414  C_kontinue(k, C_bignum_simplify(result));
    24152415}
    24162416
     
    24912491    *scan = ((double)rand())/(RAND_MAX + 1.0) * (double)((C_word)1 << C_BIGNUM_DIGIT_LENGTH);
    24922492
    2493   C_kontinue(k, C_bignum_normalize(result));
     2493  C_kontinue(k, C_bignum_simplify(result));
    24942494}
    24952495
     
    25992599                                  digit1 ^ digit2;
    26002600  }
    2601   C_kontinue(k, C_bignum_normalize(result));
     2601  C_kontinue(k, C_bignum_simplify(result));
    26022602}
    26032603
     
    26992699    }
    27002700  }
    2701   C_kontinue(k, C_bignum_normalize(result));
     2701  C_kontinue(k, C_bignum_simplify(result));
    27022702}
    27032703
     
    32093209  assert(C_fitsinbignumhalfdigitp(remainder));
    32103210
    3211   quotient = C_bignum_normalize(quotient);
     3211  quotient = C_bignum_simplify(quotient);
    32123212
    32133213  if (C_truep(return_remainder)) {
     
    33953395    if (C_truep(C_and(return_quotient, return_remainder))) {
    33963396      C_values(4, C_SCHEME_UNDEFINED, k,
    3397                C_bignum_normalize(quotient), C_bignum_normalize(remainder));
     3397               C_bignum_simplify(quotient), C_bignum_simplify(remainder));
    33983398    } else if (C_truep(return_remainder)) {
    3399       C_kontinue(k, C_bignum_normalize(remainder));
     3399      C_kontinue(k, C_bignum_simplify(remainder));
    34003400    } else {
    34013401      assert(C_truep(return_quotient));
    3402       C_kontinue(k, C_bignum_normalize(quotient));
     3402      C_kontinue(k, C_bignum_simplify(quotient));
    34033403    }
    34043404  } else {
     
    34313431    if (C_truep(return_quotient)) {
    34323432      C_values(4, C_SCHEME_UNDEFINED, k,
    3433                C_bignum_normalize(quotient),
    3434                bignum_normalize_shifted(remainder, shift));
    3435     } else {
    3436       C_kontinue(k, bignum_normalize_shifted(remainder, shift));
     3433               C_bignum_simplify(quotient),
     3434               bignum_simplify_shifted(remainder, shift));
     3435    } else {
     3436      C_kontinue(k, bignum_simplify_shifted(remainder, shift));
    34373437    }
    34383438  } else {
    34393439    assert(C_truep(return_quotient));
    3440     C_kontinue(k, C_bignum_normalize(quotient));
     3440    C_kontinue(k, C_bignum_simplify(quotient));
    34413441  }
    34423442}
     
    35703570}
    35713571
    3572 /* Like bignum_normalize, but this also shifts (denormalizes)
    3573  * division-normalized numbers.  Yeah, the terminology clashes here...
     3572/* Like bignum_simplify, but this also shifts division-normalized
     3573 * numbers, to denormalize them to regular bignum representation.
    35743574 */
    35753575static C_word
    3576 bignum_normalize_shifted(C_word big, C_word shift_right)
     3576bignum_simplify_shifted(C_word big, C_word shift_right)
    35773577{
    35783578  C_word length = C_bignum_size(big),
Note: See TracChangeset for help on using the changeset viewer.