diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2008-11-19 11:06:31 -0330 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2008-11-19 11:06:31 -0330 |
commit | 7f24f7fd2361ff5d43775e4523bc78ffdb108306 (patch) | |
tree | 62d26962d53259163ee997a7172af5a8fb550a1d /cpp/src/slice2py/Main.cpp | |
parent | Bug 3541 - Slice signal handling unsafe (diff) | |
download | ice-7f24f7fd2361ff5d43775e4523bc78ffdb108306.tar.bz2 ice-7f24f7fd2361ff5d43775e4523bc78ffdb108306.tar.xz ice-7f24f7fd2361ff5d43775e4523bc78ffdb108306.zip |
Added use of CtrlChandler to slice compilers
Diffstat (limited to 'cpp/src/slice2py/Main.cpp')
-rw-r--r-- | cpp/src/slice2py/Main.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp index 7951141b1b3..fcae12e5e5e 100644 --- a/cpp/src/slice2py/Main.cpp +++ b/cpp/src/slice2py/Main.cpp @@ -11,6 +11,7 @@ #include <IceUtil/IceUtil.h> #include <IceUtil/Options.h> #include <IceUtil/StringUtil.h> +#include <IceUtil/CtrlCHandler.h> #include <Slice/Preprocessor.h> #include <Slice/PythonUtil.h> #include <Slice/SignalHandler.h> @@ -34,6 +35,16 @@ using namespace Slice; using namespace Slice::Python; // +// Callback for Crtl-C signal handling +// +static IceUtilInternal::Output _out; + +static void closeCallback() +{ + _out.close(); +} + +// // For each Slice file Foo.ice we generate Foo_ice.py containing the Python // mappings. Furthermore, for each Slice module M in Foo.ice, we create a // Python package of the same name. This package is simply a subdirectory @@ -477,7 +488,9 @@ main(int argc, char* argv[]) for(i = args.begin(); i != args.end(); ++i) { - SignalHandler sigHandler; + SignalHandler::clearCleanupFileList(); + IceUtil::CtrlCHandler ctrlCHandler; + ctrlCHandler.setCallback(SignalHandler::removeFilesOnInterrupt); Preprocessor icecpp(argv[0], *i, cppArgs); FILE* cppHandle = icecpp.preprocess(false); @@ -537,26 +550,28 @@ main(int argc, char* argv[]) { file = output + '/' + file; } - SignalHandler::addFile(file); - IceUtilInternal::Output out; - out.open(file.c_str()); - if(!out) + SignalHandler::setCloseCallback(closeCallback); + + SignalHandler::addFileForCleanup(file); + _out.open(file.c_str()); + if(!_out) { cerr << argv[0] << ": can't open `" << file << "' for writing" << endl; u->destroy(); return EXIT_FAILURE; } - printHeader(out); - out << "\n# Generated from file `" << base << ".ice'\n"; + printHeader(_out); + _out << "\n# Generated from file `" << base << ".ice'\n"; // // Generate the Python mapping. // - generate(u, all, checksum, includePaths, out); + generate(u, all, checksum, includePaths, _out); - out.close(); + _out.close(); + SignalHandler::setCloseCallback(0); // // Create or update the Python package hierarchy. |