pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:706:   {    struct pike_string *s;    ptrdiff_t h = StrHash(str, len);       s = internal_findstring(str,len,shift,h);       if (!s) {    s = make_static_string(str, len, shift);    link_pike_string(s, h);    } else { -  if (!string_is_static(s)) +  /* NB: The following is only possible if there are no substring references +  * to the old string. +  */ +  if (!(s->flags & STRING_IS_LOCKED) && !string_is_static(s))    {    free_string_content(s);    s->alloc_type = STRING_ALLOC_STATIC;    s->str = (char*)str;    }    add_ref(s);    }       return s;   }
pike.git/src/stralloc.c:1870:    void *strstart = s->str+(start<<shift);    size_t hval = low_do_hash(strstart,len,shift);    if( (existing =    internal_findstring(strstart, len, shift, hval)) )    {    add_ref(existing);    return existing;    }    res = ba_alloc(&substring_allocator);    res->parent = s; +  s->flags |= STRING_IS_LOCKED; /* Make sure the string data isn't reallocated. */    add_ref(s);    existing = &res->str;       existing->flags = STRING_NOT_SHARED;    existing->size_shift = shift;    existing->alloc_type = STRING_ALLOC_SUBSTRING;    existing->struct_type = STRING_STRUCT_SUBSTRING;    existing->hval = hval;    existing->str = strstart;    existing->len = len;