I'm implementing the --enable-api-exceptions=no functionality for
gnome-vfsmm. I don't see a mailing list dedicated to it, so I consult
the collective wisdom here instead.

Most of the wrapper methods in it have a pattern like this:

  void foo()
  {
    GnomeVFSResult result = gnome_vfs_foo();
    handle_result(result);
  }

  void handle_result(GnomeVFSResult result) throw(Gnome::Vfs::Exception)
  {
    if(result != GNOME_VFS_OK)
      throw(Gnome::Vfs::exception(static_cast<Gnome::Vfs::Result>(result)));
  }

To add the exception-less mode, I've converted those to

  #ifdef GLIBMM_EXCEPTIONS_ENABLED
  void foo()
  #else
  void foo(std::auto_ptr<Glib::Error>& error)
  #endif
  {
    GnomeVFSResult result = gnome_vfs_foo();
  #ifdef GLIBMM_EXCEPTIONS_ENABLED
    handle_result(result);
  #else
    handle_result(result, error);
  #endif
  }

  #ifdef GLIBMM_EXCEPTIONS_ENABLED
  void handle_result(GnomeVFSResult result)
  {
     .. unchanged ...
  }
  #else
  void handle_result(GnomeVFSResult result, std::auto_ptr<Glib::Error>& error)
  {
    if(result != GNOME_VFS_OK)
    {
      Gnome::Vfs::exception e(static_cast<Gnome::Vfs::Result>(result));
      GError* gerror = NULL;

      g_set_error(&gerror,
                  error_quark(), /* my own custom quark; none is
registered by GnomeVFS */
                  0, /* dummy code */
                  e.what().c_str());

      error = ::Glib::Error::throw_exception(gerror);
    }
  }

I've registered a throw function for that custom GQuark above, and it
looks like this:

  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.
_______________________________________________
gtkmm-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to