Branch: Tag:

2016-01-18

2016-01-18 01:00:24 by Martin Nilsson <nilsson@fastmail.com>

Don't call f_random_string directly.

30:   #include "bignum.h"   #include "operators.h"   #include "gc.h" + #include "mapping.h" + #include "constants.h"      #if GMP_NUMB_BITS != SIZEOF_MP_LIMB_T * CHAR_BIT   #error Cannot cope with GMP using nail bits.
2055:    Pike_error("Random on negative number.\n");       push_object(res=fast_clone_object(THIS_PROGRAM)); +  push_svalue(simple_mapping_string_lookup(get_builtin_constants(), +  "random_string")); +  if(TYPEOF(sp[-1])!=T_FUNCTION) +  Pike_error("Unable to resolve random function.\n");    /* We add four to assure reasonably uniform randomness */    push_int(mpz_size(THIS)*sizeof(mp_limb_t) + 4); -  f_random_string(1); - #ifdef PIKE_DEBUG +  apply_svalue(&sp[-2], 1);    if (TYPEOF(sp[-1]) != T_STRING) {    Pike_error("random_string(%ld) returned non string.\n",    mpz_size(THIS)*sizeof(mp_limb_t) + 4);    } - #endif +  if ((unsigned)sp[-1].u.string->len != mpz_size(THIS)*sizeof(mp_limb_t) + 4) +  Pike_error("Wrong size random string generated.\n"); +  stack_pop_keep_top(); +     get_mpz_from_digits(OBTOMPZ(res), sp[-1].u.string, 256);    pop_stack();    mpz_fdiv_r(OBTOMPZ(res), OBTOMPZ(res), THIS); /* modulo */