Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Segmentation faults - a theory
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Sam Partington  
View profile  
 More options Sep 19 2012, 5:40 am
From: Sam Partington <sam.parting...@gmail.com>
Date: Wed, 19 Sep 2012 10:40:14 +0100
Local: Wed, Sep 19 2012 5:40 am
Subject: Re: [wxPython-dev] Segmentation faults - a theory
On 18 September 2012 20:21, Robin Dunn <ro...@alldunn.com> wrote:

> Python's GC doesn't (and can't) deal with C/C++ memory and object
> allocations.  Only with Python objects.

Yes and no.  Pythons GC could be used to track all deletions if *all*
allocated objects were owned by PyObject's objects.  This is not
trivial though, and would require a lot of changes to wxWidgets.  This
could be done upstream though, if hooks were put into wxWidgets to
make all allocations go through a wxTrackObject fn, and all deletes go
through a similar wxUntrackObject.

The default wxWidgets implementation of these would be

template<typename T>  T* wxTrackObject(T* t) {  return t; }
template<typename T> void wxUntrackObject(T* t) {  delete t; }

Every allocation would then do (the first new I found in the source):

wxAuiToolBarArt* wxAuiDefaultToolBarArt::Clone()
{
    return static_cast<wxAuiToolBarArt*>(wxTrackObject(new
wxAuiDefaultToolBarArt));

}

And every delete would then do:

wxAuiToolBar::~wxAuiToolBar()
{
   wxUntrackObject(m_art); // was delete m_art;
   ...

}

wxPython could then somehow replace that with something that created a
PyObject with appropriate tp_new and tp_free.  It gets slightly more
complicated with container types because you have to help the GC out,
but it's not terribly hard.

I am not really suggesting we do this, and it would be an enormous
effort but it is achievable IMO.

> IMO there are a few normal, legitimate uses of Destroy, and one legitimate
> but abnormal use case.  The normal cases are things like:

(skip several valid use cases)

If there is even one valid use case then it must be supported. If it
is supported we must strive to make it stable even in the face of user
error.

> I suppose I could add something like this:

>     def SelfDestruct(self): # or maybe SafelyCommitSuicide ?  ;-)
>         self.Hide()
>         wx.CallAfter(self.Destroy)

The problem is that you don't always know that you are self
destructing.  In a complex app many code paths can mean that an event
handler for a fn is far away up the callstack from the code that is
actually doing the destroy.  In our most recent crash on win32 a
double click in a dialog mysteriously got converted into a drag
message in the frame that was behind the dialog, which caused the edit
control which owned the dialog to be destroyed, in turn destroying the
dialog.  In this case a simple CallAfter did not resolve the problem,
we had to capture all mouse events for the lifetime of that dialog.
Nor would hiding the dialog be appropriate in this case.

What makes me nervous is that these things keep cropping up in ways
that can not be spotted by introspection of the code, there was
nothing obviously wrong with what was written. I know that we will be
receiving more support calls from customers for ones that we have not
managed to find during test.

>     def SelfDestruct(self):
>         self.Hide()
>         wx.GetApp().ScheduleForDestruction(self)

The problem with that is that (at least in my version of the source,
2.9.4) DeletePendingObjets only seems to be called at application
shutdown.

Doing this for every destroy would result in an ever expanding working
set.  And only doing it in SelfDestruct doesn't solve all the problem
because you just don't know sometimes that you are doing a
SelfDestruct.

Sam


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.