> The split opcode gives "failed assertion 's'" when given a > null string argument. Perhaps it should pretend it got the > null string, or at least throw a more "normal" exception.
A problem is that the string_split functions declares his parameter as non null. This function is used in several pmc, so chnaging his signature risk to break things or slow down. This patch creates a new function called Parrot_split_string and uses it in the opcode instead of split_string. It returns PMCNULL if the string or the deilimiter argument is NULL, and calls split_string otherwise. -- Salu2
Index: src/ops/string.ops =================================================================== --- src/ops/string.ops (revisión: 27651) +++ src/ops/string.ops (copia de trabajo) @@ -452,7 +452,7 @@ } op split(out PMC, in STR, in STR) :base_core { - $1 = string_split(interp, $2, $3); + $1 = Parrot_string_split(interp, $2, $3); } Index: src/string.c =================================================================== --- src/string.c (revisión: 27651) +++ src/string.c (copia de trabajo) @@ -2933,6 +2933,31 @@ /* +=item C<PMC* Parrot_string_split> + +Split a string with a delimiter. +Returns PMCNULL if the string or the delimiter is NULL, +else is the same as string_split. + +=cut + +*/ + +PARROT_API +PARROT_WARN_UNUSED_RESULT +PARROT_CANNOT_RETURN_NULL +PMC* +Parrot_string_split(PARROT_INTERP, + ARGIN_NULLOK(STRING *delim), ARGIN_NULLOK(STRING *str)) +{ + if (! delim || ! str) + return PMCNULL; + else + return string_split(interp, delim, str); +} + +/* + =item C<STRING* uint_to_str> Returns C<num> converted to a Parrot C<STRING>. Index: include/parrot/string_funcs.h =================================================================== --- include/parrot/string_funcs.h (revisión: 27651) +++ include/parrot/string_funcs.h (copia de trabajo) @@ -426,6 +426,14 @@ PARROT_API PARROT_WARN_UNUSED_RESULT +PARROT_CANNOT_RETURN_NULL +PMC* Parrot_string_split(PARROT_INTERP, + ARGIN_NULLOK(STRING *delim), + ARGIN_NULLOK(STRING *str)) + __attribute__nonnull__(1); + +PARROT_API +PARROT_WARN_UNUSED_RESULT INTVAL string_str_index(PARROT_INTERP, ARGIN(const STRING *s), ARGIN(const STRING *s2),