Branch: Tag:

2016-12-17

2016-12-17 23:00:50 by Martin Nilsson <nilsson@fastmail.com>

Revert "Retired all the WIDE_* macros except WIDE_ISALNUM"

This reverts commit 8d564e44ad50772ea768815a2c82042ee5e4de1b.

19:   #include "pike_types.h"   #include "block_allocator.h"   #include "whitespace.h" - #include "stuff.h" +       #include <errno.h>   #include <ctype.h>
3247:    UNREACHABLE(MKPCHARP(0,0));   }    - #define DIGIT(x) ( (x)<256 ? hexdecode[x] : 16 ) + #define DIGIT(x) (WIDE_ISDIGIT(x) ? (x) - '0' : \ +  WIDE_ISLOWER(x) ? (x) + 10 - 'a' : (x) + 10 - 'A')   #define MBASE ('z' - 'a' + 1 + 10)    - PMOD_EXPORT long STRTOL_PCHARP(PCHARP str, PCHARP *ptr, unsigned int base) + PMOD_EXPORT long STRTOL_PCHARP(PCHARP str, PCHARP *ptr, int base)   {    /* Note: Code duplication in strtol and pcharp_to_svalue_inumber. */       unsigned long val, mul_limit;    int c; -  unsigned add_limit, xx; -  int neg = 0, overflow = 0; +  int xx, neg = 0, add_limit, overflow = 0;       if (ptr) *ptr = str; -  if (base > MBASE) return 0; +  if (base < 0 || base > MBASE) return 0;    if (!WIDE_ISALNUM(c = EXTRACT_PCHARP(str)))    {    while (wide_isspace(c))
3289:    base = 8;    }    -  if ((val = DIGIT(c)) >= base) +  if (!WIDE_ISALNUM(c) || (xx = DIGIT(c)) >= base)    return 0; /* no number formed */    if (base == 16 && c == '0' && isxdigit(INDEX_PCHARP(str,2)) &&    (INDEX_PCHARP(str,1) == 'x' || INDEX_PCHARP(str,1) == 'X'))    {    INC_PCHARP(str,2);    c = EXTRACT_PCHARP(str); /* skip over leading "0x" or "0X" */ -  if ((val = DIGIT(c)) >= base) -  return 0; /* no number formed */ +     }       mul_limit = ((unsigned long)LONG_MAX)/base;
3309:    }    }    +  val=DIGIT(c);    while(1)    {    INC_PCHARP(str,1);    c=EXTRACT_PCHARP(str); -  if((xx=DIGIT(c)) >= base) break; +  if(!(WIDE_ISALNUM(c) && (xx=DIGIT(c)) < base)) break;    if (val > mul_limit || (val == mul_limit && xx > add_limit)) {    overflow = 1;    } else
3385:   PMOD_EXPORT int pcharp_to_svalue_inumber(struct svalue *r,    PCHARP str,    PCHARP *ptr, -  unsigned int base, +  int base,    ptrdiff_t maxlength)   {    /* Note: Code duplication in strtol and STRTOL_PCHARP. */
3394:       unsigned INT_TYPE val, mul_limit;    int c; -  unsigned int xx, add_limit; -  int neg = 0, overflow = 0; +  int xx, neg = 0, add_limit, overflow = 0;       maxlength--; /* max_length <= 0 means no max length. */    str_start = str;
3405:    if(ptr != 0)    *ptr = str;    -  if(MBASE < base) +  if(base < 0 || MBASE < base)    return 0;       if(!WIDE_ISALNUM(c = EXTRACT_PCHARP(str)))
3439:    base = 8;    }    -  if((val=DIGIT(c)) >= base) +  /* +  * For any base > 10, the digits incrementally following +  * 9 are assumed to be "abc...z" or "ABC...Z". +  */ +  if(!WIDE_ISALNUM(c) || (xx = DIGIT(c)) >= base)    return 0; /* No number formed. */       if(c == '0' &&
3451:    /* Skip over leading "0x", "0X", "0b" or "0B". */    INC_PCHARP(str,2);    c=EXTRACT_PCHARP(str); -  if((val=DIGIT(c)) >= base) -  return 0; /* No number formed. */ +     }    str_start=str;   
3465:    add_limit = (int) (MAX_INT_TYPE % base);    }    -  for(; +  for(val = DIGIT(c);    (INC_PCHARP(str,1), WIDE_ISALNUM(c = EXTRACT_PCHARP(str) )) &&    (xx = DIGIT(c)) < base &&    0 != maxlength--; )
3564:    exponent = 0;    for (;; INC_PCHARP(s,1))    { -  if (EXTRACT_PCHARP(s)<256 && hexdecode[EXTRACT_PCHARP(s)]) +  if (EXTRACT_PCHARP(s)<256 && WIDE_ISDIGIT (EXTRACT_PCHARP(s)))    {    got_digit = 1;