Dear Robert,

I GOT IT!

On Sep 16, 1:25 am, Robert Bradshaw <[EMAIL PROTECTED]>
wrote:
> No idea what Speicherzugriffsfehler means (never heard of that
> before) but __del__ might be called on a failing __init__.

Yes. I just tested, and definitely it *is* called, and this is half of
the reason for the error.

> For Cython, you might want to use __cinit__ and __dealloc__ (which
> are guaranteed to be called exactly once in pairs).

My class is pure python. More precisely, it eventually has some
attributes that are extension (cdef'd) classes, but in the above
example the error is raised before any extension class is involved.

The reason for the "invalid memory access" (thanks, Michael :) is as
follows:
1) The error is raised.
2) The __del__ method starts to work and tries to call
self.Resl.getindent() -- but self has no attribute Resl at that time.
3) The class also has a __getattr__ method. That method relies on the
existence of an attribute self.__dict -- but if the init method fails,
__dict was never initialized.
4) Now the punch line: __dict is no attribute, hence __getattr__ is
called -- infinite recursion, and finally invalid memory access after
a couple of hundred rounds.

My solution: The first thing done in the init method is now
   self.__dict = {}

Why is it a solution? Any error will be raised AFTER having defined
__dict. When __del__ refers to self.Resl, __getattr__ is called, it
refers to self.__dict (which is now defined!!) and returns None. And
that's fine.

Thank you for all your hints on debugging!

Cheers
    Simon

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to