pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:351:    */   static INLINE struct pike_string *internal_findstring(const char *s,    ptrdiff_t len,    int size_shift,    size_t hval)   {    struct pike_string *curr,**prev, **base;   #ifndef HASH_PREFIX    unsigned int depth=0;   #endif + #ifdef PIKE_DEBUG    int full_depth = 0; -  + #endif    struct pike_string *loop = NULL;    size_t h;    LOCK_BUCKET(hval);    h=HMODULO(hval);    for(base = prev = base_table + h;( curr=*prev ); prev=&curr->next)    {   #ifdef PIKE_DEBUG    if(curr->refs<1)    {    debug_dump_pike_string(curr, 70);
pike.git/src/stralloc.c:375:   #endif    debug_malloc_touch(curr);       if (hval == curr->hval &&    len==curr->len &&    size_shift==curr->size_shift &&    ( curr->str == s ||    !MEMCMP(curr->str, s,len<<size_shift))) /* found it */    {    *prev = curr->next; + #ifdef PIKE_DEBUG    if (*base == curr) {    Pike_fatal("String circularity imminent (FIND).\n");    } -  + #endif    curr->next = *base;    *base = curr;    UNLOCK_BUCKET(hval);    return curr; /* pointer to string */    }   #ifndef HASH_PREFIX    if (curr->len > HASH_PREFIX)    depth++;   #endif -  + #ifdef PIKE_DEBUG    if (++full_depth >= 1024) {    if (!loop) loop = curr;    else if (curr == loop) {    Pike_fatal("String circularity detected for string 0x%lx (length:%d).\n",    (unsigned long)curr, full_depth-1024);    }    } -  + #endif    }   #ifndef HASH_PREFIX    /* These heuruistics might require tuning! /Hubbe */    if (depth > need_more_hash_prefix_depth)    {   #if 0    fprintf(stderr,    "depth=%d num_strings=%d need_more_hash_prefix_depth=%d\n"    " HASH_PREFIX=%d\n",    depth, num_strings, need_more_hash_prefix_depth,
pike.git/src/stralloc.c:437:   static struct pike_string *propagate_shared_string(const struct pike_string *s,    ptrdiff_t h)   {    struct pike_string *curr, **prev, **base;       for(base = prev = base_table + h;( curr=*prev ); prev=&curr->next)    {    if (curr == s) /* found it */    {    *prev=curr->next; + #ifdef PIKE_DEBUG    if (*base == curr) {    Pike_fatal("String circularity imminent (PROPAGATE).\n");    } -  + #endif    curr->next=*base;    *base=curr;    return curr;    }   #ifdef PIKE_DEBUG    if(curr->refs<1)    {    debug_dump_pike_string(curr, 70);    locate_problem(has_zero_refs);    Pike_fatal("String with no references.\n");
pike.git/src/stralloc.c:467:      static void rehash_string_backwards(struct pike_string *s)   {    struct pike_string *prev = NULL;    struct pike_string *next;       if(!s) return;       /* Reverse the hash list. */    while ((next = s->next)) { + #ifdef PIKE_DEBUG    if (prev == s) {    Pike_fatal("String circularity detected for string 0x%lx (REVERSE).\n",    (unsigned long)s);    } -  + #endif    s->next = prev;    prev = s;    s = next;    }    s->next = prev;       /* Rehash the strings for this list. */    do {    ptrdiff_t h = HMODULO(s->hval);    next = s->next; -  + #ifdef PIKE_DEBUG    if (base_table[h] == s) {    Pike_fatal("String circularity imminent (REHASH).\n");    } -  + #endif    s->next = base_table[h];    base_table[h] = s;    } while ((s = next));   }      static void stralloc_rehash(void)   {    int h,old;    struct pike_string **old_base;   
pike.git/src/stralloc.c:617:    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;    -  + #ifdef PIKE_DEBUG +  struct pike_string *old;    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);    }    } -  + #endif       LOCK_BUCKET(hval);    h=HMODULO(hval); -  + #ifdef PIKE_DEBUG    if (base_table[h] == s) {    Pike_fatal("String circularity imminent (LINK).\n");    } -  + #endif    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)    stralloc_rehash();      #ifndef HASH_PREFIX    /* These heuristics might require tuning! /Hubbe */    if(need_more_hash_prefix_depth > MAX_AVG_LINK_LENGTH * 4)    { -  + #ifdef PIKE_DEBUG    size_t count=0; -  + #endif    /* Changed heuristic 2005-01-17:    *    * Increase HASH_PREFIX if there's some bucket containing    * more than MAX_AVG_LINK_LENGTH * 4 strings that are longer    * than HASH_PREFIX.    * /grubba    */       /* This could in theory have a pretty ugly complexity    * /Hubbe
pike.git/src/stralloc.c:693: Inside #if undefined(HASH_PREFIX)
   base_table[h]=0;    while(tmp)    {    size_t h2;    struct pike_string *tmp2=tmp; /* First unlink */    tmp=tmp2->next;       tmp2->hval=do_hash(tmp2); /* compute new hash value */    h2=HMODULO(tmp2->hval);    + #ifdef PIKE_DEBUG    if (base_table[h2] == tmp2) {    Pike_fatal("String circularity imminent (PREFIX).\n");    } -  + #endif    tmp2->next=base_table[h2]; /* and re-hash */    base_table[h2]=tmp2;    }    }       for(h=0;h<htable_size;h++)    {    struct pike_string *tmp=base_table[h];    while(tmp) {    size_t h2 = HMODULO(tmp->hval); -  count++; + #ifdef PIKE_DEBUG    if (h2 != h) {    Pike_fatal("PREFIX rehash failed!\n");    } -  +  count++; + #endif    tmp = tmp->next;    }    } -  +  + #ifdef PIKE_DEBUG    if (count != num_strings) {    Pike_fatal("Lost track of strings during prefix rehash: %d != %d\n",    count, num_strings);    } -  + #endif   #ifdef PIKE_RUN_UNLOCKED    for(h=0;h<BUCKET_LOCKS;h++) mt_unlock(bucket_locks + h);   #endif    }   #endif   }      PMOD_EXPORT struct pike_string *debug_begin_wide_shared_string(size_t len, int shift)   {    struct pike_string *t;