pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:18:      #include <errno.h>   #include <float.h>   #include <ctype.h>   #include <math.h>      #ifndef HUGE   #define HUGE HUGE_VAL   #endif /*!HUGE*/    - RCSID("$Id: stralloc.c,v 1.80 2000/03/20 21:00:04 hubbe Exp $"); + RCSID("$Id: stralloc.c,v 1.81 2000/04/01 07:27:02 hubbe Exp $");      #define BEGIN_HASH_SIZE 997   #define MAX_AVG_LINK_LENGTH 3      /* Experimental dynamic hash length */   #ifndef HASH_PREFIX   static unsigned int HASH_PREFIX=64;   static unsigned int need_more_hash_prefix=0;   #endif   
pike.git/src/stralloc.c:1748:    switch(ptr.shift)    {    case 0: return MKPCHARP(MEMCHR0(ptr.ptr,chr,len),0);    case 1: return MKPCHARP(MEMCHR1((p_wchar1 *)ptr.ptr,chr,len),1);    case 2: return MKPCHARP(MEMCHR2((p_wchar2 *)ptr.ptr,chr,len),2);    }    fatal("Illegal shift in MEMCHR_PCHARP.\n");    return MKPCHARP(0,0); /* make wcc happy */   }    - #define DIGIT(x) (isdigit(x) ? (x) - '0' : \ -  islower(x) ? (x) + 10 - 'a' : (x) + 10 - 'A') + #define DIGIT(x) (WIDE_ISDIGIT(x) ? (x) - '0' : \ +  WIDE_ISLOWER(x) ? (x) + 10 - 'a' : (x) + 10 - 'A')   #define MBASE ('z' - 'a' + 1 + 10)      long STRTOL_PCHARP(PCHARP str, PCHARP *ptr, int base)   {    register long val;    register int c;    int xx, neg = 0;       if (ptr) *ptr = str;    if (base < 0 || base > MBASE) return 0; -  if (!isalnum(c = EXTRACT_PCHARP(str))) +  if (!WIDE_ISALNUM(c = EXTRACT_PCHARP(str)))    {    while (ISSPACE(c))    {    INC_PCHARP(str,1);    c=EXTRACT_PCHARP(str);    }    switch (c)    {    case '-':    neg++;
pike.git/src/stralloc.c:1787:    if (!base)    {    if (c != '0')    base = 10;    else if (INDEX_PCHARP(str,1) == 'x' || INDEX_PCHARP(str,1) == 'X')    base = 16;    else    base = 8;    }    -  if (!isalnum(c) || (xx = 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" */    }    val=-DIGIT(c);    while(1)    {    INC_PCHARP(str,1);    c=EXTRACT_PCHARP(str); -  if(!(isalnum(c) && (xx=DIGIT(c)) < base)) break; +  if(!(WIDE_ISALNUM(c) && (xx=DIGIT(c)) < base)) break;    val = base * val - xx;    }    if (ptr) *ptr = str;    return (neg ? val : -val);   }      int string_to_svalue_inumber(struct svalue *r,    char * str,    char **ptr,    int base,
pike.git/src/stralloc.c:1865:    /* In case no number is formed. */    r->type = T_INT;    r->subtype = NUMBER_NUMBER;    r->u.integer = 0;    if(ptr != 0)    *ptr = str;       if(base < 0 || MBASE < base)    return 0;    -  if(!isalnum(c = EXTRACT_PCHARP(str))) +  if(!WIDE_ISALNUM(c = EXTRACT_PCHARP(str)))    { -  while(ISSPACE(c)) +  while(WIDE_ISSPACE(c))    {    INC_PCHARP(str,1);    c = EXTRACT_PCHARP(str);    }       switch (c)    {    case '-':    neg++;    /* Fall-through. */
pike.git/src/stralloc.c:1902:    else if(INDEX_PCHARP(str,1) == 'b' || INDEX_PCHARP(str,1) == 'B')    base = 2;    else    base = 8;    }       /*    * For any base > 10, the digits incrementally following    * 9 are assumed to be "abc...z" or "ABC...Z".    */ -  if(!isalnum(c) || (xx = DIGIT(c)) >= base) +  if(!WIDE_ISALNUM(c) || (xx = DIGIT(c)) >= base)    return 0; /* No number formed. */       if(implicit_base && c == '0' &&    INDEX_PCHARP(str,2) < 256 && /* Don't trust isxdigit... */    isxdigit(INDEX_PCHARP(str,2)) &&    ((base==16 && (INDEX_PCHARP(str,1)=='x' || INDEX_PCHARP(str,1)=='X')) ||    (base==2 && (INDEX_PCHARP(str,1)=='b' || INDEX_PCHARP(str,1)=='B'))))    {    /* Skip over leading "0x", "0X", "0b" or "0B". */    INC_PCHARP(str,2);    c=EXTRACT_PCHARP(str);    }       for(val = -DIGIT(c); -  isalnum(c = ( INC_PCHARP(str,1),EXTRACT_PCHARP(str) )) && +  (INC_PCHARP(str,1), WIDE_ISALNUM(c = EXTRACT_PCHARP(str) )) &&    (xx = DIGIT(c)) < base &&    0 != maxlength--; )    {   #ifdef AUTO_BIGNUM    if(INT_TYPE_MUL_OVERFLOW(val, base))    is_bignum = 1;   #endif /* AUTO_BIGNUM */    val = base * val;    /* Accumulating a negative value avoids surprises near MIN_TYPE_INT. */   #ifdef AUTO_BIGNUM
pike.git/src/stralloc.c:2016:       if (nptr.ptr == NULL)    {    errno = EINVAL;    goto noconv;    }       s = nptr;       /* Eat whitespace. */ -  while (EXTRACT_PCHARP(s) <256 && ISSPACE(EXTRACT_PCHARP(s))) INC_PCHARP(s,1); +  while (EXTRACT_PCHARP(s) <256 && WIDE_ISSPACE(EXTRACT_PCHARP(s))) INC_PCHARP(s,1);       /* Get the sign. */    sign = EXTRACT_PCHARP(s) == '-' ? -1 : 1;    if (EXTRACT_PCHARP(s) == '-' || EXTRACT_PCHARP(s) == '+')    INC_PCHARP(s,1);       num = 0.0;    got_dot = 0;    got_digit = 0;    exponent = 0;    for (;; INC_PCHARP(s,1))    { -  if (EXTRACT_PCHARP(s)<256 && isdigit (EXTRACT_PCHARP(s))) +  if (EXTRACT_PCHARP(s)<256 && WIDE_ISDIGIT (EXTRACT_PCHARP(s)))    {    got_digit = 1;       /* Make sure that multiplication by 10 will not overflow. */    if (num > DBL_MAX * 0.1)    /* The value of the digit doesn't matter, since we have already    gotten as many digits as can be represented in a `double'.    This doesn't necessarily mean the result will overflow.    The exponent may reduce it to within range.   
pike.git/src/stralloc.c:2114:    {    if (num < DBL_MIN * pow(10.0, (double) -exponent))    goto underflow;    }    else if (exponent > 0)    {    if (num > DBL_MAX * pow(10.0, (double) -exponent))    goto overflow;    }    +  if(exponent < 0 && exponent >-100) /* make sure we don't underflow */ +  num /= pow(10.0, (double) -exponent); +  else    num *= pow(10.0, (double) exponent);       return num * sign;       overflow:    /* Return an overflow error. */    errno = ERANGE;    return HUGE * sign;       underflow: