[PATCH] atomictempfile: avoid infinite recursion in destructor

Matt Mackall mpm at selenic.com
Fri Dec 10 15:57:38 CST 2010


On Mon, 2010-11-29 at 22:03 -0500, Greg Ward wrote:
> # HG changeset patch
> # User Greg Ward <greg-hg at gerg.ca>
> # Date 1291085861 18000
> # Branch stable
> # Node ID 76a458f91f5baad3dd75a26d445ea51402fc32d1
> # Parent  5fb924ee44d516e2f91bb7f5cfd5c81b0629faa4
> atomictempfile: avoid infinite recursion in destructor.
> 
> This is a weird one: if Python sees that the caller is not passing the
> right args to the constructor, it raises TypeError rather than enter
> the constructor.  But it still ends up calling the destructor, which
> assumes that self._fp has been set in the constructor.  But it hasn't,
> because the constructor wasn't actually executed.  So we go into a
> nasty infinite recursion between __del__() and __getattr__(), when we
> should just crash with TypeError so the programmer can see what he did
> wrong.

I think it's a bit too weird. Either we do this for all variables used
by all destructors, or skip it. As this only defends against explosively
incorrect code, I don't think we should worry about it.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list