[svn:parrot] r40965 - in trunk/src: . interp pmc
cotto at svn.parrot.org
cotto at svn.parrot.org
Fri Sep 4 01:05:07 UTC 2009
Author: cotto
Date: Fri Sep 4 01:05:05 2009
New Revision: 40965
URL: https://trac.parrot.org/parrot/changeset/40965
Log:
[string] remove more ->strstart abuse, courtesy of darbelo++
Modified:
trunk/src/interp/inter_cb.c
trunk/src/packdump.c
trunk/src/pmc/hash.pmc
trunk/src/pmc/string.pmc
Modified: trunk/src/interp/inter_cb.c
==============================================================================
--- trunk/src/interp/inter_cb.c Thu Sep 3 21:30:05 2009 (r40964)
+++ trunk/src/interp/inter_cb.c Fri Sep 4 01:05:05 2009 (r40965)
@@ -299,6 +299,8 @@
PMC *sub;
STRING *sig_str;
char *p;
+ char ch;
+ char *sig_cstr;
char pasm_sig[4];
INTVAL i_param;
PMC *p_param;
@@ -311,7 +313,8 @@
signature = VTABLE_getprop(interp, user_data, sc);
sig_str = VTABLE_get_string(interp, signature);
- p = sig_str->strstart;
+ sig_cstr = Parrot_str_to_cstring(interp, sig_str);
+ p = sig_cstr;
++p; /* Skip return type */
pasm_sig[0] = 'v'; /* no return value supported yet */
@@ -367,9 +370,12 @@
param = Parrot_str_new(interp, external_data, 0);
break;
default:
+ ch = *p;
+ Parrot_str_free_cstring(sig_cstr);
Parrot_ex_throw_from_c_args(interp, NULL, 1,
- "unhandled signature char '%c' in run_cb", *p);
+ "unhandled signature char '%c' in run_cb", ch);
}
+ Parrot_str_free_cstring(sig_cstr);
pasm_sig[3] = '\0';
Parrot_runops_fromc_args_event(interp, sub, pasm_sig,
user_data, param);
Modified: trunk/src/packdump.c
==============================================================================
--- trunk/src/packdump.c Thu Sep 3 21:30:05 2009 (r40964)
+++ trunk/src/packdump.c Fri Sep 4 01:05:05 2009 (r40965)
@@ -224,9 +224,8 @@
ct_index = PackFile_find_in_const(interp, ct, key, PFC_STRING);
Parrot_io_printf(interp, " PFC_OFFSET => %ld\n", ct_index);
detail = ct->constants[ct_index];
- Parrot_io_printf(interp, " DATA => '%.*s'\n",
- (int)detail->u.string->bufused,
- (char *)detail->u.string->strstart);
+ Parrot_io_printf(interp, " DATA => '%Ss'\n",
+ detail->u.string);
Parrot_io_printf(interp, " },\n");
}
break;
Modified: trunk/src/pmc/hash.pmc
==============================================================================
--- trunk/src/pmc/hash.pmc Thu Sep 3 21:30:05 2009 (r40964)
+++ trunk/src/pmc/hash.pmc Fri Sep 4 01:05:05 2009 (r40965)
@@ -620,16 +620,20 @@
for (j = 0; j < n; ++j) {
STRING * const key = VTABLE_shift_string(INTERP, iter);
+ char * key_str;
+ size_t i, str_len;
int all_digit = 1;
- int i;
PMC *val;
- for (i = 0; i < (int)key->strlen; ++i) {
- if (!isdigit((unsigned char)((const char *)key->strstart)[i])) {
+ key_str = Parrot_str_to_cstring(INTERP, key);
+ str_len = strlen(key_str);
+ for (i = 0; i < str_len; ++i) {
+ if (!isdigit(key_str[i])) {
all_digit = 0;
break;
}
}
+ Parrot_str_free_cstring(key_str);
if (all_digit) {
res = Parrot_str_append(INTERP, res, key);
Modified: trunk/src/pmc/string.pmc
==============================================================================
--- trunk/src/pmc/string.pmc Thu Sep 3 21:30:05 2009 (r40964)
+++ trunk/src/pmc/string.pmc Fri Sep 4 01:05:05 2009 (r40965)
@@ -734,17 +734,18 @@
enum_class_Integer));
/* TODO verify encoding */
- const STRING *me = VTABLE_get_string(INTERP, SELF);
- const char *start = me->strstart;
- const char * const end = start + me->bufused;
- UINTVAL i = 0;
+ const STRING *me = VTABLE_get_string(INTERP, SELF);
+ char *str = Parrot_str_to_cstring(INTERP, me);
+ UINTVAL i = 0;
+ size_t j = 0;
+ size_t len = strlen(str);
if (base < 2 || base > 36)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
"invalid conversion to int - bad base %d", base);
- while (start < end) {
- const unsigned char c = *start;
+ while ( j < len) {
+ const unsigned char c = str[j];
int dig;
if (isdigit((unsigned char)c))
@@ -760,13 +761,17 @@
break;
i = i * base + dig;
- ++start;
+ j++;
}
- if (start < end)
+ if (j < len) {
+ char ch = str[j];
+ Parrot_str_free_cstring(str);
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
- "invalid conversion to int - bad char %c", *start);
+ "invalid conversion to int - bad char %c", ch);
+ }
+ Parrot_str_free_cstring(str);
/* TODO: autopromote to BigInt instead of casting away the high bit */
VTABLE_set_integer_native(INTERP, result, (INTVAL)i);
RETURN(PMC *result);
More information about the parrot-commits
mailing list