[pypy-dev] [pypy-svn] r29534 - pypy/dist/pypy/rpython/ootypesystem/test

Samuele Pedroni pedronis at strakt.com
Fri Jun 30 19:44:34 CEST 2006


antocuni at codespeak.net wrote:
> Author: antocuni
> Date: Fri Jun 30 16:08:16 2006
> New Revision: 29534
> 
> Modified:
>    pypy/dist/pypy/rpython/ootypesystem/test/test_oorecord.py
> Log:
> Added a failing test.
> 
> Basically, if we modify the Record after its hash has already been
> computed, we might obtain two objects that compare equal but hash
> differently.
> 
> Disabling the caching in LowLevelType.__hash__ fix the test, but I
> think it's not what we want.
> 
> Adding the following __hash__ to ootype.Record also fix the test, but
> I'm not sure if it's correct, especially with recursive structures:
> 
>   def __hash__(self):
>     return hash(self._fields)
> 

Records are really like lltypesystem Structs, although because some of 
their code was copied from Instance, they may give the impression
that you can add fields after the fact, but that should not be done,
it breaks the fact that they are supposed to compare by structure.

If you are needing that you need some other approach or introduce
some kind of forward definition.

_add_fields should really disappear from Record.



> 
> 
> 
> Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_oorecord.py
> ==============================================================================
> --- pypy/dist/pypy/rpython/ootypesystem/test/test_oorecord.py	(original)
> +++ pypy/dist/pypy/rpython/ootypesystem/test/test_oorecord.py	Fri Jun 30 16:08:16 2006
> @@ -38,3 +38,14 @@
>      t.a = 1
>      t.b = 2
>      assert ooidentityhash(t) != ooidentityhash(t2)
> +
> +import py
> +def test_hash():
> +    #py.test.skip("LowLevelType.__hash__ bug waiting to be fixed")
> +    T1 = Record({"item0": Signed, "item1": Signed})
> +    T2 = Record({"item0": Signed})
> +
> +    hash(T2) # compute the hash, it will stored in __cached_hash
> +    T2._add_fields({"item1": Signed}) # modify the object
> +    assert T1 == T2
> +    assert hash(T1) == hash(T2)
> _______________________________________________
> pypy-svn mailing list
> pypy-svn at codespeak.net
> http://codespeak.net/mailman/listinfo/pypy-svn




More information about the Pypy-dev mailing list