Skip to content

Commit

Permalink
Get rid of side-effects in Parrot_str_length
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.parrot.org/parrot/branches/immutable_strings_part1@45740 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
bacek committed Apr 17, 2010
1 parent 7c2c129 commit 9721f99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
5 changes: 2 additions & 3 deletions include/parrot/string_funcs.h
Expand Up @@ -231,10 +231,9 @@ STRING* Parrot_str_join(PARROT_INTERP,

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
INTVAL Parrot_str_length(PARROT_INTERP, ARGMOD(STRING *s))
INTVAL Parrot_str_length(PARROT_INTERP, ARGIN(const STRING * const s))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*s);
__attribute__nonnull__(2);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
Expand Down
15 changes: 7 additions & 8 deletions src/string/api.c
Expand Up @@ -757,7 +757,7 @@ Parrot_str_new_init(PARROT_INTERP, ARGIN_NULLOK(const char *buffer), UINTVAL len
if (encoding == Parrot_fixed_8_encoding_ptr)
s->strlen = len;
else
(void)Parrot_str_length(interp, s);
s->strlen = CHARSET_CODEPOINTS(interp, s);

return s;
}
Expand All @@ -770,7 +770,7 @@ Parrot_str_new_init(PARROT_INTERP, ARGIN_NULLOK(const char *buffer), UINTVAL len
if (encoding == Parrot_fixed_8_encoding_ptr)
s->strlen = len;
else
(void)Parrot_str_length(interp, s);
s->strlen = CHARSET_CODEPOINTS(interp, s);
}
else {
s->strlen = s->bufused = 0;
Expand Down Expand Up @@ -960,7 +960,7 @@ string_chr(PARROT_INTERP, UINTVAL character)
=over 4
=item C<INTVAL Parrot_str_length(PARROT_INTERP, STRING *s)>
=item C<INTVAL Parrot_str_length(PARROT_INTERP, const STRING * const s)>
Calculates and returns the number of characters in the specified Parrot string.
Expand All @@ -971,11 +971,10 @@ Calculates and returns the number of characters in the specified Parrot string.
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
INTVAL
Parrot_str_length(PARROT_INTERP, ARGMOD(STRING *s))
Parrot_str_length(PARROT_INTERP, ARGIN(const STRING * const s))
{
ASSERT_ARGS(Parrot_str_length)

s->strlen = CHARSET_CODEPOINTS(interp, s);
return s->strlen;
}

Expand Down Expand Up @@ -1214,7 +1213,7 @@ Parrot_str_replace(PARROT_INTERP, ARGIN(STRING *src),
(char *)src->strstart + end_byte,
src->bufused - end_byte);

(void)Parrot_str_length(interp, dest);
dest->strlen = CHARSET_CODEPOINTS(interp, dest);

return dest;
}
Expand Down Expand Up @@ -2603,7 +2602,7 @@ Parrot_str_unescape(PARROT_INTERP,

/* Force validating the string */
if (encoding != result->encoding)
(void)Parrot_str_length(interp, result);
result->strlen = CHARSET_CODEPOINTS(interp, result);

if (!CHARSET_VALIDATE(interp, result))
Parrot_ex_throw_from_c_args(interp, NULL,
Expand Down Expand Up @@ -3061,8 +3060,8 @@ Parrot_str_join(PARROT_INTERP, ARGIN_NULLOK(STRING *j), ARGIN(PMC *ar))
}

res->bufused = pos - res->strstart;
res->strlen = CHARSET_CODEPOINTS(interp, res);

(void)Parrot_str_length(interp, res);
Parrot_gc_free_fixed_size_storage(interp, ar_len * sizeof (STRING *),
chunks);

Expand Down

0 comments on commit 9721f99

Please sign in to comment.