diff options
-rw-r--r-- | cpp/include/Slice/SignalHandler.h | 12 | ||||
-rw-r--r-- | cpp/src/Slice/JavaUtil.cpp | 21 | ||||
-rw-r--r-- | cpp/src/Slice/Preprocessor.cpp | 18 | ||||
-rw-r--r-- | cpp/src/Slice/SignalHandler.cpp | 79 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 27 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Main.cpp | 5 | ||||
-rw-r--r-- | cpp/src/slice2cs/Gen.cpp | 23 | ||||
-rw-r--r-- | cpp/src/slice2cs/Main.cpp | 5 | ||||
-rw-r--r-- | cpp/src/slice2docbook/Main.cpp | 6 | ||||
-rw-r--r-- | cpp/src/slice2freeze/Main.cpp | 87 | ||||
-rw-r--r-- | cpp/src/slice2freezej/Main.cpp | 4 | ||||
-rw-r--r-- | cpp/src/slice2html/Gen.cpp | 22 | ||||
-rw-r--r-- | cpp/src/slice2html/Main.cpp | 4 | ||||
-rw-r--r-- | cpp/src/slice2java/Main.cpp | 5 | ||||
-rw-r--r-- | cpp/src/slice2py/Main.cpp | 33 | ||||
-rw-r--r-- | cpp/src/slice2rb/Main.cpp | 33 |
16 files changed, 269 insertions, 115 deletions
diff --git a/cpp/include/Slice/SignalHandler.h b/cpp/include/Slice/SignalHandler.h index 4914de3092d..6d5214314fe 100644 --- a/cpp/include/Slice/SignalHandler.h +++ b/cpp/include/Slice/SignalHandler.h @@ -11,6 +11,7 @@ #define SLICE_SIGNAL_HANDLER_H #include <IceUtil/Config.h> +#include <IceUtil/OutputUtil.h> #include <string> #ifndef SLICE_API @@ -24,14 +25,19 @@ namespace Slice { +typedef void (*SignalHandlerCloseCallback)(); + class SLICE_API SignalHandler { public: - SignalHandler(); - ~SignalHandler(); + static void addFileForCleanup(const std::string&); + + static void setCloseCallback(SignalHandlerCloseCallback); + + static void clearCleanupFileList(); - static void addFile(const std::string&); + static void removeFilesOnInterrupt(int signal); }; } diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp index 3179c3df7c5..2a2aac1ca0d 100644 --- a/cpp/src/Slice/JavaUtil.cpp +++ b/cpp/src/Slice/JavaUtil.cpp @@ -27,6 +27,19 @@ using namespace Slice; using namespace IceUtil; using namespace IceUtilInternal; +// +// Callback for Crtl-C signal handling +// +static Slice::JavaGenerator* _javaGen = 0; + +static void closeCallback() +{ + if(_javaGen != 0) + { + _javaGen->close(); + } +} + Slice::JavaOutput::JavaOutput() { } @@ -110,7 +123,7 @@ Slice::JavaOutput::openClass(const string& cls, const string& prefix) path += "/"; } path += file; - SignalHandler::addFile(path); + SignalHandler::addFileForCleanup(path); open(path.c_str()); if(isOpen()) @@ -160,7 +173,7 @@ Slice::JavaGenerator::JavaGenerator(const string& dir) : _dir(dir), _out(0) { - //SignalHandler::setCallback(closeCallback); + SignalHandler::setCloseCallback(closeCallback); } Slice::JavaGenerator::JavaGenerator(const string& dir, Slice::FeatureProfile profile) : @@ -173,6 +186,8 @@ Slice::JavaGenerator::JavaGenerator(const string& dir, Slice::FeatureProfile pro Slice::JavaGenerator::~JavaGenerator() { assert(_out == 0); + + SignalHandler::setCloseCallback(0); } bool @@ -184,6 +199,7 @@ Slice::JavaGenerator::open(const string& absolute) if(out->openClass(absolute, _dir)) { _out = out; + _javaGen = this; // For Ctrl-C handling } else { @@ -198,6 +214,7 @@ Slice::JavaGenerator::close() { assert(_out != 0); *_out << nl; + _javaGen = this; // For Ctrl-C handling delete _out; _out = 0; } diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp index 8c7f1983413..1d331f24387 100644 --- a/cpp/src/Slice/Preprocessor.cpp +++ b/cpp/src/Slice/Preprocessor.cpp @@ -29,6 +29,19 @@ using namespace std; using namespace Slice; // +// Callback for Crtl-C signal handling +// +static Preprocessor* _preprocess = 0; + +static void closeCallback() +{ + if(_preprocess != 0) + { + _preprocess->close(); + } +} + +// // mcpp defines // namespace Slice @@ -51,6 +64,8 @@ Slice::Preprocessor::Preprocessor(const string& path, const string& fileName, co _args(args), _cppHandle(0) { + _preprocess = this; + SignalHandler::setCloseCallback(closeCallback); } Slice::Preprocessor::~Preprocessor() @@ -437,6 +452,9 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin bool Slice::Preprocessor::close() { + _preprocess = 0; + SignalHandler::setCloseCallback(0); + if(_cppHandle != 0) { int status = fclose(_cppHandle); diff --git a/cpp/src/Slice/SignalHandler.cpp b/cpp/src/Slice/SignalHandler.cpp index fa693d88db7..8fd0261da42 100644 --- a/cpp/src/Slice/SignalHandler.cpp +++ b/cpp/src/Slice/SignalHandler.cpp @@ -7,66 +7,61 @@ // // ********************************************************************** -#include <IceUtil/DisableWarnings.h> #include <Slice/SignalHandler.h> -#include <vector> -#include <cstdlib> +#include <IceUtil/StaticMutex.h> +#include <map> -#ifndef _WIN32 -# include <signal.h> -#endif - - -using namespace std; using namespace Slice; +using namespace IceUtil; +using namespace IceUtilInternal; +using namespace std; -// -// Signal handler routine to unlink output files in case of translator -// being interrupted. -// +static StaticMutex _mutex = ICE_STATIC_MUTEX_INITIALIZER; + +static SignalHandlerCloseCallback _callback = 0; static vector<string> _fileList; -#ifdef _WIN32 -static BOOL WINAPI signalHandler(DWORD dwCtrlType) -#else -static void signalHandler(int signal) -#endif +void +SignalHandler::addFileForCleanup(const string& file) { - for(unsigned int i = 0; i < _fileList.size(); ++i) - { - remove(_fileList[i].c_str()); - } + StaticMutex::Lock lock(_mutex); - exit(1); +cout << "Adding " << file << endl; + _fileList.push_back(file); } - -Slice::SignalHandler::SignalHandler() +void +SignalHandler::setCloseCallback(Slice::SignalHandlerCloseCallback callback) { -#ifdef _WIN32 - SetConsoleCtrlHandler(signalHandler, TRUE); -#else - sigset(SIGHUP, signalHandler); - sigset(SIGINT, signalHandler); - sigset(SIGQUIT, signalHandler); -#endif + _callback = callback; } -Slice::SignalHandler::~SignalHandler() +void +SignalHandler::clearCleanupFileList() { -#ifdef _WIN32 - SetConsoleCtrlHandler(signalHandler, FALSE); -#else - sigset(SIGHUP, SIG_DFL); - sigset(SIGINT, SIG_DFL); - sigset(SIGQUIT, SIG_DFL); -#endif + StaticMutex::Lock lock(_mutex); +cout << "Clearing files" << endl; _fileList.clear(); + _callback = 0; } void -Slice::SignalHandler::addFile(const string& file) +SignalHandler::removeFilesOnInterrupt(int signal) { - _fileList.push_back(file); + StaticMutex::Lock lock(_mutex); + +cout << "Removing files" << endl; + if(_callback != 0) + { + _callback(); + } + + for(unsigned int i = 0; i < _fileList.size(); ++i) + { +cout << " Removing " << _fileList[i] << endl; + remove(_fileList[i].c_str()); + } + + exit(1); } diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 4c0eb293823..73a3673e655 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -23,6 +23,19 @@ using namespace Slice; using namespace IceUtil; using namespace IceUtilInternal; +// +// Callback for Crtl-C signal handling +// +static Gen* _gen = 0; + +static void closeCallback() +{ + if(_gen != 0) + { + _gen->closeOutput(); + } +} + static string getDeprecateSymbol(const ContainedPtr& p1, const ContainedPtr& p2) { @@ -51,6 +64,9 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte _stream(stream), _ice(ice) { + _gen = this; + SignalHandler::setCloseCallback(closeCallback); + for(vector<string>::iterator p = _includePaths.begin(); p != _includePaths.end(); ++p) { *p = fullPath(*p); @@ -71,8 +87,6 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte fileImplH = dir + '/' + fileImplH; fileImplC = dir + '/' + fileImplC; } - SignalHandler::addFile(fileImplH); - SignalHandler::addFile(fileImplC); struct stat st; if(stat(fileImplH.c_str(), &st) == 0) @@ -86,6 +100,7 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte return; } + SignalHandler::addFileForCleanup(fileImplH); implH.open(fileImplH.c_str()); if(!implH) { @@ -93,6 +108,7 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte return; } + SignalHandler::addFileForCleanup(fileImplC); implC.open(fileImplC.c_str()); if(!implC) { @@ -118,9 +134,8 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte fileH = dir + '/' + fileH; fileC = dir + '/' + fileC; } - SignalHandler::addFile(fileH); - SignalHandler::addFile(fileC); + SignalHandler::addFileForCleanup(fileH); H.open(fileH.c_str()); if(!H) { @@ -128,6 +143,7 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte return; } + SignalHandler::addFileForCleanup(fileC); C.open(fileC.c_str()); if(!C) { @@ -161,6 +177,9 @@ Slice::Gen::~Gen() implH << "\n\n#endif\n"; implC << '\n'; } + + _gen = 0; + SignalHandler::setCloseCallback(0); } bool diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp index 0fef7634add..4ead491dd22 100644 --- a/cpp/src/slice2cpp/Main.cpp +++ b/cpp/src/slice2cpp/Main.cpp @@ -8,6 +8,7 @@ // ********************************************************************** #include <IceUtil/Options.h> +#include <IceUtil/CtrlCHandler.h> #include <Slice/Preprocessor.h> #include <Slice/SignalHandler.h> #include <Gen.h> @@ -151,7 +152,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); if(depend) { diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 8cd18659005..ac5f55098d0 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -39,6 +39,19 @@ using IceUtilInternal::eb; using IceUtilInternal::spar; using IceUtilInternal::epar; +// +// Callback for Crtl-C signal handling +// +static Gen* _gen = 0; + +static void closeCallback() +{ + if(_gen != 0) + { + _gen->closeOutput(); + } +} + static string // Should be an anonymous namespace, but VC++ 6 can't handle that. sliceModeToIceMode(Operation::Mode opMode) { @@ -1059,6 +1072,9 @@ Slice::Gen::Gen(const string& name, const string& base, const vector<string>& in : _includePaths(includePaths), _stream(stream) { + _gen = this; + SignalHandler::setCloseCallback(closeCallback); + string fileBase = base; string::size_type pos = base.find_last_of("/\\"); if(pos != string::npos) @@ -1073,9 +1089,8 @@ Slice::Gen::Gen(const string& name, const string& base, const vector<string>& in file = dir + '/' + file; fileImpl = dir + '/' + fileImpl; } - SignalHandler::addFile(file); - SignalHandler::addFile(fileImpl); + SignalHandler::addFileForCleanup(file); _out.open(file.c_str()); if(!_out) { @@ -1111,6 +1126,8 @@ Slice::Gen::Gen(const string& name, const string& base, const vector<string>& in cerr << name << ": `" << fileImpl << "' already exists--will not overwrite" << endl; return; } + + SignalHandler::addFileForCleanup(fileImpl); _impl.open(fileImpl.c_str()); if(!_impl) { @@ -1130,6 +1147,8 @@ Slice::Gen::~Gen() { _impl << '\n'; } + + SignalHandler::setCloseCallback(0); } bool diff --git a/cpp/src/slice2cs/Main.cpp b/cpp/src/slice2cs/Main.cpp index 770ee8b5ea4..236e5b6da46 100644 --- a/cpp/src/slice2cs/Main.cpp +++ b/cpp/src/slice2cs/Main.cpp @@ -8,6 +8,7 @@ // ********************************************************************** #include <IceUtil/Options.h> +#include <IceUtil/CtrlCHandler.h> #include <Slice/Preprocessor.h> #include <Slice/SignalHandler.h> #include <Gen.h> @@ -146,7 +147,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); if(depend) { diff --git a/cpp/src/slice2docbook/Main.cpp b/cpp/src/slice2docbook/Main.cpp index 4386ceae454..b7ffe832082 100644 --- a/cpp/src/slice2docbook/Main.cpp +++ b/cpp/src/slice2docbook/Main.cpp @@ -9,6 +9,7 @@ #include <IceUtil/Options.h> #include <IceUtil/StringUtil.h> +#include <IceUtil/CtrlCHandler.h> #include <Slice/Preprocessor.h> #include <Slice/SignalHandler.h> #include <Gen.h> @@ -150,7 +151,8 @@ main(int argc, char* argv[]) int status = EXIT_SUCCESS; - SignalHandler sigHandler; + IceUtil::CtrlCHandler ctrlCHandler; + ctrlCHandler.setCallback(SignalHandler::removeFilesOnInterrupt); for(vector<string>::size_type idx = 1; idx < args.size(); ++idx) { @@ -188,7 +190,7 @@ main(int argc, char* argv[]) if(status == EXIT_SUCCESS && !preprocess) { - SignalHandler::addFile(docbook); + SignalHandler::addFileForCleanup(docbook); Gen gen(argv[0], docbook, standAlone, chapter, noIndex, sortFields); if(!gen) diff --git a/cpp/src/slice2freeze/Main.cpp b/cpp/src/slice2freeze/Main.cpp index 2cf304eb7bc..4b3072b066f 100644 --- a/cpp/src/slice2freeze/Main.cpp +++ b/cpp/src/slice2freeze/Main.cpp @@ -9,6 +9,7 @@ #include <IceUtil/DisableWarnings.h> #include <IceUtil/Options.h> +#include <IceUtil/CtrlCHandler.h> #include <Slice/Preprocessor.h> #include <Slice/Util.h> #include <Slice/CPlusPlusUtil.h> @@ -22,6 +23,18 @@ using namespace IceUtil; using namespace IceUtilInternal; using namespace Slice; +static ::IceUtilInternal::Output _H; +static ::IceUtilInternal::Output _CPP; + +// +// Callback for Crtl-C signal handling +// +static void closeCallback() +{ + _H.close(); + _CPP.close(); +} + static string ICE_ENCODING_COMPARE = "Freeze::IceEncodingCompare"; class MetaDataVisitor : public ParserVisitor @@ -1780,7 +1793,8 @@ main(int argc, char* argv[]) int status = EXIT_SUCCESS; - SignalHandler sigHandler; + IceUtil::CtrlCHandler ctrlCHandler; + ctrlCHandler.setCallback(SignalHandler::removeFilesOnInterrupt); for(vector<string>::size_type idx = 1; idx < args.size(); ++idx) { @@ -1839,30 +1853,29 @@ main(int argc, char* argv[]) } } - SignalHandler::addFile(fileH); - SignalHandler::addFile(fileC); + SignalHandler::setCloseCallback(closeCallback); - Output H; - H.open(fileH.c_str()); - if(!H) + SignalHandler::addFileForCleanup(fileH); + _H.open(fileH.c_str()); + if(!_H) { cerr << argv[0] << ": can't open `" << fileH << "' for writing: " << strerror(errno) << endl; u->destroy(); return EXIT_FAILURE; } - printHeader(H); - printFreezeTypes(H, dicts, indices); + printHeader(_H); + printFreezeTypes(_H, dicts, indices); - Output CPP; - CPP.open(fileC.c_str()); - if(!CPP) + SignalHandler::addFileForCleanup(fileC); + _CPP.open(fileC.c_str()); + if(!_CPP) { cerr << argv[0] << ": can't open `" << fileC << "' for writing: " << strerror(errno) << endl; u->destroy(); return EXIT_FAILURE; } - printHeader(CPP); - printFreezeTypes(CPP, dicts, indices); + printHeader(_CPP); + printFreezeTypes(_CPP, dicts, indices); for(vector<string>::const_iterator i = extraHeaders.begin(); i != extraHeaders.end(); ++i) { @@ -1876,57 +1889,57 @@ main(int argc, char* argv[]) } if(!guard.empty()) { - CPP << "\n#ifndef " << guard; - CPP << "\n#define " << guard; + _CPP << "\n#ifndef " << guard; + _CPP << "\n#define " << guard; } - CPP << "\n#include <"; + _CPP << "\n#include <"; if(!include.empty()) { - CPP << include << '/'; + _CPP << include << '/'; } - CPP << hdr << '>'; + _CPP << hdr << '>'; if(!guard.empty()) { - CPP << "\n#endif"; + _CPP << "\n#endif"; } } string s = fileH; transform(s.begin(), s.end(), s.begin(), ToIfdef()); - H << "\n#ifndef __" << s << "__"; - H << "\n#define __" << s << "__"; - H << '\n'; + _H << "\n#ifndef __" << s << "__"; + _H << "\n#define __" << s << "__"; + _H << '\n'; if(dicts.size() > 0) { - H << "\n#include <Freeze/Map.h>"; + _H << "\n#include <Freeze/Map.h>"; } if(indices.size() > 0) { - H << "\n#include <Freeze/Index.h>"; + _H << "\n#include <Freeze/Index.h>"; } { for(StringList::const_iterator p = includes.begin(); p != includes.end(); ++p) { - H << "\n#include <" << changeInclude(*p, includePaths) << "." + headerExtension + ">"; + _H << "\n#include <" << changeInclude(*p, includePaths) << "." + headerExtension + ">"; } } - CPP << "\n#include <Ice/BasicStream.h>"; - CPP << "\n#include <"; + _CPP << "\n#include <Ice/BasicStream.h>"; + _CPP << "\n#include <"; if(include.size()) { - CPP << include << '/'; + _CPP << include << '/'; } - CPP << includeH << '>'; + _CPP << includeH << '>'; - printVersionCheck(H); - printVersionCheck(CPP); + printVersionCheck(_H); + printVersionCheck(_CPP); - printDllExportStuff(H, dllExport); + printDllExportStuff(_H, dllExport); if(dllExport.size()) { dllExport += " "; @@ -1937,7 +1950,7 @@ main(int argc, char* argv[]) { try { - if(!writeDict(argv[0], u, *p, H, CPP, dllExport)) + if(!writeDict(argv[0], u, *p, _H, _CPP, dllExport)) { u->destroy(); return EXIT_FAILURE; @@ -1956,7 +1969,7 @@ main(int argc, char* argv[]) { try { - if(!writeIndex(argv[0], u, *q, H, CPP, dllExport)) + if(!writeIndex(argv[0], u, *q, _H, _CPP, dllExport)) { u->destroy(); return EXIT_FAILURE; @@ -1972,9 +1985,11 @@ main(int argc, char* argv[]) } - H << "\n\n#endif\n"; - CPP << '\n'; + _H << "\n\n#endif\n"; + _CPP << '\n'; + _H.close(); + _CPP.close(); } u->destroy(); diff --git a/cpp/src/slice2freezej/Main.cpp b/cpp/src/slice2freezej/Main.cpp index 709de7a58cb..69fbbd3327e 100644 --- a/cpp/src/slice2freezej/Main.cpp +++ b/cpp/src/slice2freezej/Main.cpp @@ -9,6 +9,7 @@ #include <IceUtil/Options.h> #include <IceUtil/StringUtil.h> +#include <IceUtil/CtrlCHandler.h> #include <Slice/Preprocessor.h> #include <Slice/JavaUtil.h> #include <Slice/SignalHandler.h> @@ -1421,7 +1422,8 @@ main(int argc, char* argv[]) int status = EXIT_SUCCESS; - SignalHandler sigHandler; + IceUtil::CtrlCHandler ctrlCHandler; + ctrlCHandler.setCallback(SignalHandler::removeFilesOnInterrupt); for(vector<string>::size_type idx = 0; idx < args.size(); ++idx) { diff --git a/cpp/src/slice2html/Gen.cpp b/cpp/src/slice2html/Gen.cpp index 91a114601de..3be0eecb3e2 100644 --- a/cpp/src/slice2html/Gen.cpp +++ b/cpp/src/slice2html/Gen.cpp @@ -30,6 +30,20 @@ using namespace Slice; using namespace IceUtil; using namespace IceUtilInternal; +// +// Callback for Crtl-C signal handling +// +static GeneratorBase* _genBase = 0; + +static void closeCallback() +{ + if(_genBase != 0) + { + _genBase->closeStream(); + } +} + + namespace Slice { @@ -38,6 +52,8 @@ generate(const UnitPtr& unit, const string& dir, const string& header, const str const string& indexHeader, const string& indexFooter, const string& imageDir, const string& logoURL, const string& searchAction, unsigned indexCount, unsigned warnSummary) { + SignalHandler::setCloseCallback(closeCallback); + unit->mergeModules(); // @@ -87,6 +103,8 @@ generate(const UnitPtr& unit, const string& dir, const string& header, const str GeneratorBase::setSymbols(tocv.symbols()); PageVisitor v(files); unit->visit(&v, false); + + SignalHandler::setCloseCallback(0); } } @@ -196,10 +214,12 @@ Slice::GeneratorBase::setSymbols(const ContainedList& symbols) Slice::GeneratorBase::GeneratorBase(XMLOutput& o, const Files& files) : _out(o), _files(files) { + _genBase = this; } Slice::GeneratorBase::~GeneratorBase() { + _genBase = 0; } // @@ -1242,7 +1262,7 @@ Slice::GeneratorBase::getLogoURL() void Slice::GeneratorBase::openStream(const string& path) { - SignalHandler::addFile(path); + SignalHandler::addFileForCleanup(path); _out.open(path.c_str()); if(!_out.isOpen()) diff --git a/cpp/src/slice2html/Main.cpp b/cpp/src/slice2html/Main.cpp index d7a3b1911bc..b63082571bb 100644 --- a/cpp/src/slice2html/Main.cpp +++ b/cpp/src/slice2html/Main.cpp @@ -8,6 +8,7 @@ // ********************************************************************** #include <IceUtil/Options.h> +#include <IceUtil/CtrlCHandler.h> #include <Slice/Preprocessor.h> #include <Slice/SignalHandler.h> #include <Gen.h> @@ -173,7 +174,8 @@ main(int argc, char* argv[]) int status = EXIT_SUCCESS; - SignalHandler sigHandler; + IceUtil::CtrlCHandler ctrlCHandler; + ctrlCHandler.setCallback(SignalHandler::removeFilesOnInterrupt); for(vector<string>::size_type idx = 0; idx < args.size(); ++idx) { diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp index 1b16f9ddb14..bfee9cfce90 100644 --- a/cpp/src/slice2java/Main.cpp +++ b/cpp/src/slice2java/Main.cpp @@ -8,6 +8,7 @@ // ********************************************************************** #include <IceUtil/Options.h> +#include <IceUtil/CtrlCHandler.h> #include <Slice/Preprocessor.h> #include <Slice/SignalHandler.h> #include <Gen.h> @@ -176,7 +177,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); if(depend) { 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. diff --git a/cpp/src/slice2rb/Main.cpp b/cpp/src/slice2rb/Main.cpp index 2e91d3c1d8a..b52f8f0d1cd 100644 --- a/cpp/src/slice2rb/Main.cpp +++ b/cpp/src/slice2rb/Main.cpp @@ -9,6 +9,7 @@ #include <IceUtil/DisableWarnings.h> #include <IceUtil/Options.h> +#include <IceUtil/CtrlCHandler.h> #include <Slice/Preprocessor.h> #include <Slice/RubyUtil.h> #include <Slice/SignalHandler.h> @@ -30,6 +31,16 @@ using namespace std; using namespace Slice; using namespace Slice::Ruby; +// +// Callback for Crtl-C signal handling +// +static IceUtilInternal::Output _out; + +static void closeCallback() +{ + _out.close(); +} + void usage(const char* n) { @@ -138,7 +149,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); @@ -192,26 +205,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 Ruby mapping. // - generate(u, all, checksum, includePaths, out); + generate(u, all, checksum, includePaths, _out); - out.close(); + _out.close(); + SignalHandler::setCloseCallback(0); } u->destroy(); |