This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: should gdb.Value implement __hash__()?

The Python rule is that mutable objects aren't hashable, so if gdb.Value can change, then it should not have a __hash__ method (and calling hash() on it should fail).


On Nov 2, 2010, at 5:03 PM, Tom Tromey wrote:

>>>>>> "Joachim" == Joachim Protze <> 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.
> Tom

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]