pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:552:    if( tmp )    free( tmp );    return res;   }      struct pike_string *findstring(const char *foo)   {    return binary_findstring(foo, strlen(foo));   }    - /* -  * find a string that is already shared and move it to the head -  * of that list in the hastable -  */ - 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; -  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"); -  } - #endif -  } -  return 0; /* not found */ - } -  +    /*** rehash ***/      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. */
pike.git/src/stralloc.c:772:    t->flags |= STRING_ALLOC_BA;    } else {    t->str = xalloc(bytes);    t->flags |= STRING_ALLOC_MALLOC;    }    t->refs = 0;    t->size_shift=shift;    add_ref(t); /* For DMALLOC */    t->len=len;    DO_IF_DEBUG(t->next = NULL); -  UNSET_ONERROR(&fe); +  UNSET_ONERROR(fe);    low_set_index(t,len,0);    return t;   }      static struct pike_string * make_static_string(const char * str, size_t len,    enum size_shift shift)   {    struct pike_string * t = ba_alloc(&string_allocator);       t->flags = STRING_NOT_HASHED|STRING_NOT_SHARED|STRING_ALLOC_STATIC; -  t->str = str; +  t->str = (char *)str;    t->refs = 0;    t->len = len;    t->size_shift = shift;    add_ref(t); /* For DMALLOC */       return t;   }      PMOD_EXPORT struct pike_string * make_shared_static_string(const char *str, size_t len,    enum size_shift shift)
pike.git/src/stralloc.c:812:    link_pike_string(s, h);    } else {    if (!string_is_static(s)) {    if (string_is_block_allocated(s)) {    ba_free(&string_allocator, s->str);    } else {    free(s->str);    }    s->flags &= ~STRING_ALLOC_MASK;    s->flags |= STRING_ALLOC_STATIC; -  s->str = str; +  s->str = (char*)str;    }    add_ref(s);    }       return s;   }      /*    * This function assumes that the shift size is already the minimum it    * can be.
pike.git/src/stralloc.c:1096:    {    if( p )    p->next = s->next;    else    base_table[h] = s->next;    break;    }    p = tmp;    tmp = tmp->next;    } - #ifdef PIKE_DEBUG +     if( !tmp )    Pike_fatal("unlink on non-shared string\n"); -  +     s->next=(struct pike_string *)(ptrdiff_t)-1; - #endif +     num_strings--;    s->flags |= STRING_NOT_SHARED;   }      PMOD_EXPORT void do_free_string(struct pike_string *s)   {    if (s)    free_string(s);   }   
pike.git/src/stralloc.c:1405: Inside #if defined(PIKE_DEBUG)
   return 1;    }    }    }    return 0;   }      /* for once, this is actually a debug function! */   struct pike_string *debug_findstring(const struct pike_string *foo)   { -  return propagate_shared_string(foo, HMODULO(foo->hval)); +  return safe_debug_finstring(foo) ? foo : 0;   }      PMOD_EXPORT void debug_dump_pike_string(const struct pike_string *s, INT32 max)   {    INT32 e;    fprintf(stderr,"0x%p: %ld refs, len=%ld, size_shift=%d, hval=%lux (%lx)\n",    s,    (long)s->refs,    DO_NOT_WARN((long)s->len),    s->size_shift,