Better recursion support

So, here's a patch for recursive object support. I'm a bit clumsy with git, so it took several commits and an accidental branch to get everything straightened.

I did it as an API addition, so that people using the library for simple objects don't have a performance penalty. Some of the objects I wanted to compare happen to be frozen, so there's support for unwritable objects as well (though performance is rather worse in that case - still far better than the old patch I submitted).