[pypy-dev] [pypy-commit] pypy default: (cfbolz, timfel) annotate no_nul on strings in result set if splitting at nul-byte

Alex Gaynor alex.gaynor at gmail.com
Tue Mar 12 15:35:26 CET 2013


I don't think this is totally correct, it's only true if `max == -1`.
Otherwise you can have something like:

>>> "abc\0def\0ghi\0".split("\0", 1)
['abc', 'def\x00ghi\x00']

Alex


On Tue, Mar 12, 2013 at 7:19 AM, timfel <noreply at buildbot.pypy.org> wrote:

> Author: Tim Felgentreff <timfelgentreff at gmail.com>
> Branch:
> Changeset: r62315:156750d24e38
> Date: 2013-03-12 15:18 +0100
> http://bitbucket.org/pypy/pypy/changeset/156750d24e38/
>
> Log:    (cfbolz, timfel) annotate no_nul on strings in result set if
>         splitting at nul-byte
>
> diff --git a/rpython/annotator/test/test_annrpython.py
> b/rpython/annotator/test/test_annrpython.py
> --- a/rpython/annotator/test/test_annrpython.py
> +++ b/rpython/annotator/test/test_annrpython.py
> @@ -446,6 +446,17 @@
>          s_item = s.listdef.listitem.s_value
>          assert s_item.no_nul
>
> +    def test_str_split_nul(self):
> +        def f(n):
> +            return n.split('\0')[0]
> +
> +        a = self.RPythonAnnotator()
> +        a.translator.config.translation.check_str_without_nul = True
> +        s = a.build_types(f, [annmodel.SomeString(no_nul=False,
> can_be_None=False)])
> +        assert isinstance(s, annmodel.SomeString)
> +        assert not s.can_be_None
> +        assert s.no_nul
> +
>      def test_str_splitlines(self):
>          a = self.RPythonAnnotator()
>          def f(a_str):
> diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
> --- a/rpython/annotator/unaryop.py
> +++ b/rpython/annotator/unaryop.py
> @@ -496,7 +496,11 @@
>
>      def method_split(str, patt, max=-1):
>          getbookkeeper().count("str_split", str, patt)
> -        s_item = str.basestringclass(no_nul=str.no_nul)
> +        if patt.is_constant() and patt.const == "\0":
> +            no_nul = True
> +        else:
> +            no_nul = str.no_nul
> +        s_item = str.basestringclass(no_nul=no_nul)
>          return getbookkeeper().newlist(s_item)
>
>      def method_rsplit(str, patt, max=-1):
> _______________________________________________
> pypy-commit mailing list
> pypy-commit at python.org
> http://mail.python.org/mailman/listinfo/pypy-commit
>



-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
"The people's good is the highest law." -- Cicero
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20130312/9f8d878e/attachment.html>


More information about the pypy-dev mailing list