This is the mail archive of the
mailing list for the GDB project.
Re: should gdb.Value implement __hash__()?
>>>>> "Joachim" == Joachim Protze <email@example.com> writes:
Joachim> The problem is, that gdb.Value is hashable, but the hash does
Joachim> not depend on the value of gdb.Value. Also repr(gdb.Value) is
Joachim> not usable as key. str(gdb.Value) triggers the
Joachim> lookup_function, which tries to find str(gdb.Value) in dict -
Joachim> resulting in endless recursion.
Joachim> Is there a way to get a stringrepresentation of the content of
Joachim> gdb.Value bypassing the prettyprinting mechanism? Or is it
Joachim> possible to provide a __hash__, that represents the content of
Joachim> the value? Or to provide the raw string as __repr__()?
Right now I think there isn't a good way.
We want to add a method to Value to show the contents as a python
buffer. But nobody has done that yet. (And, Value is not exactly like
a python buffer, since some parts can be optimized out...)
I think the current hash is based on the idea that a struct value's
contents can change. But I am not completely sure this is the case.
If it is in fact immutable, we could change the hash.
In your case if you know that you only want your hash to hold pointer
values, you can use long(value) as the key.