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.231 2008/07/22 23:35:12 mast Exp $ + || $Id: stralloc.c,v 1.232 2008/11/05 12:09:36 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:621: Inside #if defined(PIKE_DEBUG)
   extern int d_flag;    if(d_flag>10)    verify_shared_strings_tables();   #endif    if (len <= SHORT_STRING_THRESHOLD) {    t=(struct pike_string *)alloc_short_pike_string0();    } else {    t=(struct pike_string *)xalloc(len + 1 + sizeof(struct pike_string_hdr));    t->flags = STRING_NOT_HASHED | STRING_NOT_SHARED;    } -  t->refs = 1; +  t->refs = 0; +  add_ref(t); /* For DMALLOC */    t->str[len]=0;    t->len=len;    t->size_shift=0;    DO_IF_DEBUG(t->next = NULL);    return t;   }      static void link_pike_string(struct pike_string *s, size_t hval)   {    size_t h;
pike.git/src/stralloc.c:882:    return end_shared_string(s);   }      PMOD_EXPORT struct pike_string *end_and_resize_shared_string(struct pike_string *str, ptrdiff_t len)   {    struct pike_string *tmp;   #ifdef PIKE_DEBUG    if(len > str->len)    Pike_fatal("Cannot extend string here!\n");   #endif -  if( str->len <= SHORT_STRING_THRESHOLD ? -  (len <= SHORT_STRING_THRESHOLD) : -  (len > SHORT_STRING_THRESHOLD) && str->len > len/2 ) +  if( (str->len <= SHORT_STRING_THRESHOLD) || +  ((len > SHORT_STRING_THRESHOLD) && (str->len <= (len<<1))) )    { -  +  /* Short string before and after or +  * long string and at least half the length of the buffer. +  * +  * NOTE: We lose track of the actual buffer length here, so don't +  * use this function to shorten a string in decrements. +  * +  * FIXME: Wide strings get only a partial NUL-termination. +  */    str->len=len;    str->str[len]=0;    return end_shared_string(str);    }    tmp = make_shared_binary_pcharp(MKPCHARP_STR(str),len);    free_string(str);    return tmp;   }