pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:11:   #include "pike_macros.h"   #include "pike_memory.h"   #include "pike_error.h"   #include "gc.h"   #include "stuff.h"   #include "bignum.h"   #include "interpret.h"   #include "operators.h"   #include "pike_float.h"   #include "block_allocator.h" - #include "port.h" +       #include <errno.h>   #include <float.h>   #include <ctype.h>   #include <math.h>      #define SET_HSIZE(X) htable_mask=(htable_size=(1<<(X)))-1   #define HMODULO(X) ((X) & (htable_mask))      static unsigned INT32 htable_mask;
pike.git/src/stralloc.c:479: Inside #if defined(PIKE_DEBUG)
   locate_problem(has_zero_refs);    Pike_fatal("String with no references.\n");    }   #endif    debug_malloc_touch(curr);       if ( len == curr->len &&    size_shift == curr->size_shift &&    hval == curr->hval &&    ( curr->str == s || -  !MEMCMP(curr->str, s,len<<size_shift))) /* found it */ +  !memcmp(curr->str, s,len<<size_shift))) /* found it */    {    /* *prev = curr->next; */    /* curr->next = *base; */    /* *base = curr; */    return curr; /* pointer to string */    }    depth++;    if (curr->len > (ptrdiff_t)hash_prefix_len)    prefix_depth++;    }
pike.git/src/stralloc.c:961:      PMOD_EXPORT struct pike_string * debug_make_shared_binary_string(const char *str,size_t len)   {    struct pike_string *s;    ptrdiff_t h = StrHash(str, len);       s = internal_findstring(str,len,0,h);    if (!s)    {    s=begin_shared_string(len); -  MEMCPY(s->str, str, len); +  memcpy(s->str, str, len);    link_pike_string(s, h);    } else {    add_ref(s);    }       return s;   }      PMOD_EXPORT struct pike_string * debug_make_shared_binary_pcharp(const PCHARP str,size_t len)   {
pike.git/src/stralloc.c:1018:    convert_1_to_0(STR0(s),str,len);    return end_shared_string(s);    }       h=low_do_hash(str, len, 1);       s = internal_findstring((char *)str,len,1,h);    if (!s)    {    s=begin_wide_shared_string(len,1); -  MEMCPY(s->str, str, len<<1); +  memcpy(s->str, str, len<<1);    link_pike_string(s, h);    } else {    add_ref(s);    }       return s;   }      PMOD_EXPORT struct pike_string * debug_make_shared_binary_string2(const p_wchar2 *str,size_t len)   {
pike.git/src/stralloc.c:1053:    convert_2_to_1(STR1(s),str,len);    return end_shared_string(s); /* not entirely optimal */    }       h=low_do_hash(str, len, 2);       s = internal_findstring((char *)str,len,2,h);    if (!s)    {    s=begin_wide_shared_string(len,2); -  MEMCPY(s->str, str, len<<2); +  memcpy(s->str, str, len<<2);    link_pike_string(s, h);    } else {    add_ref(s);    }       return s;   }      PMOD_EXPORT struct pike_string *debug_make_shared_string(const char *str)   {
pike.git/src/stralloc.c:1512:      /*** String compare functions ***/      /* does not take locale into account */   int low_quick_binary_strcmp(const char *a, ptrdiff_t alen,    const char *b, ptrdiff_t blen)   {    int tmp;    if(alen > blen)    { -  tmp=MEMCMP(a, b, blen); +  tmp=memcmp(a, b, blen);    if(tmp) return tmp;    return 1;    }else if(alen < blen){ -  tmp=MEMCMP(a, b, alen); +  tmp=memcmp(a, b, alen);    if(tmp) return tmp;    return -1;    }else{ -  return MEMCMP(a, b, alen); +  return memcmp(a, b, alen);    }   }         /* does not take locale into account */   ptrdiff_t generic_quick_binary_strcmp(const char *a,    ptrdiff_t alen, int asize,    const char *b,    ptrdiff_t blen, int bsize)   { -  if(!asize && !bsize) -  { -  int tmp; -  /* FIXME: Does MEMCMP() guarantee that the characters -  * are compared as unsigned? -  * /grubba 2006-03-11 -  */ -  if(alen > blen) -  { -  tmp=MEMCMP(a, b, blen); -  if(tmp) return tmp; -  return 1; -  }else if(alen < blen){ -  tmp=MEMCMP(a, b, alen); -  if(tmp) return tmp; -  return -1; -  }else{ -  return MEMCMP(a, b, alen); -  } -  }else{ +     ptrdiff_t pos; -  +  if(!asize && !bsize) +  return low_quick_binary_strcmp(a, alen, b, blen); +     for(pos=0;pos< MINIMUM(alen,blen) ;pos++)    {    p_wchar2 ac=generic_extract(a,asize,pos);    p_wchar2 bc=generic_extract(b,bsize,pos);    if(ac != bc) {    if (ac < bc) return -1;    return 1;    }    }    return alen-blen;   } - } +       /* Does not take locale into account    *    * Similar to (and could be used in place of) generic_quick_binary_strcmp(),    * but returns +/- (offset + 1) to the first difference beween the strings.    *    * This can be used by eg replace_many() to speed up the comparisons.    */   ptrdiff_t generic_find_binary_prefix(const char *a,    ptrdiff_t alen, int asize,
pike.git/src/stralloc.c:1612:    CASE(2,2);   #undef CASE    }    if (alen == blen) return 0;    if (alen < blen) return ~alen;    return blen+1;   }      PMOD_EXPORT int c_compare_string(struct pike_string *s, char *foo, int len)   { -  return s->len == len && s->size_shift == 0 && !MEMCMP(s->str,foo,len); +  return s->len == len && s->size_shift == 0 && !memcmp(s->str,foo,len);   }    - #ifndef HAVE_STRCOLL - /* No locale function available */ - static int low_binary_strcmp(char *a, ptrdiff_t alen, -  char *b, ptrdiff_t blen) - { -  low_quick_binary_strcmp(a,alen,b,blen); - } - #else -  +    /* takes locale into account */   static int low_binary_strcmp(char *a, ptrdiff_t alen,    char *b, ptrdiff_t blen)   {    while(alen>0 && blen>0)    {    int tmp1 = strcoll(a,b);    ptrdiff_t tmp2;    if(tmp1) return (int)tmp1;    tmp2 = strlen(a)+1;    a += tmp2;    b += tmp2;    alen -= tmp2;    blen -= tmp2;    }    if(alen==blen) return 0;    if(alen > blen) return 1;    return -1;   } - #endif +       /* Does not take locale into account */ -  +    PMOD_EXPORT ptrdiff_t my_quick_strcmp(struct pike_string *a,    struct pike_string *b)   {    if(a==b) return 0;       return generic_quick_binary_strcmp(a->str, a->len, a->size_shift,    b->str, b->len, b->size_shift);   }      /* Does take locale into account */
pike.git/src/stralloc.c:1674:    return low_binary_strcmp(a->str,a->len,b->str,b->len);       default:    {    ptrdiff_t e, l = MINIMUM(a->len, b->len);    for(e=0;e<l;e++)    {    INT32 ac=index_shared_string(a,e);    INT32 bc=index_shared_string(b,e);    - #ifdef HAVE_STRCOLL +     if(ac < 256 && bc < 256)    {    char atmp[2],btmp[2];    int tmp;    atmp[0]=ac;    btmp[0]=bc;    atmp[1]=0;    btmp[1]=0;    if((tmp=strcoll(atmp,btmp)))    return tmp; -  }else - #endif -  if(ac-bc) return ac-bc; +     } -  +  else if(ac-bc) +  return ac-bc; +  }    return a->len - b->len;    }    }   }      struct pike_string *realloc_unlinked_string(struct pike_string *a,    ptrdiff_t size)   {    char * s = NULL;    size_t nbytes = (size_t)(size+1) << a->size_shift;
pike.git/src/stralloc.c:1761:   /* Returns an unlinked string ready for end_shared_string */   static struct pike_string *realloc_shared_string(struct pike_string *a,    ptrdiff_t size)   {    if(string_may_modify(a))    {    unlink_pike_string(a);    return realloc_unlinked_string(a, size);    }else{    struct pike_string *r=begin_wide_shared_string(size,a->size_shift); -  MEMCPY(r->str, a->str, a->len<<a->size_shift); +  memcpy(r->str, a->str, a->len<<a->size_shift);    r->flags |= a->flags & STRING_CHECKED_MASK;    r->min = a->min;    r->max = a->max;    free_string(a);    return r;    }   }      struct pike_string *new_realloc_shared_string(struct pike_string *a, INT32 size, int shift)   {
pike.git/src/stralloc.c:1937:    } else {    link_pike_string(a, a->hval);    }    }else{    a = end_shared_string(a);    }    return a;    }else{    struct pike_string *r;    r=begin_wide_shared_string(a->len,a->size_shift); -  MEMCPY(r->str, a->str, a->len << a->size_shift); +  memcpy(r->str, a->str, a->len << a->size_shift);    low_set_index(r,index,c);    free_string(a);    return end_shared_string(r);    }   }      PMOD_EXPORT void set_flags_for_add( struct pike_string *ret,    unsigned char aflags,    unsigned char amin,    unsigned char amax,
pike.git/src/stralloc.c:2011:   }      PMOD_EXPORT struct pike_string *add_and_free_shared_strings(struct pike_string *a,    struct pike_string *b)   {    ptrdiff_t alen = a->len;    if(a->size_shift == b->size_shift)    {    a = realloc_shared_string(a, alen + b->len);    update_flags_for_add( a, b ); -  MEMCPY(a->str+(alen<<a->size_shift),b->str,b->len<<b->size_shift); +  memcpy(a->str+(alen<<a->size_shift),b->str,b->len<<b->size_shift);    free_string(b);    a->flags |= STRING_NOT_HASHED;    return end_shared_string(a);    }else{    struct pike_string *ret=add_shared_strings(a,b);    free_string(a);    free_string(b);    return ret;    }   }
pike.git/src/stralloc.c:2418:   {    init_string_builder_alloc(s, 256, mag);   }      PMOD_EXPORT void init_string_builder_copy(struct string_builder *to,    struct string_builder *from)   {    to->malloced = from->malloced;    to->s = begin_wide_shared_string (from->malloced, from->s->size_shift);    to->s->len = from->s->len; -  MEMCPY (to->s->str, from->s->str, (from->s->len + 1) << from->s->size_shift); +  memcpy (to->s->str, from->s->str, (from->s->len + 1) << from->s->size_shift);    to->known_shift = from->known_shift;   }      /* str becomes invalid if successful (i.e. nonzero returned),    * otherwise nothing happens. */   PMOD_EXPORT int init_string_builder_with_string (struct string_builder *s,    struct pike_string *str)   {    if (string_may_modify(str)) {    /* Unlink the string and use it as buffer directly. */
pike.git/src/stralloc.c:2512:    Pike_fatal("Non-positive count in call to string_builder_putchars().\n");    if (!count) return;       string_build_mkspace(s, count, mag);    if (mag > s->known_shift) {    s->known_shift = mag;    }       switch (s->s->size_shift) {    case 0: -  MEMSET (STR0 (s->s) + s->s->len, ch, count); +  memset (STR0 (s->s) + s->s->len, ch, count);    break;    case 1: {    int i;    for (i = 0; i < count; i++)    (STR1 (s->s) + s->s->len)[i] = ch;    break;    }    case 2: {    int i;    for (i = 0; i < count; i++)
pike.git/src/stralloc.c:2667: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    if(len<=0)    Pike_fatal("Cannot fill with zero length strings!\n");   #endif    if(howmany<=0) return;       if(!s->s->size_shift &&    len == 1 &&    (!from.shift || !min_magnitude(EXTRACT_PCHARP(from))))    { -  MEMSET(string_builder_allocate(s,howmany,0), +  memset(string_builder_allocate(s,howmany,0),    EXTRACT_PCHARP(from),    howmany);    /* Ensure NUL-termination */    s->s->str[s->s->len << s->s->size_shift] = 0;    return;    }       if ((shift = from.shift) > s->s->size_shift) {    /* Check if we really need the extra magnitude. */    /* FIXME: What about offset? */
pike.git/src/stralloc.c:2705:    PCHARP to;    tmp=MINIMUM(howmany, len);    to=MKPCHARP_STR_OFF(s->s,s->s->len);    generic_memcpy(to,from, tmp);    s->s->len+=tmp;    howmany-=tmp;       while(howmany > 0)    {    tmp = MINIMUM(len, howmany); -  MEMCPY(s->s->str + (s->s->len << s->s->size_shift), +  memcpy(s->s->str + (s->s->len << s->s->size_shift),    to.ptr,    tmp << s->s->size_shift);    len+=tmp;    howmany-=tmp;    s->s->len+=tmp;    }    }    /* Ensure NUL-termination */    s->s->str[s->s->len << s->s->size_shift] = 0;   }
pike.git/src/stralloc.c:3296:    low_set_index(s->s,s->s->len,0);    if(s->known_shift == s->s->size_shift)    return low_end_shared_string(s->s);    return end_shared_string(s->s);   }      PMOD_EXPORT PCHARP MEMCHR_PCHARP(PCHARP ptr, int chr, ptrdiff_t len)   {    switch(ptr.shift)    { -  case 0: return MKPCHARP(MEMCHR(ptr.ptr,chr,len),0); +  case 0: return MKPCHARP(memchr(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);    }   #ifdef PIKE_DEBUG    Pike_fatal("Illegal shift in MEMCHR_PCHARP.\n");   #endif    return MKPCHARP(0,0); /* make wcc happy */   }      #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, int base)   { -  /* Note: Code duplication in STRTOL and pcharp_to_svalue_inumber. */ +  /* Note: Code duplication in strtol and pcharp_to_svalue_inumber. */       unsigned long val, mul_limit;    int c;    int xx, neg = 0, add_limit, overflow = 0;       if (ptr) *ptr = str;    if (base < 0 || base > MBASE) return 0;    if (!WIDE_ISALNUM(c = EXTRACT_PCHARP(str)))    {    while (WIDE_ISSPACE(c))
pike.git/src/stralloc.c:3464:    if(ptr) *(p_wchar0 **)ptr=tmp.ptr;    return ret;   }      PMOD_EXPORT int pcharp_to_svalue_inumber(struct svalue *r,    PCHARP str,    PCHARP *ptr,    int base,    ptrdiff_t maxlength)   { -  /* Note: Code duplication in STRTOL and STRTOL_PCHARP. */ +  /* Note: Code duplication in strtol and STRTOL_PCHARP. */       PCHARP str_start;       unsigned INT_TYPE val, mul_limit;    int c;    int xx, neg = 0, add_limit, overflow = 0;       maxlength--; /* max_length <= 0 means no max length. */    str_start = str;   
pike.git/src/stralloc.c:3605:    free_string(Pike_sp[-1].u.string);    Pike_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. */   PMOD_EXPORT double STRTOD_PCHARP(PCHARP nptr, PCHARP *endptr)   { -  /* Note: Code duplication in STRTOD. */ +  /* Note: Code duplication in strtod. */       register PCHARP s;    short int sign;       /* The number so far. */    double num;       int got_dot; /* Found a decimal point. */    int got_digit; /* Seen any digits. */   
pike.git/src/stralloc.c:3689:    long int exp;       errno = 0;    INC_PCHARP(s,1);    exp = STRTOL_PCHARP(s, &end, 10);    if (errno == ERANGE)    {    /* The exponent overflowed a `long int'. It is probably a safe    assumption that an exponent that cannot be represented by    a `long int' exceeds the limits of a `double'. */ -  /* NOTE: Don't trust the value returned from STRTOL. +  /* NOTE: Don't trust the value returned from strtol.    * We need to find the sign of the exponent by hand.    */    p_wchar2 c;    while(WIDE_ISSPACE(c = EXTRACT_PCHARP(s))) {    INC_PCHARP(s, 1);    }    if (endptr != NULL)    *endptr = end;    if (c == '-')    goto underflow;