pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:8:   #include "pike_macros.h"   #include "dynamic_buffer.h"   #include "pike_macros.h"   #include "pike_memory.h"   #include "error.h"   #include "gc.h"   #include "stuff.h"      #include <ctype.h>    - RCSID("$Id: stralloc.c,v 1.49 1998/10/29 16:37:33 grubba Exp $"); + RCSID("$Id: stralloc.c,v 1.50 1998/11/22 11:03:18 hubbe Exp $");      #define BEGIN_HASH_SIZE 997   #define MAX_AVG_LINK_LENGTH 3   #define HASH_PREFIX 64      unsigned INT32 htable_size=0;   static unsigned int hashprimes_entry=0;   static struct pike_string **base_table=0;   static unsigned INT32 full_hash_value;   unsigned INT32 num_strings=0;
pike.git/src/stralloc.c:83:    case 0: return ((unsigned char *)str)[pos];    case 1: return ((unsigned INT16 *)str)[pos];    case 2: return ((unsigned INT32 *)str)[pos];    }    fatal("Illegal shift size!\n");    return 0;   }      INLINE unsigned INT32 index_shared_string(struct pike_string *s, int pos)   { - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(pos > s->len || pos<0) {    if (s->len) {    fatal("String index %d is out of range [0 - %d]!\n", pos, s->len-1);    } else {    fatal("Attempt to index the empty string with %d!\n", pos);    }    }   #endif    return generic_extract(s->str,s->size_shift,pos);   }      INLINE void low_set_index(struct pike_string *s, int pos, int value)   { - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(pos > s->len || pos<0)    fatal("string index out of range!\n");       if(pos == s->len && value)    fatal("string zero termination foul!\n");   #endif    switch(s->size_shift)    {    case 0: STR0(s)[pos]=value; break;    case 1: STR1(s)[pos]=value; break;    case 2: STR2(s)[pos]=value; break;    default:    fatal("Illegal shift size!\n");    }   }    - #ifdef DEBUG + #ifdef PIKE_DEBUG   struct INLINE pike_string *debug_check_size_shift(struct pike_string *a,int shift)   {    if(a->size_shift != shift)    fatal("Wrong STRX macro used!\n");    return a;   }   #endif      #define CONVERT(FROM,TO) \   INLINE void PIKE_CONCAT4(convert_,FROM,_to_,TO)(PIKE_CONCAT(p_wchar,TO) *to, const PIKE_CONCAT(p_wchar,FROM) *from, int len) \
pike.git/src/stralloc.c:201:    }   }      INLINE void pike_string_cpy(PCHARP to,    struct pike_string *from)   {    generic_memcpy(to,MKPCHARP_STR(from),from->len);   }       - #ifdef DEBUG + #ifdef PIKE_DEBUG   #ifdef DEBUG_MALLOC   #define DM(X) X   #else   #define DM(X)   #endif      static void locate_problem(int (*isproblem)(struct pike_string *))   {    unsigned INT32 e;    struct pike_string *s;
pike.git/src/stralloc.c:265:   \*/   static struct pike_string *internal_findstring(const char *s,    int len,    int size_shift,    int h)   {    struct pike_string *curr,**prev, **base;       for(base = prev = base_table + h;( curr=*prev ); prev=&curr->next)    { - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(curr->refs<1)    {    debug_dump_pike_string(curr, 70);    locate_problem(has_zero_refs);    fatal("String with no references.\n");    }   #endif       if (full_hash_value == curr->hval &&    len==curr->len &&
pike.git/src/stralloc.c:316:       for(base = prev = base_table + h;( curr=*prev ); prev=&curr->next)    {    if (curr == s) /* found it */    {    *prev=curr->next;    curr->next=*base;    *base=curr;    return curr;    } - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(curr->refs<1)    {    debug_dump_pike_string(curr, 70);    locate_problem(has_zero_refs);    fatal("String with no references.\n");    }   #endif    }    return 0; /* not found */   }
pike.git/src/stralloc.c:367:         /*** Make new strings ***/      /* note that begin_shared_string expects the _exact_ size of the string,    * not the maximum size    */   struct pike_string *debug_begin_shared_string(int len)   {    struct pike_string *t; - #ifdef DEBUG + #ifdef PIKE_DEBUG    extern int d_flag;    if(d_flag>10)    verify_shared_strings_tables();   #endif    t=(struct pike_string *)xalloc(len + sizeof(struct pike_string));    t->str[len]=0;    t->len=len;    t->size_shift=0;    return t;   }
pike.git/src/stralloc.c:393:    base_table[h] = s;    s->hval=full_hash_value;    num_strings++;    if(num_strings > MAX_AVG_LINK_LENGTH * htable_size)    rehash();   }      struct pike_string *debug_begin_wide_shared_string(int len, int shift)   {    struct pike_string *t; - #ifdef DEBUG + #ifdef PIKE_DEBUG    extern int d_flag;    if(d_flag>10)    verify_shared_strings_tables();   #endif    t=(struct pike_string *)xalloc((len<<shift) + sizeof(struct pike_string));    t->len=len;    t->size_shift=shift;    low_set_index(t,len,0);    return t;   }
pike.git/src/stralloc.c:417:    * can be.    */   struct pike_string *low_end_shared_string(struct pike_string *s)   {    int len,h;    struct pike_string *s2;       len=s->len;    h=do_hash(s);    s2=internal_findstring(s->str,len,s->size_shift,h); - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(s2==s)    fatal("end_shared_string called twice! (or something like that)\n");   #endif       if(s2)    {    free((char *)s);    s=s2;    }else{    link_pike_string(s, h);
pike.git/src/stralloc.c:593:      /*** Free strings ***/      void unlink_pike_string(struct pike_string *s)   {    int h;       h=do_hash(s);    propagate_shared_string(s,h);    base_table[h]=s->next; - #ifdef DEBUG + #ifdef PIKE_DEBUG    s->next=(struct pike_string *)-1;   #endif    num_strings--;   }      void really_free_string(struct pike_string *s)   { - #ifdef DEBUG + #ifdef PIKE_DEBUG    extern int d_flag;    if(d_flag > 2)    {    if(s->next == (struct pike_string *)-1)    fatal("Freeing shared string again!\n");       if(((long)s->next) & 1)    fatal("Freeing shared string again, memory corrupt or other bug!\n");    }   #endif
pike.git/src/stralloc.c:676:    my_strcat(b);    }   /*    sprintf(b,"Searches: %ld Average search length: %6.3f\n",    (long)num_str_searches, (double)search_len / num_str_searches);    my_strcat(b);   */    return free_buf();   }    - /*** DEBUG ***/ - #ifdef DEBUG + /*** PIKE_DEBUG ***/ + #ifdef PIKE_DEBUG      void check_string(struct pike_string *s)   {    do_hash(s);    if(full_hash_value != s->hval)    {    locate_problem(wrong_hash);    fatal("Hash value changed?\n");    }   
pike.git/src/stralloc.c:1045:    * within a string!    *    * Phew, this function become complicated when I inserted magic for wide    * characters...    */   struct pike_string *modify_shared_string(struct pike_string *a,    INT32 index,    INT32 c)   {    INT32 old_value; - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(index<0 || index>=a->len)    fatal("Index out of range in modify_shared_string()\n");   #endif          old_value=index_shared_string(a,index);    if(old_value==c) return a;       /* First test if the string needs to be grown:    * ie; the new value does not fit in the char size of
pike.git/src/stralloc.c:1241:    haystack->size_shift);       if(!r) return -1;    return (r-haystack->str)>>haystack->size_shift;   }      struct pike_string *string_slice(struct pike_string *s,    INT32 start,    INT32 len)   { - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(start < 0 || len<0 || start+len>s->len )    {    fatal("string_slice, start = %d, len = %d, s->len = %d\n",start,len,s->len);    }   #endif       if(start==0 && len==s->len)    {    add_ref(s);    return s;
pike.git/src/stralloc.c:1378: Inside #if defined(DEBUG_MALLOC)
  #ifdef DEBUG_MALLOC   struct shared_string_location *all_shared_string_locations;   #endif         void cleanup_shared_string_table(void)   {    unsigned INT32 e;    struct pike_string *s,*next;    - #if defined(DEBUG) && defined(DEBUG_MALLOC) + #if defined(PIKE_DEBUG) && defined(DEBUG_MALLOC)    while(all_shared_string_locations)    {    struct shared_string_location *x=all_shared_string_locations;    all_shared_string_locations=x->next;    free_string(x->s);    x->s=0;    }       if(verbose_debug_exit)    {
pike.git/src/stralloc.c:1434:    size_+=htable_size * sizeof(struct pike_string *);    for(e=0;e<htable_size;e++)    {    struct pike_string *p;    for(p=base_table[e];p;p=p->next)    {    num_++;    size_+=sizeof(struct pike_string)+(p->len<<p->size_shift);    }    } - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(num_strings != num_)    fatal("Num strings is wrong! %d!=%d.\n",num_strings, num_);   #endif    num[0]=num_;    size[0]=size_;   }      void gc_mark_all_strings(void)   {    unsigned INT32 e;
pike.git/src/stralloc.c:1538:    s->s->len+=len;   }      void string_builder_fill(struct string_builder *s,    int howmany,    PCHARP from,    INT32 len,    INT32 offset)   {    INT32 tmp; - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(len<=0)    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),