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.222 2008/06/23 18:56:08 mast Exp $ + || $Id: stralloc.c,v 1.223 2008/06/23 19:22:52 mast 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:1599:    }   }      PMOD_EXPORT struct pike_string *realloc_unlinked_string(struct pike_string *a,    ptrdiff_t size)   {    struct pike_string *r = NULL;       if (a->len <= SHORT_STRING_THRESHOLD) {    if (size <= SHORT_STRING_THRESHOLD) { -  /* There's already place enough. */ +  /* There's already space enough. */    a->len = size;    low_set_index(a, size, 0);    return a;    }    } else if (size > SHORT_STRING_THRESHOLD) {    r=(struct pike_string *)realloc((char *)a,    sizeof(struct pike_string_hdr)+    ((size+1)<<a->size_shift));    }   
pike.git/src/stralloc.c:3027:   }      PMOD_EXPORT void free_string_builder(struct string_builder *s)   {    s->s->len = s->malloced;    free_string(s->s);   }      PMOD_EXPORT struct pike_string *finish_string_builder(struct string_builder *s)   { -  /* Ensure NUL-termination */ -  low_set_index(s->s,s->s->len,0); -  if (s->s->len <= SHORT_STRING_THRESHOLD) { +     ptrdiff_t len = s->s->len; -  +  if (len != s->malloced) {    s->s->len = s->malloced;    s->s = realloc_unlinked_string(s->s, len);    } -  +  else +  /* Ensure NUL-termination */ +  low_set_index(s->s,s->s->len,0);    if(s->known_shift == s->s->size_shift)    return low_end_shared_string(s->s);    return end_shared_string(s->s);   }      PMOD_EXPORT PCHARP MEMCHR_PCHARP(PCHARP ptr, int chr, ptrdiff_t len)   {    switch(ptr.shift)    {    case 0: return MKPCHARP(MEMCHR0(ptr.ptr,chr,len),0);