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.163 2010/04/29 15:08:51 grubba Exp $ + || $Id: stralloc.c,v 1.164 2010/09/20 14:49:32 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.163 2010/04/29 15:08:51 grubba Exp $"); + RCSID("$Id: stralloc.c,v 1.164 2010/09/20 14:49:32 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:369:   #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; +  if (*base == curr) { +  Pike_fatal("String circularity imminent (FIND).\n"); +  }    curr->next = *base;    *base = curr;    UNLOCK_BUCKET(hval);    return curr; /* pointer to string */    }   #ifndef HASH_PREFIX    if (curr->len > HASH_PREFIX)    depth++;   #endif -  +  if (curr == curr->next) { +  Pike_fatal("String circularity detected for string 0x%lx.\n", +  (unsigned long)curr);    } -  +  }   #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,    HASH_PREFIX);
pike.git/src/stralloc.c:421:   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; +  if (*base == curr) { +  Pike_fatal("String circularity imminent (PROPAGATE).\n"); +  }    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:448:      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)) { +  if (prev == s) { +  Pike_fatal("String circularity detected for string 0x%lx (REVERSE).\n", +  (unsigned long)s); +  }    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; -  +  if (base_table[h] == s) { +  Pike_fatal("String circularity imminent (REHASH).\n"); +  }    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:583:    t->size_shift=0;    return t;   }      static void link_pike_string(struct pike_string *s, size_t hval)   {    size_t h;    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)    stralloc_rehash();      #ifndef HASH_PREFIX
pike.git/src/stralloc.c:642: 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);    +  if (base_table[h2] == tmp2) { +  Pike_fatal("String circularity imminent (PREFIX).\n"); +  }    tmp2->next=base_table[h2]; /* and re-hash */    base_table[h2]=tmp2;    }    }   #ifdef PIKE_RUN_UNLOCKED    for(h=0;h<BUCKET_LOCKS;h++) mt_unlock(bucket_locks + h);   #endif    }   #endif   }