[Python-Dev] A cute new way to get an infinite loop (original) (raw)
Tim Peters tim.peters at gmail.com
Mon Sep 27 00:06:00 CEST 2004
- Previous message: [Python-Dev] A cute new way to get an infinite loop
- Next message: [Python-Dev] More data points
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[Raymond Hettinger]
... One situation did look suspect. PySequenceIterSearch() remembers an index/count across calls to PyIterNext() -- 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!
- Previous message: [Python-Dev] A cute new way to get an infinite loop
- Next message: [Python-Dev] More data points
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]