On Wed, 2006-09-27 at 08:18 +0200, Murray Cumming wrote: > > The reference manual seems to suggest that the following makes sense: > > > > try { Gtk::Main application ( ac , av , context ) ; } > > catch ( Glib::OptionError e ) { std::cout << e.what ( ) << std::endl ; > > return 1 ; } > > It's unlikely to be the problem (and I haven't read this whole thread > yet), but you should catch exceptions by const reference: > > catch (const Glib::OptionError& e ) Indeed. Too much Java :-) To summarize, I have three problems: 1. The code: Glib::ustring name ( "gfontbrowser" ) ; bool version ( FALSE ) ; Glib::OptionEntry entry ; entry.set_long_name ( _( "version" ) ) ; entry.set_description ( _( "Show version and exit." ) ) ; Glib::OptionGroup options ( name , "GFontBrowser" ) ; options.add_entry ( entry , version ) ; Glib::OptionContext context ( _( "-- A font browser for GTK+, Fontconfig, Pango based systems." ) ) ; context.add_group ( options ) ; context.set_main_group ( options ) ; Gtk::Main application ( ac , av , context ) ; does what it is expected to but if I replace the last line with: try { Gtk::Main application ( ac , av , context ) ; } catch ( const Glib::OptionError & e ) { std::cout << e.what ( ) << std::endl ; return 1 ; } then I get a seg fault. 2. When either of the above start I get a whole slew of error messages report assertion violations but I have no idea why: (gfontbrowser:8064): Gnome-CRITICAL **: gnome_program_get_app_id: assertion `program != NULL' failed (gfontbrowser:8064): GLib-CRITICAL **: g_string_prepend: assertion `val != NULL' failed (gfontbrowser:8064): Gnome-CRITICAL **: gnome_program_get_app_id: assertion `program != NULL' failed (gfontbrowser:8064): GConf-CRITICAL **: gconf_escape_key: assertion `arbitrary_text != NULL' failed (gfontbrowser:8064): GConf-CRITICAL **: gconf_client_add_dir: assertion `gconf_valid_key (dirname, NULL)' failed (gfontbrowser:8064): Gnome-CRITICAL **: gnome_program_locate_file: assertion `program != NULL' failed (gfontbrowser:8064): Gnome-CRITICAL **: gnome_program_locate_file: assertion `program != NULL' failed (gfontbrowser:8064): Gnome-CRITICAL **: gnome_program_get_app_id: assertion `program != NULL' failed (gfontbrowser:8064): GLib-CRITICAL **: g_string_prepend: assertion `val != NULL' failed (gfontbrowser:8064): Gtk-CRITICAL **: gtk_accel_map_add_entry: assertion `_gtk_accel_path_is_valid (accel_path)' failed (gfontbrowser:8064): Gtk-CRITICAL **: gtk_widget_set_accel_path: assertion `_gtk_accel_path_is_valid (accel_path)' failed (gfontbrowser:8064): Gnome-CRITICAL **: gnome_program_get_app_id: assertion `program != NULL' failed (gfontbrowser:8064): GLib-CRITICAL **: g_string_prepend: assertion `val != NULL' failed (gfontbrowser:8064): Gnome-CRITICAL **: gnome_program_get_app_id: assertion `program != NULL' failed (gfontbrowser:8064): GLib-CRITICAL **: g_string_prepend: assertion `val != NULL' failed (gfontbrowser:8064): Gtk-CRITICAL **: gtk_widget_set_accel_path: assertion `_gtk_accel_path_is_valid (accel_path)' failed (gfontbrowser:8064): Gnome-CRITICAL **: gnome_program_get_app_id: assertion `program != NULL' failed 3. When the program terminates I get: *** glibc detected *** free(): invalid pointer: 0x080b9910 *** Aborted If I replace the C++ above with the C code: gboolean version ( FALSE ) ; const GOptionEntry options[] = { { "version" , 0 , 0 , G_OPTION_ARG_NONE , &version , _( "Show version and exit." ) , 0 } , { 0 , '\0' , 0 , G_OPTION_ARG_NONE , 0 , 0 , 0 } } ; GError * error ( 0 ) ; GOptionContext *const context ( g_option_context_new ( _( "-- A font browser for GTK+, Fontconfig, Pango based systems." ) ) ) ; g_option_context_add_main_entries ( context , options , "gfontbrowser" ) ; g_option_context_add_group ( context , gtk_get_option_group ( TRUE ) ) ; const bool success ( g_option_context_parse ( context , &ac , &av , &error ) ) ; g_option_context_free ( context ) ; if ( ! success ) { std::cout << error->message << std::endl ; return 1 ; } if ( version ) { std::cout << g_get_prgname ( ) << " v" << VERSION << std::endl ; return 0 ; } Gtk::Main application ( ac , av ) ; everything works fine, no assertion failures. I should note problem 4: I get different help output. the C gives: Usage: gfontbrowser [OPTION...] -- A font browser for GTK+, Fontconfig, Pango based systems. Help Options: -?, --help Show help options --help-all Show all help options --help-gtk Show GTK+ Options GTK+ Options --class=CLASS Program class as used by the window manager --name=NAME Program name as used by the window manager --screen=SCREEN X screen to use --sync Make X calls synchronous --gtk-module=MODULES Load additional GTK+ modules --g-fatal-warnings Make all warnings fatal Application Options: --version Show version and exit. --display=DISPLAY X display to use whereas the C++ gives: Usage: gfontbrowser [OPTION...] -- A font browser for GTK+, Fontconfig, Pango based systems. Help Options: -?, --help Show help options --help-all Show all help options --help-gfontbrowser --help-gtk Show GTK+ Options GFontBrowser --gfontbrowser-version Show version and exit. GTK+ Options --class=CLASS Program class as used by the window manager --name=NAME Program name as used by the window manager --screen=SCREEN X screen to use --sync Make X calls synchronous --gtk-module=MODULES Load additional GTK+ modules --g-fatal-warnings Make all warnings fatal Application Options: --gfontbrowser-version Show version and exit. --display=DISPLAY X display to use but I had expected the output to be the same. -- Russel. ==================================================== Dr Russel Winder +44 20 7585 2200 41 Buckmaster Road +44 7770 465 077 London SW11 1EN, UK russel russel org uk
Attachment:
signature.asc
Description: This is a digitally signed message part