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.166 2010/09/27 12:16:21 grubba Exp $ + || $Id: stralloc.c,v 1.167 2010/09/29 09:46:54 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.166 2010/09/27 12:16:21 grubba Exp $"); + RCSID("$Id: stralloc.c,v 1.167 2010/09/29 09:46:54 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   
pike.git/src/stralloc.c:535:    for(h=0;h<BUCKET_LOCKS;h++) mt_unlock(bucket_locks + h);   #endif   }      /* Allocation of strings */      /* Allocate some fixed string sizes with BLOCK_ALLOC. */      /* Use the BLOCK_ALLOC() stuff for short strings */    + #undef INIT_BLOCK + #define INIT_BLOCK(NEW_STR) do { \ +  (NEW_STR)->refs = 1; \ +  } while(0) +    #define SHORT_STRING_BLOCK 256   #define SHORT_STRING_THRESHOLD 15 /* % 4 === -1 */      struct short_pike_string0 {    PIKE_STRING_CONTENTS;    p_wchar0 str[SHORT_STRING_THRESHOLD+1];   };      struct short_pike_string1 {    PIKE_STRING_CONTENTS;
pike.git/src/stralloc.c:557:      struct short_pike_string2 {    PIKE_STRING_CONTENTS;    p_wchar2 str[SHORT_STRING_THRESHOLD+1];   };      BLOCK_ALLOC(short_pike_string0, SHORT_STRING_BLOCK)   BLOCK_ALLOC(short_pike_string1, SHORT_STRING_BLOCK)   BLOCK_ALLOC(short_pike_string2, SHORT_STRING_BLOCK)    + #undef INIT_BLOCK + #define INIT_BLOCK(x) +    #define really_free_short_pike_string(s) do { \    if (!s->size_shift) { \    really_free_short_pike_string0((struct short_pike_string0 *)s); \    } else if (s->size_shift == 1) { \    really_free_short_pike_string1((struct short_pike_string1 *)s); \    DO_IF_DEBUG( \    } else if (s->size_shift != 2) { \    Pike_fatal("Unsupported string shift: %d\n", s->size_shift); \    ) \    } else { \
pike.git/src/stralloc.c:595: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    extern int d_flag;    if(d_flag>10)    verify_shared_strings_tables();   #endif    if (len <= SHORT_STRING_THRESHOLD) {    t=(struct pike_string *)alloc_short_pike_string0();    } else {    t=(struct pike_string *)xalloc(len + sizeof(struct pike_string));    } +  t->refs = 0; +  add_ref(t); /* For DMALLOC */    t->str[len]=0;    t->len=len;    t->size_shift=0;    return t;   }      static void link_pike_string(struct pike_string *s, size_t hval)   {    struct pike_string *old;    size_t h;
pike.git/src/stralloc.c:616:    if ((old = internal_findstring(s->str, s->len, s->size_shift, hval))) {    if (old == s) {    Pike_fatal("Relinking already linked string! %s\n", s->str);    } else {    Pike_fatal("Relinking duplicate string! %s\n", s->str);    }    }       LOCK_BUCKET(hval);    h=HMODULO(hval); -  s->refs = 0; +     if (base_table[h] == s) {    Pike_fatal("String circularity imminent (LINK).\n");    }    s->next = base_table[h];    base_table[h] = s;    s->hval=hval;    num_strings++;    UNLOCK_BUCKET(hval);       if(num_strings > MAX_AVG_LINK_LENGTH * htable_size)
pike.git/src/stralloc.c:734: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    } else if (shift != 2) {    Pike_fatal("Unsupported string shift: %d\n", shift);   #endif /* PIKE_DEBUG */    } else {    t = (struct pike_string *)alloc_short_pike_string2();    }    } else {    t=(struct pike_string *)xalloc((len<<shift) + sizeof(struct pike_string));    } +  t->refs = 0; +  add_ref(t); /* For DMALLOC */    t->len=len;    t->size_shift=shift;    low_set_index(t,len,0);    return t;   }      /*    * This function assumes that the shift size is already the minimum it    * can be.    */
pike.git/src/stralloc.c:762: Inside #if defined(PIKE_DEBUG)
   s2 = internal_findstring(s->str, len, s->size_shift, h);   #ifdef PIKE_DEBUG    if(s2==s)    Pike_fatal("end_shared_string called twice! (or something like that)\n");   #endif       if(s2)    {    really_free_pike_string(s);    s = s2; +  add_ref(s);    }else{    link_pike_string(s, h);    } -  add_ref(s); +        return s;      }      /*    * This function checks if the shift size can be decreased before    * entering the string in the shared string table    */   PMOD_EXPORT struct pike_string *end_shared_string(struct pike_string *s)
pike.git/src/stralloc.c:850:   {    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);    link_pike_string(s, h); +  } else { +  add_ref(s);    }    -  add_ref(s); -  +     return s;   }      PMOD_EXPORT struct pike_string * debug_make_shared_binary_pcharp(const PCHARP str,size_t len)   {    switch(str.shift)    {    case 0:    return make_shared_binary_string((char *)(str.ptr), len);    case 1:
pike.git/src/stralloc.c:905:    }       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);    link_pike_string(s, h); +  } else { +  add_ref(s);    }    -  add_ref(s); -  +     return s;   }      PMOD_EXPORT struct pike_string * debug_make_shared_binary_string2(const p_wchar2 *str,size_t len)   {    struct pike_string *s;    ptrdiff_t h;       switch(find_magnitude2(str,len))    {
pike.git/src/stralloc.c:940:    }       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);    link_pike_string(s, h); +  } else { +  add_ref(s);    }    -  add_ref(s); -  +     return s;   }      PMOD_EXPORT struct pike_string *debug_make_shared_string(const char *str)   {    return make_shared_binary_string(str, strlen(str));   }      PMOD_EXPORT struct pike_string *debug_make_shared_string0(const p_wchar0 *str)   {
pike.git/src/stralloc.c:1642:    /* Doesn't change hash value - sneak it in there */    low_set_index(a,index,c);    unlink_pike_string(a);    old = internal_findstring(a->str, a->len, a->size_shift, a->hval);    if (old) {    /* The new string is equal to some old string. */    really_free_pike_string(a);    add_ref(a = old);    } else {    link_pike_string(a, a->hval); -  add_ref(a); +     }    return a;    }else{    unlink_pike_string(a);    low_set_index(a,index,c);    return end_shared_string(a);    }    }else{    struct pike_string *r;    r=begin_wide_shared_string(a->len,a->size_shift);