From 5f14e5bedd4749be433c3a1de21944ef4a2db5de Mon Sep 17 00:00:00 2001 From: Daniel Arbelo Arrocha Date: Fri, 28 May 2010 15:25:07 +0000 Subject: [PATCH] Make sure the new 'extra' member is NULL when unused. Mark a few places as TODO. git-svn-id: https://svn.parrot.org/parrot/branches/gsoc_nfg@47092 d31e2699-5ff4-0310-a27c-f18f2fbe73fe --- src/io/buffer.c | 1 + src/string/api.c | 12 ++++++++++++ src/string/encoding/utf16.c | 1 + src/string/encoding/utf8.c | 1 + 4 files changed, 15 insertions(+) diff --git a/src/io/buffer.c b/src/io/buffer.c index 023dc03e93..2d753f96e1 100644 --- a/src/io/buffer.c +++ b/src/io/buffer.c @@ -467,6 +467,7 @@ Parrot_io_readline_buffer(PARROT_INTERP, ARGMOD(PMC *filehandle), ARGOUT(STRING } s = *buf; s->strlen = 0; + s->extra = NULL; /* fill empty buffer */ if (!(buffer_flags & PIO_BF_READBUF)) { diff --git a/src/string/api.c b/src/string/api.c index f92781e675..037b154721 100644 --- a/src/string/api.c +++ b/src/string/api.c @@ -220,6 +220,7 @@ Parrot_str_new_noinit(PARROT_INTERP, s->charset = PARROT_DEFAULT_CHARSET; s->encoding = CHARSET_GET_PREFERRED_ENCODING(interp, s); + s->extra = NULL; Parrot_gc_allocate_string_storage(interp, s, (size_t)string_max_bytes(interp, s, capacity)); @@ -550,6 +551,7 @@ Parrot_str_new_from_buffer(PARROT_INTERP, ARGMOD(Buffer *buffer), const UINTVAL result->strlen = len; result->encoding = Parrot_fixed_8_encoding_ptr; result->charset = Parrot_binary_charset_ptr; + result->extra = NULL; Buffer_buflen(buffer) = 0; Buffer_bufstart(buffer) = NULL; @@ -746,6 +748,7 @@ Parrot_str_new_init(PARROT_INTERP, ARGIN_NULLOK(const char *buffer), UINTVAL len STRING * const s = Parrot_gc_new_string_header(interp, flags); s->encoding = encoding; s->charset = charset; + s->extra = NULL; if (flags & PObj_external_FLAG) { /* @@ -1202,6 +1205,10 @@ Parrot_str_replace(PARROT_INTERP, ARGIN(const STRING *src), dest->encoding = enc; dest->charset = cs; + /* TODO: We should merge the grapheme tables here and translate the + dynamic graphemes in the second string if needed. */ + dest->extra = NULL; + /* Clear COW flag. We own buffer */ PObj_get_FLAGS(dest) = PObj_is_string_FLAG | PObj_is_COWable_FLAG @@ -2569,6 +2576,7 @@ Parrot_str_unescape_string(PARROT_INTERP, ARGIN(const STRING *src), reserved = string_max_bytes(interp, result, srclen); Parrot_gc_allocate_string_storage(interp, result, reserved); result->bufused = reserved; + result->extra = NULL; // TODO: Check wether we'll need a grapheme table here and create one if we will. src->encoding->iter_init(interp, src, &itersrc); encoding->iter_init(interp, result, &iterdest); @@ -3223,6 +3231,7 @@ Parrot_str_join(PARROT_INTERP, ARGIN_NULLOK(STRING *j), ARGIN(PMC *ar)) res->charset = j->charset; res->encoding = j->encoding; + res->extra = NULL; /* Iterate over chunks and append it to res */ pos = res->strstart; @@ -3232,6 +3241,7 @@ Parrot_str_join(PARROT_INTERP, ARGIN_NULLOK(STRING *j), ARGIN(PMC *ar)) if (!STRING_IS_NULL(s)) { mem_sys_memcopy(pos, s->strstart, s->bufused); pos += s->bufused; + res->extra = s->extra; } for (i = 1; i < ar_len; ++i) { @@ -3246,6 +3256,8 @@ Parrot_str_join(PARROT_INTERP, ARGIN_NULLOK(STRING *j), ARGIN(PMC *ar)) mem_sys_memcopy(pos, next->strstart, next->bufused); pos += next->bufused; + // TODO: Merge grapheme tables as we go. If it's needed. + /* We can consume all buffer and pos will be next-after-end of buffer */ PARROT_ASSERT(pos <= res->strstart + Buffer_buflen(res) + 1); } diff --git a/src/string/encoding/utf16.c b/src/string/encoding/utf16.c index 0c5ec2dbf7..3e1f661b73 100644 --- a/src/string/encoding/utf16.c +++ b/src/string/encoding/utf16.c @@ -196,6 +196,7 @@ to_encoding(PARROT_INTERP, ARGIN(const STRING *src)) result = Parrot_gc_new_string_header(interp, 0); + result->extra = NULL; /* * TODO adapt string creation functions */ diff --git a/src/string/encoding/utf8.c b/src/string/encoding/utf8.c index ff1776127f..a5140de5c4 100644 --- a/src/string/encoding/utf8.c +++ b/src/string/encoding/utf8.c @@ -528,6 +528,7 @@ to_encoding(PARROT_INTERP, ARGIN(const STRING *src)) result->charset = Parrot_unicode_charset_ptr; result->encoding = Parrot_utf8_encoding_ptr; result->strlen = src_len; + result->extra = NULL; if (!src->strlen) return result;