gobject.py causes infinite recursion for certain struct types
Submitted by Robert O'Callahan
Link to original bug (#761892)
Description
When debugging Firefox with gdb, printing certain structures (TArrays) causes gdb to spew a massive message about infinite recursion in gobject.py.
The problem is quite simple. We have a struct that looks like this:
struct nsTArrayHeader
{
static nsTArrayHeader sEmptyHdr;
uint32_t mLength;
uint32_t mCapacity : 31;
uint32_t mIsAutoArray : 1;
};
At
https://git.gnome.org/browse/glib/tree/gobject/gobject.py#n59
is_g_type_instance_helper
calls itself recursively on the type of the struct's first field. Here the struct's first field has the same type as the struct itself. That can't happen for nonstatic fields, but it can for static fields, and is_g_type_instance_helper doesn't check whether the field is static.
I've fixed this locally by changing the tail of is_g_type_instance_helper
to the following:
fields = type.fields()
for field in fields:
if hasattr(field, 'bitpos') and field.bitpos == 0:
return is_g_type_instance_helper(field.type)
return False
Edited by Philip Withnall