summaryrefslogtreecommitdiff
path: root/cpp/src/slice2py
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/slice2py')
-rw-r--r--cpp/src/slice2py/Main.cpp33
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.