A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-September/049095.html below:

[Python-Dev] A cute new way to get an infinite loop

[Python-Dev] A cute new way to get an infinite loopTim Peters tim.peters at gmail.com
Mon Sep 27 00:06:00 CEST 2004
[Raymond Hettinger]
> ...
> One situation did look suspect.  _PySequence_IterSearch() remembers an
> index/count across calls to PyIter_Next() -- it looks like the worst
> that could happen is the index or count would be wrong, but no crashers.

If the operation is PY_ITERSEARCH_INDEX, n is the 0-based count of the
number of times the iterator got poked before the object was found. 
That's always correct, by definition (given that there's no guarantee
the iterator can be rewound and restarted, or even that it would yield
the same objects if it could be restarted, what else could "the index
of the first occurrence" mean?).

If the operation is PY_ITERSEARCH_COUNT, then n is the number of times
poking the iterator returned the object in question.  That's also
correct by defintion of what PySequence_Count() means, although
there's again no guarantee that the user passes a sensible iterable
object (== one that would produce the same objects if crawled over a
second time).

So those are fine.

Thanks for checking the others, and for checking in a test and the fix!
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4