Permalink
Browse files

[cage] Change the parsing of FixedIntegerArray initialization strings…

… from

poking directly into the guts of a STRING to use a temporary C string.
Partially resolves RT #47011.


git-svn-id: https://svn.parrot.org/parrot/trunk@35576 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent 2179856 commit 68b482053dcc63b209038d82c05f1936c49dc048 @allisonrandal allisonrandal committed Jan 15, 2009
Showing with 12 additions and 5 deletions.
  1. +12 −5 src/pmc/fixedintegerarray.pmc
View
17 src/pmc/fixedintegerarray.pmc
@@ -59,7 +59,7 @@ in the constant PMC pool.
VTABLE PMC *new_from_string(STRING *rep, INTVAL flags) {
const INTVAL type = SELF->vtable->base_type;
INTVAL n, elem, i, l;
- char *p, *start;
+ char *source, *p, *start;
int base;
if (flags & PObj_constant_FLAG)
@@ -76,22 +76,28 @@ in the constant PMC pool.
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_ENCODING,
"unhandled string encoding in constructor");
+ source = string_to_cstring(interp, rep);
+
/* "()" - no args */
- if (l <= 2 && ((char *)rep->strstart)[0] == '(')
+ if (l <= 2 && *source == '(') {
+ string_cstring_free(source);
return SELF;
+ }
/* count commas */
- p = rep->strstart;
- for (i = l, n = 0; i; --i, ++p) {
+ p = source;
+ n = 0;
+ while (*p) {
if (*p == ',')
++n;
+ p++;
}
/* presize the array */
SELF.set_integer_native(n + 1);
/* parse string */
- p = rep->strstart;
+ p = source;
for (i = l, n = 0; i; --i, ++p) {
switch (*p) {
@@ -127,6 +133,7 @@ in the constant PMC pool.
}
}
+ string_cstring_free(source);
return SELF;
}

0 comments on commit 68b4820

Please sign in to comment.