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.69 1999/10/23 00:43:44 noring Exp $"); + RCSID("$Id: stralloc.c,v 1.70 1999/10/23 06:51:32 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:575:    s=begin_shared_string(len);    MEMCPY(s->str, str, len);    link_pike_string(s, h);    }       add_ref(s);       return s;   }    + struct pike_string * debug_make_shared_binary_pcharp(const PCHARP str,int len) + { +  switch(str.shift) +  { +  case 0: +  return make_shared_binary_string((p_wchar0 *)(str.ptr), len); +  case 1: +  return make_shared_binary_string1((p_wchar1 *)(str.ptr), len); +  case 2: +  return make_shared_binary_string2((p_wchar2 *)(str.ptr), len); +  default: +  fatal("Unknown string width!\n"); +  } + } +  + struct pike_string * debug_make_shared_pcharp(const PCHARP str) + { +  return debug_make_shared_binary_pcharp(str, pcharp_strlen(str)); + } +    struct pike_string * debug_make_shared_binary_string1(const p_wchar1 *str,int len)   {    struct pike_string *s;    int h;       if(!find_magnitude1(str,len))    {    /* Wrong size, convert */    s=begin_shared_string(len);    convert_1_to_0(STR0(s),str,len);
pike.git/src/stralloc.c:1776:    {    INC_PCHARP(str,1);    c=EXTRACT_PCHARP(str);    if(!(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, + int string_to_svalue_inumber(struct svalue *r, +  char * str, +  char **ptr, +  int base,    int maxlength)   { -  char *str_start; +  PCHARP tmp; +  int ret=pcharp_to_svalue_inumber(r, +  MKPCHARP(str,0), +  &tmp, +  base, +  maxlength); +  if(ptr) *ptr=(char *)tmp.ptr; +  return ret; + }    -  + int wide_string_to_svalue_inumber(struct svalue *r, +  void * str, +  void **ptr, +  int base, +  int maxlength, +  int shift) + { +  PCHARP tmp; +  int ret=pcharp_to_svalue_inumber(r, +  MKPCHARP(str,shift), +  &tmp, +  base, +  maxlength); +  if(ptr) *ptr=(char *)tmp.ptr; +  return ret; + } +  + int pcharp_to_svalue_inumber(struct svalue *r, +  PCHARP str, +  PCHARP *ptr, +  int base, +  int maxlength) + { +  PCHARP str_start; +     INT_TYPE xx, neg = 0, is_bignum = 0;    INT_TYPE val;    INT_TYPE c;       maxlength--; /* max_length <= 0 means no max length. */    str_start = str;       /* 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 = *str)) +  if(!isalnum(c = EXTRACT_PCHARP(str)))    {    while(ISSPACE(c)) -  c = *++str; +  { +  INC_PCHARP(str,1); +  c = EXTRACT_PCHARP(str); +  }       switch (c)    {    case '-':    neg++;    /* Fall-through. */    case '+': -  c = *++str; +  INC_PCHARP(str,1); +  c = EXTRACT_PCHARP(str);    }    }       if(base == 0)    {    if(c != '0')    base = 10; -  else if(str[1] == 'x' || str[1] == 'X') +  else if(INDEX_PCHARP(str,1) == 'x' || INDEX_PCHARP(str,1) == 'X')    base = 16;    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)    return 0; /* No number formed. */    -  if(base == 16 && c == '0' && isxdigit(((unsigned char *)str)[2]) && -  (str[1] == 'x' || str[1] == 'X')) -  c = *(str += 2); /* Skip over leading "0x" or "0X". */ +  if(base == 16 && c == '0' && +  INDEX_PCHARP(str,2) < 256 && /* Don't trust isxdigit... */ +  isxdigit(INDEX_PCHARP(str,2)) && +  (INDEX_PCHARP(str,1) == 'x' || INDEX_PCHARP(str,1) == 'X')) +  { +  /* Skip over leading "0x" or "0X". */ +  INC_PCHARP(str,2); +  c=EXTRACT_PCHARP(str); +  }    -  for(val = -DIGIT(c); isalnum(c = *++str) && +  for(val = -DIGIT(c); +  isalnum(c = ( INC_PCHARP(str,1),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 */    /* Accumulating a negative value avoids surprises near MIN_TYPE_INT. */    val = base * val - xx;    }       if(ptr != 0)    *ptr = str;       r->u.integer = (neg ? val : -val);      #ifdef AUTO_BIGNUM    if(is_bignum || (!neg && r->u.integer < 0))    { -  struct pike_string *s; -  -  s = begin_shared_string(str - str_start); -  MEMCPY(s->str, str_start, str - str_start); -  s = end_shared_string(s); -  -  push_string(s); +  push_string(make_shared_binary_pcharp(str_start, +  SUBTRACT_PCHARP(str,str_start)));    push_int(base); -  +  +  /* Note that this can concievably throw errors() +  * in some situations that might not be desirable... +  * take care. +  * /Hubbe +  */    convert_stack_top_with_base_to_bignum();       *r = *--sp;    }   #endif /* AUTO_BIGNUM */       return 1;   }      int convert_stack_top_string_to_inumber(int base)   {    struct svalue r;    int i;       if(sp[-1].type != T_STRING)    error("Cannot convert stack top to integer number.\n");    -  i = string_to_svalue_inumber(&r, sp[-1].u.string->str, 0, base, 0); +  i=pcharp_to_svalue_inumber(&r, MKPCHARP_STR(sp[-1].u.string), 0, base, 0);       free_string(sp[-1].u.string);    sp[-1] = r;       return i;   }      /* Convert PCHARP to a double. If ENDPTR is not NULL, a pointer to the    character after the last one used in the number is put in *ENDPTR. */   double STRTOD_PCHARP(PCHARP nptr, PCHARP *endptr)