Re: Crash during throw_func()



On 10/25/06, Murray Cumming <murrayc murrayc com> wrote:
On Wed, 2006-10-25 at 09:11 -0500, Matt Hoosier wrote:
> On 10/25/06, Murray Cumming <murrayc murrayc com> wrote:
> > On Tue, 2006-10-24 at 19:18 -0500, Matt Hoosier wrote:
> > [snip]
> > >   std::auto_ptr<Glib::Error> throw_func(GError* gobject)
> > >   {
> > >     Glib::Error* e = new Glib::Error(gobject);
> > >     printf ("checkpoint 1..."); fflush (stdout);
> > >     std::auto_ptr<Glib::Error> p(e); // this line crashes
> > >     printf ("checkpoint 2..."); fflush (stdout); // never appears
> > >     return p;
> > >   }
> > >
> > > Any ideas why the construction of that auto_ptr would fail? I am
> > > absolutely certain that the Glib::Error gets built; the first
> > > checkpoint after it shows up.
> >
> > No, it looks fine. valgrind can probably give clues. Or you could put
> > the patch somewhere for me to investigate.
> >
> > I am surprised that no Glib::Error exception is registered for
> > gnome-vfsmm.
>
> There's a separate Gnome::Vfs::exception [not registered as any kind
> of wrapping] which inherits directly from Glib::Exception. Maybe this
> should be rearranged to inherit from Glib::Error, but I suppose that
> would break backward ABI compatibility.

Maybe that has worked because we have never thrown a Vfs exception by
automatically mapping a GError to the exception. I guess we throw them
directly after checking more complicated conditions. Or maybe we just go
lucky.

To be consistent with that, I think you will want to use a
std::auto_ptr<Gnome::Vfs::exception> if possible, instead of a
std::auto_ptr<Glib::Error>. But that doesn't explain the crash.

Good idea. What's the preferred way to handle situations like this:

 Handle::~Handle()
 {
   if(gobj())
     close(); // This may throw an exception
 }

There's not really an opportunity to pass back the auto_ptr<exception>
in this case. Should we just do:

 Handle::~Handle()
 {
   if(gobj())
   {
     std::auto_ptr<Gnome::Vfs::exception> error;
     close(error);
   }
 }

and ignore the fact that the error may be set?


--
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]