pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: stralloc.c,v 1.153 2003/03/14 15:50:47 grubba Exp $ + || $Id: stralloc.c,v 1.154 2003/03/17 16:44:23 grubba Exp $   */      #include "global.h"   #include "stralloc.h"   #include "pike_macros.h"   #include "dynamic_buffer.h"   #include "pike_macros.h"   #include "pike_memory.h"   #include "pike_error.h"   #include "gc.h"
pike.git/src/stralloc.c:17:   #include "bignum.h"   #include "interpret.h"   #include "block_alloc.h"   #include "operators.h"      #include <errno.h>   #include <float.h>   #include <ctype.h>   #include <math.h>    - RCSID("$Id: stralloc.c,v 1.153 2003/03/14 15:50:47 grubba Exp $"); + RCSID("$Id: stralloc.c,v 1.154 2003/03/17 16:44:23 grubba Exp $");      /* #define STRALLOC_USE_PRIMES */      #ifdef STRALLOC_USE_PRIMES      #define SET_HSIZE(X) htable_size=hashprimes[(X)]   #define HMODULO(X) ((X) % htable_size)      #else      #define SET_HSIZE(X) htable_mask=(htable_size=(1<<(X)))-1   #define HMODULO(X) ((X) & (htable_mask))      unsigned INT32 htable_mask;      #endif    -  + #if (SIZEOF_LONG == 4) && defined(_LP64) + /* Kludge for gcc and the system header files not using the same model... */ + #undef LONG_MIN + #undef LONG_MAX + #undef ULONG_MAX + #define LONG_MIN INT_MIN + #define LONG_MAX INT_MAX + #define ULONG_MAX UINT_MAX + #endif      #if PIKE_RUN_UNLOCKED   /* Make this bigger when we get lightweight threads */   #define BUCKET_LOCKS 2048   static PIKE_MUTEX_T *bucket_locks;      #define BUCKETLOCK(HVAL) \    (bucket_locks + (HMODULO(hval__) & (BUCKET_LOCKS-1)))      #define LOCK_BUCKET(HVAL) do { \
pike.git/src/stralloc.c:2216:       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" */    }    +  mul_limit = ((unsigned long)LONG_MAX)/base; +  add_limit = (int) (LONG_MAX % base);    if (neg) { -  mul_limit = (unsigned long) LONG_MIN / base; -  add_limit = (int) ((unsigned long) LONG_MIN % base); +  if (++add_limit == base) { +  add_limit = 0; +  mul_limit++;    } -  else { -  mul_limit = LONG_MAX / base; -  add_limit = (int) (LONG_MAX % base); +     }       val=DIGIT(c);    while(1)    {    INC_PCHARP(str,1);    c=EXTRACT_PCHARP(str);    if(!(WIDE_ISALNUM(c) && (xx=DIGIT(c)) < base)) break; -  if (val > mul_limit || (val == mul_limit && xx > add_limit)) +  if (val > mul_limit || (val == mul_limit && xx > add_limit)) {    overflow = 1; -  else +  } else    val = base * val + xx;    }       if (ptr) *ptr = str;    if (overflow) {    errno = ERANGE;    return neg ? LONG_MIN : LONG_MAX;    }    else {    if (neg) -  return val > (unsigned long) LONG_MAX ? -  -(long) (val - (unsigned long) LONG_MAX) - LONG_MAX : -  -(long) val; +  return (long)(~val + 1);    else    return (long) val;    }   }      PMOD_EXPORT int string_to_svalue_inumber(struct svalue *r,    char * str,    char **ptr,    int base,    int maxlength)