[svn:parrot] r46564 - trunk/src/string/charset

Christoph Otto christoph at mksig.org
Thu May 13 06:40:53 UTC 2010


On 05/12/2010 06:30 PM, NotFound at parrot.org wrote:
> Author: NotFound
> Date: Thu May 13 01:30:49 2010
> New Revision: 46564
> URL: https://trac.parrot.org/parrot/changeset/46564
>
> Log:
> simplify mixed_cs_index
>
> Modified:
>     trunk/src/string/charset/ascii.c
>
> Modified: trunk/src/string/charset/ascii.c
> ==============================================================================
> --- trunk/src/string/charset/ascii.c	Thu May 13 01:26:03 2010	(r46563)
> +++ trunk/src/string/charset/ascii.c	Thu May 13 01:30:49 2010	(r46564)
> @@ -531,43 +531,32 @@
>       UINTVAL offs)
>   {
>       ASSERT_ARGS(mixed_cs_index)
> +
>       String_iter src_iter, search_iter;
> -    UINTVAL len, next_pos;
> -    INTVAL found_at;
> +    const UINTVAL maxpos = src->strlen - search->strlen + 1;
> +    const UINTVAL cfirst = Parrot_str_indexed(interp, search, 0);
>
>       ENCODING_ITER_INIT(interp, src,&src_iter);
>       src_iter.set_position(interp,&src_iter, offs);
>       ENCODING_ITER_INIT(interp, search,&search_iter);
> -    len = search->strlen;
> -
> -    found_at = -1;
> -    next_pos = offs;
>
> -    for (; len&&  offs<  src->strlen ;) {
> -        const UINTVAL c1 = src_iter.get_and_advance(interp,&src_iter);
> -        const UINTVAL c2 = search_iter.get_and_advance(interp,&search_iter);
> -
> -        if (c1 == c2) {
> -            --len;
> -            if (found_at == -1)
> -                found_at = offs;
> -            ++offs;
> -        }
> -        else {
> -            len = search->strlen;
> -            ++offs;
> -            ++next_pos;
> -            if (offs != next_pos) {
> -                src_iter.set_position(interp,&src_iter, next_pos);
> -                offs = next_pos;
> +    while (src_iter.charpos<  maxpos) {
> +        if (cfirst == src_iter.get_and_advance(interp,&src_iter)) {
> +            const INTVAL next_pos = src_iter.charpos;
> +            const INTVAL next_byte = src_iter.bytepos;
> +            UINTVAL len;
> +            search_iter.set_position(interp,&search_iter, 1);
> +            for (len = search->strlen - 1; len; --len) {
> +                if ((src_iter.get_and_advance(interp,&src_iter)) !=
> +                        (search_iter.get_and_advance(interp,&search_iter)))
> +                    break;
>               }
> -
> -            found_at = -1;
> -            search_iter.set_position(interp,&search_iter, 0);
> +            if (len == 0)
> +                return next_pos - 1;
> +            src_iter.charpos = next_pos;
> +            src_iter.bytepos = next_byte;
>           }
>       }
> -    if (len == 0)
> -        return found_at;
>       return -1;
>   }
>
> _______________________________________________
> http://lists.parrot.org/mailman/listinfo/parrot-commits
>

This change causes a segfault when running parrot-nqp on an empty file 
(empty.pm) as follows:
touch empty.pm
./parrot-nqp --target=pir -o empty.pir empty.pm
Curiously the segfault only happens when the options are in that order.  Using 
"-o empty.pir --target=pir" works fine.  If it looks like this commit is 
exposing something broken, a tt is in order.
I reverted it in r46573.

Christoph


More information about the parrot-dev mailing list