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.164 2010/09/20 14:49:32 grubba Exp $ + || $Id: stralloc.c,v 1.165 2010/09/22 14:35:37 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.164 2010/09/20 14:49:32 grubba Exp $"); + RCSID("$Id: stralloc.c,v 1.165 2010/09/22 14:35:37 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:347:    */   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 +  int full_depth = 0; +  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);    locate_problem(has_zero_refs);
pike.git/src/stralloc.c:381:    }    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); +  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);    }    } -  +  }   #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:596:    t=(struct pike_string *)xalloc(len + sizeof(struct pike_string));    }    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; -  +  +  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)    stralloc_rehash();      #ifndef HASH_PREFIX    /* These heuristics might require tuning! /Hubbe */    if(need_more_hash_prefix_depth > MAX_AVG_LINK_LENGTH * 4)    { -  +  size_t count=0;    /* 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:669: Inside #if undefined(HASH_PREFIX)
   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;    }    } +  +  for(h=0;h<htable_size;h++) +  { +  struct pike_string *tmp=base_table[h]; +  while(tmp) { +  size_t h2 = HMODULO(tmp->hval); +  count++; +  if (h2 != h) { +  Pike_fatal("PREFIX rehash failed!\n"); +  } +  tmp = tmp->next; +  } +  } +  if (count != num_strings) { +  Pike_fatal("Lost track of strings during prefix rehash: %d != %d\n", +  count, num_strings); +  }   #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;