[Python-Dev] Memory size overflows

Scott Gilbert xscottg@yahoo.com
Tue, 15 Oct 2002 10:24:09 -0700 (PDT)


The following is really ugly (until you put it in a macro), but would work:

#define HALF_BITS (sizeof(size_t) * 4U)
#define LO_MASK ((((size_t)1) << HALF_BITS)-1)
#define HI_MASK (LO_MASK<<HALF_BITS)

  if (
      /* Tim's fast path */
      ((src1 | src2) & HI_MASK) && (
      /* Ugly slower path */
      (((src1&LO_MASK) * (src2>>HALF_BITS)) & HI_MASK) |
      (((src1>>HALF_BITS) * (src2&LO_MASK)) & HI_MASK) |
      (src1>>HALF_BITS) * (src2>>HALF_BITS))
  ) {
     goto overflow;
  }


Of course it's hoping for some common subexpression elimination from the
compiler.








__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com