GNOME Bugzilla – Bug 528286
Unable to catch exception from Glib::spawn_async_with_pipes on windows
Last modified: 2010-06-09 21:18:00 UTC
reported on irc by aib42: When trying to use spawn_async_with_pipes, it doesn't seem possible to catch the exception thrown: /***** main.cpp *****/ #include <gtkmm.h> #include <iostream> void foo() { std::cout << "foo()" << std::endl; } int main() { std::vector<std::string> v(1); v[0] = std::string("C:\\Windows\\system32\\cmd.exe"); std::cout << "Spawning: " << v[0] << std::endl; Glib::Pid p; try { Glib::spawn_async(Glib::get_current_dir(), v, Glib::SpawnFlags(0), sigc::ptr_fun(foo), &p); // Glib::spawn_async(Glib::get_current_dir(), v, Glib::SpawnFlags(0), sigc::slot<void>(), &p); } catch (Glib::Error e) { std::cerr << "Error: " << e.what() << std::endl; } catch (...) { std::cerr << "Uncaught exception" << std::endl; } std::cout << "Hello, World!" << std::endl; } /***** make output *****/ g++ -O2 -g -Wall -fmessage-length=0 -mms-bitfields -IC:/SDK/GTK+-2.10.11-1/include/gtkmm-2.4 -IC:/SDK/GTK+-2.10.11-1/lib/gtkmm-2.4/include -IC:/SDK/GTK+-2.10.11-1/include/glibmm-2.4 -IC:/SDK/GTK+-2.10.11-1/lib/glibmm-2.4/include -IC:/SDK/GTK+-2.10.11-1/include/gdkmm-2.4 -IC:/SDK/GTK+-2.10.11-1/lib/gdkmm-2.4/include -IC:/SDK/GTK+-2.10.11-1/include/pangomm-1.4 -IC:/SDK/GTK+-2.10.11-1/include/atkmm-1.6 -IC:/SDK/GTK+-2.10.11-1/include/gtk-2.0 -IC:/SDK/GTK+-2.10.11-1/include/sigc++-2.0 -IC:/SDK/GTK+-2.10.11-1/lib/sigc++-2.0/include -IC:/SDK/GTK+-2.10.11-1/include/glib-2.0 -IC:/SDK/GTK+-2.10.11-1/lib/glib-2.0/include -IC:/SDK/GTK+-2.10.11-1/lib/gtk-2.0/include -IC:/SDK/GTK+-2.10.11-1/include/cairomm-1.0 -IC:/SDK/GTK+-2.10.11-1/include/pango-1.0 -IC:/SDK/GTK+-2.10.11-1/include/cairo -IC:/SDK/GTK+-2.10.11-1/include/freetype2 -IC:/SDK/GTK+-2.10.11-1/include -IC:/SDK/GTK+-2.10.11-1/include/atk-1.0 -c main.cpp g++ -o GTKonsole.exe main.o -user32 -Wl,-luuid -LC:/SDK/GTK+-2.10.11-1/lib -lgtkmm-2.4 -lgdkmm-2.4 -latkmm-1.6 -lgtk-win32-2.0 -lpangomm-1.4 -lcairomm-1.0 -lglibmm-2.4 -lsigc-2.0 -lgdk-win32-2.0 -lgdi32 -limm32 -lshell32 -lole32 -latk-1.0 -lgdk_pixbuf-2.0 -lpangowin32-1.0 -lpangocairo-1.0 -lcairo -lpangoft2-1.0 -lfontconfig -lfreetype -lz -lpango-1.0 -lm -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl -liconv /***** versions *****/ g++ (GCC) 3.4.5 (mingw special) GTK: 2.10.11-1 (Win32 installer) gtkmm/glibmm: 2.4 /***** output *****/ 21:47:35 X:\GTKonsole>GTKonsole.exe Spawning: C:\Windows\system32\cmd.exe (GTKonsole.exe:1552): GLib-WARNING **: passing a child setup function to the g_spawn functions is pointless and dangerou s on Win32 foo() This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. 21:47:41 X:\GTKonsole>
additional info from IRC: (2:25:23 PM) armin: I already had problems with exceptions not getting caught on Win32 when a dynamic library throws an exception that I tried to catch in an executable built with a different compiler. (2:25:28 PM) armin: Or, this is what I assumed to be the cause. (2:25:41 PM) jonner: armin: ugh (2:26:18 PM) jonner: so it doesn't work if the default gtkmm binaries are built with msvc, and the application is mingw...? (2:26:39 PM) armin: I think so
The test case seems to work for me. I get this output: Spawning: C:\Windows\system32\cmd.exe foo() Error: Failed to execute child process "C:\Windows\system32\cmd.exe" (No such file or directory) Hello, World! Isn't is working for you, Jonathan? Why didn't aib42 submit this bug so we could ask him about it?
I don't have an easy way to test on windows, so I don't know whether it works or not. I filed the bug since he/she wasn't comfortable doing so, and I didn't want to lose it in case it was real. But he/she is cc-ed to this bug if you have additional questions.
Yup, I'm here. I'm sorry, as the "New Bug Wizard" was somewhat GTK-application-oriented, I accepted when Jonathon offered to file it for me. Are you using mingw as well, Murray?
> Are you using mingw as well, Murray? No. Are you using multiple compilers?
Ahh, I think that's it. (Or at least that's what the first comment suggests) I have MSVC express edition, gcc/mingw and gcc/cygwin on my computer. Oh, and I have MSVC 2008 here on my work computer. I've only tried this with gcc at home, though. Maybe I should try building gtkmm/glib from the sources? That should take care of the ABI issues, right?
Well where did you get the gtkmm that you now have?
http://ftp.gnome.org/pub/gnome/binaries/win32/gtkmm/2.10/gtkmm-win32-devel-2.10.11-1.exe linked from http://www.gtkmm.org/download.shtml
I thought that the gtkmm Windows installer provided versions for multiple compilers. Cedric, I guess we still need a page that describes that installer.
I wonder if somebody could test this bug with armin's new installers and (possibly) close it if things work as expected.
Orhan, could you please try the latest installer.
Aha! " 23:56:21 X:\GTKonsole>gtkonsole Spawning: C:\Windows\system32\cmd.exe (GTKonsole.exe:476): GLib-WARNING **: passing a child setup function to the g_spawn functions is pointless on Windows and it is ignored Hello, World! 23:56:30 X:\GTKonsole>Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. 23:56:30 X:\GTKonsole> " The new installer seems to work. Notice that foo() isn't called and the program terminates cleanly with "Hello, World!". Thanks. -- MinGW version: 23:56:30 X:\GTKonsole>g++ -v Reading specs from C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/specs Configured with: ../gcc-3.4.5-20060117-3/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw3 2 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --d isable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-l ibgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug Thread model: win32 gcc version 3.4.5 (mingw-vista special r3) mingw32-make output: g++ -O2 -g -Wall -fmessage-length=0 `pkg-config gtkmm-2.4 cairo pango --cflags` -c -o main.o main.cpp g++ -o GTKonsole.exe main.o `pkg-config gtkmm-2.4 cairo pango --libs`
Thanks. Closing then.