Lazy mpz allocation

Torbjörn Granlund tg at gmplib.org
Mon Aug 31 19:20:43 UTC 2015


nisse at lysator.liu.se (Niels Möller) writes:

  tg at gmplib.org (Torbjörn Granlund) writes:
  
  > (We should use 'attribute ((visibility ("hidden")))' for the the
  > constant zero limbs at any rate.  I'll commit a basic patch for that
  > soonish.)
  
  Maybe it should have a more interesting value than zero, to help catch
  bugs if it is used when it shouldn't. And when running valgrind, it
  could be explicitly marked as readable but undefined, to generate
  valgrind warnings if any branch or memory access depends on the value.
  
Unfortunately, the manual sayd "Initialize x, and set its value to 0."
about mpz_init.

  It's tempting to try to rely on it being zero, like eliminating the
  _mp_size != 0 test in mpz_odd_p, but that's broken unless all code that
  may assign zero to _mp_size makes sure that _mp_size == 0 implies
  _mp_d[0] == 0, which I doubt is a good idea.
  
I don't think we do that, nor should we.

-- 
Torbjörn
Please encrypt, key id 0xC8601622


More information about the gmp-devel mailing list