[New-bugs-announce] [issue15529] PyIter_Check evaluates to 0 for Python list object

Tom Tromey report at bugs.python.org
Wed Aug 1 18:40:31 CEST 2012

New submission from Tom Tromey:

I was debugging this bug reported against gdb:


It turns out that what went wrong in this code was that
PyIter_Check evaluates to 0 when its argument is a
Python list.

This happens because the PyIter_Check macro looks at the
tp_iternext field; but this field is 0 in PyList_Type.

I am not sure of the correct fix; but PyIter_Check is not
faithfully reflecting what PyObject_GetIter does.
Maybe it isn't intended to; but anyway it seems that
checking tp_iter would maybe be a better approximation.

Even if PyIter_Check remains as-is, I think it would be nice
if the documentation were more specific about what it
actually does.

FWIW I'm modifying gdb not to use this function.

components: None
messages: 167143
nosy: tromey
priority: normal
severity: normal
status: open
title: PyIter_Check evaluates to 0 for Python list object
versions: Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list