pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:19:      #include <errno.h>   #include <float.h>   #include <ctype.h>   #include <math.h>      #ifndef HUGE   #define HUGE HUGE_VAL   #endif /*!HUGE*/    - RCSID("$Id: stralloc.c,v 1.122 2001/03/30 12:23:16 hubbe Exp $"); + RCSID("$Id: stralloc.c,v 1.123 2001/03/30 15:34:53 grubba Exp $");      #if PIKE_RUN_UNLOCKED   /* Make this bigger when we get lightweight threads */   #define BUCKET_LOCKS 2048   static PIKE_MUTEX_T *bucket_locks;      #define BUCKETLOCK(HVAL) \    (bucket_locks + ((hval__ % htable_size) & (BUCKET_LOCKS-1)))      #define LOCK_BUCKET(HVAL) do { \
pike.git/src/stralloc.c:298:    UNLOCK_BUCKET(e);    }       DM(fprintf(stderr,"Plausible problem location(s):\n"));    DM(dump_memhdr_locations(yes,0,0));       DM(fprintf(stderr,"More Plausible problem location(s):\n"));    DM(dump_memhdr_locations(yes,no,0));   }    + static int bad_pointer(struct pike_string *s) + { +  return (((ptrdiff_t)s)&(sizeof(pike_string *)-1)); + } +    static int has_zero_refs(struct pike_string *s)   {    return s->refs<=0;   }   static int wrong_hash(struct pike_string *s)   {    return s->hval != do_hash(s);   }   static int improper_zero_termination(struct pike_string *s)   {
pike.git/src/stralloc.c:320:   #else   #define locate_problem(X)   #endif      /* Find a string in the shared string table.    * This assumes that the string is minimized!!!!    */   static INLINE struct pike_string *internal_findstring(const char *s,    ptrdiff_t len,    int size_shift, -  ptrdiff_t hval) +  size_t hval)   {    struct pike_string *curr,**prev, **base;   #ifndef HASH_PREFIX    unsigned int depth=0;   #endif    size_t h;    LOCK_BUCKET(hval);    h=hval % htable_size;    for(base = prev = base_table + h;( curr=*prev ); prev=&curr->next)    {
pike.git/src/stralloc.c:873:   }      /*** Free strings ***/      PMOD_EXPORT void unlink_pike_string(struct pike_string *s)   {    size_t h;    LOCK_BUCKET(s->hval);    h= s->hval % htable_size;    propagate_shared_string(s,h); + #ifdef PIKE_DEBUG +  if (base_table[h] != s) { +  fatal("propagate_shared_string() failed!\n"); +  } + #endif /* PIKE_DEBUG */    base_table[h]=s->next;   #ifdef PIKE_DEBUG    s->next=(struct pike_string *)(ptrdiff_t)-1;   #endif    num_strings--;    UNLOCK_BUCKET(s->hval);   }      PMOD_EXPORT void do_free_string(struct pike_string *s)   {
pike.git/src/stralloc.c:1022: Inside #if defined(PIKE_DEBUG)
   struct pike_string *s;       for(e=0;e<htable_size;e++)    {    h=0;    LOCK_BUCKET(e);    for(s=base_table[e];s;s=s->next)    {    num++;    h++; +  +  if (bad_pointer(s)) { +  fatal("Odd string pointer in string table!\n"); +  } +     if(s->len < 0)    fatal("Shared string shorter than zero bytes.\n");       if(s->refs <= 0)    {    locate_problem(has_zero_refs);    fatal("Shared string had too few references.\n");    }       if(index_shared_string(s,s->len))