summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2008-01-18 10:27:58 -0330
committerDwayne Boone <dwayne@zeroc.com>2008-01-18 10:27:58 -0330
commit40da4a3aecbc259c472d77f58d1d6466af42e5ef (patch)
tree3780215d0441c84682c9c281b3187b78973a6b9e /cpp/src
parentAdded Windows signal handling (diff)
downloadice-40da4a3aecbc259c472d77f58d1d6466af42e5ef.tar.bz2
ice-40da4a3aecbc259c472d77f58d1d6466af42e5ef.tar.xz
ice-40da4a3aecbc259c472d77f58d1d6466af42e5ef.zip
Windows fixes for translator interrupt cleanup
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IceUtil/OutputUtil.cpp9
-rw-r--r--cpp/src/Slice/JavaUtil.cpp17
-rw-r--r--cpp/src/Slice/Preprocessor.cpp45
-rw-r--r--cpp/src/Slice/RubyUtil.cpp2
-rw-r--r--cpp/src/Slice/SignalHandler.cpp13
-rwxr-xr-xcpp/src/slice2cpp/Gen.cpp27
-rw-r--r--cpp/src/slice2cpp/Gen.h1
-rw-r--r--cpp/src/slice2cppe/Gen.cpp27
-rw-r--r--cpp/src/slice2cppe/Gen.h1
-rwxr-xr-xcpp/src/slice2cs/Gen.cpp25
-rw-r--r--cpp/src/slice2cs/Gen.h1
-rw-r--r--cpp/src/slice2docbook/Gen.cpp24
-rw-r--r--cpp/src/slice2docbook/Gen.h1
-rw-r--r--cpp/src/slice2freeze/Main.cpp84
-rw-r--r--cpp/src/slice2html/Gen.cpp31
-rw-r--r--cpp/src/slice2html/Gen.h2
-rw-r--r--cpp/src/slice2py/Main.cpp26
-rw-r--r--cpp/src/slice2rb/Main.cpp25
-rwxr-xr-xcpp/src/slice2sl/Gen.cpp25
-rw-r--r--cpp/src/slice2sl/Gen.h1
20 files changed, 320 insertions, 67 deletions
diff --git a/cpp/src/IceUtil/OutputUtil.cpp b/cpp/src/IceUtil/OutputUtil.cpp
index 4f61c2a144c..d47c921c2d1 100644
--- a/cpp/src/IceUtil/OutputUtil.cpp
+++ b/cpp/src/IceUtil/OutputUtil.cpp
@@ -92,6 +92,15 @@ IceUtilInternal::OutputBase::open(const char* s)
_fout.open(s);
}
+void
+IceUtilInternal::OutputBase::close()
+{
+ if(_fout.is_open())
+ {
+ _fout.close();
+ }
+}
+
bool
IceUtilInternal::OutputBase::isOpen()
{
diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp
index cb4874a2df8..2c8cfde1458 100644
--- a/cpp/src/Slice/JavaUtil.cpp
+++ b/cpp/src/Slice/JavaUtil.cpp
@@ -27,6 +27,20 @@ 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()
{
}
@@ -160,6 +174,7 @@ Slice::JavaGenerator::JavaGenerator(const string& dir) :
_dir(dir),
_out(0)
{
+ SignalHandler::setCallback(closeCallback);
}
Slice::JavaGenerator::JavaGenerator(const string& dir, Slice::FeatureProfile profile) :
@@ -183,6 +198,7 @@ Slice::JavaGenerator::open(const string& absolute)
if(out->openClass(absolute, _dir))
{
_out = out;
+ _javaGen = this; // For Ctrl-C handling
}
else
{
@@ -199,6 +215,7 @@ Slice::JavaGenerator::close()
*_out << nl;
delete _out;
_out = 0;
+ _javaGen = 0; // For Ctrl-C handling
}
Output&
diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp
index d91bb1f069e..66474c113b7 100644
--- a/cpp/src/Slice/Preprocessor.cpp
+++ b/cpp/src/Slice/Preprocessor.cpp
@@ -27,6 +27,20 @@ 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
@@ -49,14 +63,16 @@ Slice::Preprocessor::Preprocessor(const string& path, const string& fileName, co
_args(args),
_cppHandle(0)
{
+ _preprocess = this;
+ SignalHandler::setCallback(closeCallback);
}
Slice::Preprocessor::~Preprocessor()
{
- if(_cppHandle)
- {
- close();
- }
+ _preprocess = 0;
+ SignalHandler::setCallback(0);
+
+ close();
}
string
@@ -412,21 +428,22 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin
bool
Slice::Preprocessor::close()
{
- assert(_cppHandle);
-
- int status = fclose(_cppHandle);
- _cppHandle = 0;
-
- if(status != 0)
+ if(_cppHandle != 0)
{
- return false;
- }
+ int status = fclose(_cppHandle);
+ _cppHandle = 0;
+
+ if(status != 0)
+ {
+ return false;
+ }
#ifdef _WIN32
- _unlink(_cppFile.c_str());
+ _unlink(_cppFile.c_str());
#else
- unlink(_cppFile.c_str());
+ unlink(_cppFile.c_str());
#endif
+ }
return true;
}
diff --git a/cpp/src/Slice/RubyUtil.cpp b/cpp/src/Slice/RubyUtil.cpp
index 1b078e08b7d..27a25fc7dc2 100644
--- a/cpp/src/Slice/RubyUtil.cpp
+++ b/cpp/src/Slice/RubyUtil.cpp
@@ -110,7 +110,7 @@ lookupKwd(const string& name)
{
"BEGIN", "END", "alias", "and", "begin", "break", "case", "class", "clone", "def", "display", "do", "dup",
"else", "elsif", "end", "ensure", "extend", "false", "for", "freeze", "hash", "if", "in", "inspect", "method",
- "methods", "module", "next", "new", "nil", "not", "or", "redo", "rescue", "retry", "return", "self", "send",
+ "methods", "module", "new", "next", "nil", "not", "or", "redo", "rescue", "retry", "return", "self", "send",
"super", "taint", "then", "true", "undef", "unless", "untaint", "until", "when", "while", "yield"
};
bool found = binary_search(&keywordList[0],
diff --git a/cpp/src/Slice/SignalHandler.cpp b/cpp/src/Slice/SignalHandler.cpp
index b1606a6b4f1..bbe5a3a4757 100644
--- a/cpp/src/Slice/SignalHandler.cpp
+++ b/cpp/src/Slice/SignalHandler.cpp
@@ -17,11 +17,13 @@
using namespace std;
+using namespace Slice;
//
// Signal handler routine to unlink output files in case of translator
// being interrupted.
//
+static SignalHandlerCallback _callback = 0;
static vector<string> _fileList;
#ifdef _WIN32
@@ -30,6 +32,11 @@ static BOOL WINAPI signalHandler(DWORD dwCtrlType)
static void signalHandler(int signal)
#endif
{
+ if(_callback != 0)
+ {
+ _callback();
+ }
+
for(unsigned int i = 0; i < _fileList.size(); ++i)
{
remove(_fileList[i].c_str());
@@ -64,6 +71,12 @@ Slice::SignalHandler::~SignalHandler()
}
void
+Slice::SignalHandler::setCallback(SignalHandlerCallback callback)
+{
+ _callback = callback;
+}
+
+void
Slice::SignalHandler::addFile(const string& file)
{
_fileList.push_back(file);
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 91473852683..c8f759b8170 100755
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -22,6 +22,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)
{
@@ -50,6 +63,9 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte
_stream(stream),
_ice(ice)
{
+ _gen = this;
+ SignalHandler::setCallback(closeCallback);
+
for(vector<string>::iterator p = _includePaths.begin(); p != _includePaths.end(); ++p)
{
if(p->length() && (*p)[p->length() - 1] != '/')
@@ -163,6 +179,8 @@ Slice::Gen::~Gen()
implH << "\n\n#endif\n";
implC << '\n';
}
+
+ SignalHandler::setCallback(0);
}
bool
@@ -381,6 +399,15 @@ Slice::Gen::generate(const UnitPtr& p)
}
void
+Slice::Gen::closeOutput()
+{
+ H.close();
+ C.close();
+ implH.close();
+ implC.close();
+}
+
+void
Slice::Gen::writeExtraHeaders(IceUtilInternal::Output& out)
{
for(vector<string>::const_iterator i = _extraHeaders.begin(); i != _extraHeaders.end(); ++i)
diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h
index 8e0b397c6de..670ae9740d9 100644
--- a/cpp/src/slice2cpp/Gen.h
+++ b/cpp/src/slice2cpp/Gen.h
@@ -38,6 +38,7 @@ public:
bool operator!() const; // Returns true if there was a constructor error
void generate(const UnitPtr&);
+ void closeOutput();
static bool setUseWstring(ContainedPtr, std::list<bool>&, bool);
static bool resetUseWstring(std::list<bool>&);
diff --git a/cpp/src/slice2cppe/Gen.cpp b/cpp/src/slice2cppe/Gen.cpp
index 89fcbd1e155..775b66ef99c 100644
--- a/cpp/src/slice2cppe/Gen.cpp
+++ b/cpp/src/slice2cppe/Gen.cpp
@@ -21,6 +21,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 void
getIds(const ClassDefPtr& p, StringList& ids)
{
@@ -69,6 +82,9 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte
_impl(imp),
_ice(ice)
{
+ _gen = this;
+ SignalHandler::setCallback(closeCallback);
+
Slice::featureProfile = Slice::IceE;
for(vector<string>::iterator p = _includePaths.begin(); p != _includePaths.end(); ++p)
@@ -184,6 +200,8 @@ Slice::Gen::~Gen()
implH << "\n\n#endif\n";
implC << '\n';
}
+
+ SignalHandler::setCallback(0);
}
bool
@@ -343,6 +361,15 @@ Slice::Gen::generate(const UnitPtr& p)
}
void
+Slice::Gen::closeOutput()
+{
+ H.close();
+ C.close();
+ implH.close();
+ implC.close();
+}
+
+void
Slice::Gen::writeExtraHeaders(Output& out)
{
for(vector<string>::const_iterator i = _extraHeaders.begin(); i != _extraHeaders.end(); ++i)
diff --git a/cpp/src/slice2cppe/Gen.h b/cpp/src/slice2cppe/Gen.h
index cc317addb06..0552080e140 100644
--- a/cpp/src/slice2cppe/Gen.h
+++ b/cpp/src/slice2cppe/Gen.h
@@ -42,6 +42,7 @@ public:
bool operator!() const; // Returns true if there was a constructor error
void generate(const UnitPtr&);
+ void closeOutput();
static bool setUseWstring(ContainedPtr, std::list<bool>&, bool);
static bool resetUseWstring(std::list<bool>&);
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp
index a68b54f7da5..9c7dffbc7e6 100755
--- 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::setCallback(closeCallback);
+
string fileBase = base;
string::size_type pos = base.find_last_of("/\\");
if(pos != string::npos)
@@ -1130,6 +1146,8 @@ Slice::Gen::~Gen()
{
_impl << '\n';
}
+
+ SignalHandler::setCallback(0);
}
bool
@@ -1240,6 +1258,13 @@ Slice::Gen::generateChecksums(const UnitPtr& u)
}
void
+Slice::Gen::closeOutput()
+{
+ _out.close();
+ _impl.close();
+}
+
+void
Slice::Gen::printHeader()
{
static const char* header =
diff --git a/cpp/src/slice2cs/Gen.h b/cpp/src/slice2cs/Gen.h
index 97dfe52b065..bd62d0ad705 100644
--- a/cpp/src/slice2cs/Gen.h
+++ b/cpp/src/slice2cs/Gen.h
@@ -62,6 +62,7 @@ public:
void generateImpl(const UnitPtr&);
void generateImplTie(const UnitPtr&);
void generateChecksums(const UnitPtr&);
+ void closeOutput();
private:
diff --git a/cpp/src/slice2docbook/Gen.cpp b/cpp/src/slice2docbook/Gen.cpp
index 926c4f4e434..3f634dbef1f 100644
--- a/cpp/src/slice2docbook/Gen.cpp
+++ b/cpp/src/slice2docbook/Gen.cpp
@@ -9,6 +9,7 @@
#include <IceUtil/DisableWarnings.h>
#include <IceUtil/Functional.h>
+#include <Slice/SignalHandler.h>
#include <Gen.h>
#ifdef __BCPLUSPLUS__
@@ -20,12 +21,28 @@ 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();
+ }
+}
+
Slice::Gen::Gen(const string& name, const string& file, bool standAlone, bool chapter,
bool noIndex, bool sortFields) :
_standAlone(standAlone),
_noIndex(noIndex),
_sortFields(sortFields)
{
+ _gen = this;
+ SignalHandler::setCallback(closeCallback);
+
if(chapter)
{
_chapter = "chapter";
@@ -45,6 +62,7 @@ Slice::Gen::Gen(const string& name, const string& file, bool standAlone, bool ch
Slice::Gen::~Gen()
{
+ SignalHandler::setCallback(0);
}
bool
@@ -67,6 +85,12 @@ Slice::Gen::generate(const UnitPtr& p)
p->visit(this, false);
}
+void
+Slice::Gen::closeOutput()
+{
+ O.close();
+}
+
bool
Slice::Gen::visitUnitStart(const UnitPtr& p)
{
diff --git a/cpp/src/slice2docbook/Gen.h b/cpp/src/slice2docbook/Gen.h
index 969d98e450c..9b20ee187ac 100644
--- a/cpp/src/slice2docbook/Gen.h
+++ b/cpp/src/slice2docbook/Gen.h
@@ -27,6 +27,7 @@ public:
bool operator!() const; // Returns true if there was a constructor error
void generate(const UnitPtr&);
+ void closeOutput();
virtual bool visitUnitStart(const UnitPtr&);
virtual void visitUnitEnd(const UnitPtr&);
diff --git a/cpp/src/slice2freeze/Main.cpp b/cpp/src/slice2freeze/Main.cpp
index 0790f7ff60e..8a149b57f5d 100644
--- a/cpp/src/slice2freeze/Main.cpp
+++ b/cpp/src/slice2freeze/Main.cpp
@@ -19,6 +19,18 @@ using namespace IceUtil;
using namespace IceUtilInternal;
using namespace Slice;
+static IceUtilInternal::Output _H;
+static IceUtilInternal::Output _C;
+
+//
+// Callback for Crtl-C signal handling
+//
+static void closeCallback()
+{
+ _H.close();
+ _C.close();
+}
+
static string ICE_ENCODING_COMPARE = "Freeze::IceEncodingCompare";
struct DictIndex
@@ -1732,9 +1744,6 @@ main(int argc, char* argv[])
if(status == EXIT_SUCCESS && !preprocess)
{
- SignalHandler::addFile(fileH);
- SignalHandler::addFile(fileC);
-
u->mergeModules();
u->sort();
@@ -1748,27 +1757,30 @@ main(int argc, char* argv[])
}
}
- Output H;
- H.open(fileH.c_str());
- if(!H)
+ SignalHandler::addFile(fileH);
+ SignalHandler::addFile(fileC);
+
+ SignalHandler::setCallback(closeCallback);
+
+ _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 C;
- C.open(fileC.c_str());
- if(!C)
+ _C.open(fileC.c_str());
+ if(!_C)
{
cerr << argv[0] << ": can't open `" << fileC << "' for writing: " << strerror(errno) << endl;
u->destroy();
return EXIT_FAILURE;
}
- printHeader(C);
- printFreezeTypes(C, dicts, indices);
+ printHeader(_C);
+ printFreezeTypes(_C, dicts, indices);
for(vector<string>::const_iterator i = extraHeaders.begin(); i != extraHeaders.end(); ++i)
{
@@ -1782,57 +1794,57 @@ main(int argc, char* argv[])
}
if(!guard.empty())
{
- C << "\n#ifndef " << guard;
- C << "\n#define " << guard;
+ _C << "\n#ifndef " << guard;
+ _C << "\n#define " << guard;
}
- C << "\n#include <";
+ _C << "\n#include <";
if(!include.empty())
{
- C << include << '/';
+ _C << include << '/';
}
- C << hdr << '>';
+ _C << hdr << '>';
if(!guard.empty())
{
- C << "\n#endif";
+ _C << "\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 + ">";
}
}
- C << "\n#include <Ice/BasicStream.h>";
- C << "\n#include <";
+ _C << "\n#include <Ice/BasicStream.h>";
+ _C << "\n#include <";
if(include.size())
{
- C << include << '/';
+ _C << include << '/';
}
- C << includeH << '>';
+ _C << includeH << '>';
- printVersionCheck(H);
- printVersionCheck(C);
+ printVersionCheck(_H);
+ printVersionCheck(_C);
- printDllExportStuff(H, dllExport);
+ printDllExportStuff(_H, dllExport);
if(dllExport.size())
{
dllExport += " ";
@@ -1843,7 +1855,7 @@ main(int argc, char* argv[])
{
try
{
- if(!writeDict(argv[0], u, *p, H, C, dllExport))
+ if(!writeDict(argv[0], u, *p, _H, _C, dllExport))
{
u->destroy();
return EXIT_FAILURE;
@@ -1862,7 +1874,7 @@ main(int argc, char* argv[])
{
try
{
- if(!writeIndex(argv[0], u, *q, H, C, dllExport))
+ if(!writeIndex(argv[0], u, *q, _H, _C, dllExport))
{
u->destroy();
return EXIT_FAILURE;
@@ -1878,8 +1890,8 @@ main(int argc, char* argv[])
}
- H << "\n\n#endif\n";
- C << '\n';
+ _H << "\n\n#endif\n";
+ _C << '\n';
}
diff --git a/cpp/src/slice2html/Gen.cpp b/cpp/src/slice2html/Gen.cpp
index e477449255d..c3c51ae2868 100644
--- a/cpp/src/slice2html/Gen.cpp
+++ b/cpp/src/slice2html/Gen.cpp
@@ -30,15 +30,30 @@ 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
{
void
-generate(const UnitPtr& unit, const string& dir,
- const string& header, const string& footer,
- const string& indexHeader, const string& indexFooter,
- const string& imageDir, const string& logoURL, const string& searchAction, unsigned indexCount, unsigned warnSummary)
+generate(const UnitPtr& unit, const string& dir, const string& header, const string& footer,
+ const string& indexHeader, const string& indexFooter, const string& imageDir, const string& logoURL,
+ const string& searchAction, unsigned indexCount, unsigned warnSummary)
{
+ SignalHandler::setCallback(closeCallback);
+
unit->mergeModules();
//
@@ -197,10 +212,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;
}
//
@@ -1203,6 +1220,12 @@ Slice::GeneratorBase::openStream(const string& path)
}
}
+void
+Slice::GeneratorBase::closeStream()
+{
+ _out.close();
+}
+
string
Slice::GeneratorBase::containedToId(const ContainedPtr& contained, bool asTarget)
{
diff --git a/cpp/src/slice2html/Gen.h b/cpp/src/slice2html/Gen.h
index 665f08a08f5..fcdbc63bba4 100644
--- a/cpp/src/slice2html/Gen.h
+++ b/cpp/src/slice2html/Gen.h
@@ -36,6 +36,8 @@ public:
static void warnSummary(int);
static void setSymbols(const ContainedList&);
+ void closeStream();
+
protected:
GeneratorBase(::IceUtilInternal::XMLOutput&, const Files&);
diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp
index 521786ac6ce..c0d7dd61be3 100644
--- a/cpp/src/slice2py/Main.cpp
+++ b/cpp/src/slice2py/Main.cpp
@@ -33,6 +33,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
@@ -538,22 +548,26 @@ main(int argc, char* argv[])
}
SignalHandler::addFile(file);
- IceUtilInternal::Output out;
- out.open(file.c_str());
- if(!out)
+ SignalHandler::setCallback(closeCallback);
+
+ _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();
+ SignalHandler::setCallback(0);
//
// Create or update the Python package hierarchy.
diff --git a/cpp/src/slice2rb/Main.cpp b/cpp/src/slice2rb/Main.cpp
index 8250a4a49ca..1bf68718f58 100644
--- a/cpp/src/slice2rb/Main.cpp
+++ b/cpp/src/slice2rb/Main.cpp
@@ -30,6 +30,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)
{
@@ -194,23 +204,26 @@ main(int argc, char* argv[])
}
SignalHandler::addFile(file);
- IceUtilInternal::Output out;
- out.open(file.c_str());
- if(!out)
+ SignalHandler::setCallback(closeCallback);
+
+ _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();
+ SignalHandler::setCallback(0);
}
u->destroy();
diff --git a/cpp/src/slice2sl/Gen.cpp b/cpp/src/slice2sl/Gen.cpp
index 604c6e0e5d3..63f13486e9b 100755
--- a/cpp/src/slice2sl/Gen.cpp
+++ b/cpp/src/slice2sl/Gen.cpp
@@ -38,6 +38,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)
{
@@ -488,6 +501,9 @@ Slice::CsVisitor::emitAttributes(const ContainedPtr& p)
Slice::Gen::Gen(const string& name, const string& base, const vector<string>& includePaths, const string& dir) :
_includePaths(includePaths)
{
+ _gen = this;
+ SignalHandler::setCallback(closeCallback);
+
string fileBase = base;
string::size_type pos = base.find_last_of("/\\");
if(pos != string::npos)
@@ -529,6 +545,8 @@ Slice::Gen::~Gen()
{
_impl << '\n';
}
+
+ SignalHandler::setCallback(0);
}
bool
@@ -566,6 +584,13 @@ Slice::Gen::generate(const UnitPtr& p)
}
void
+Slice::Gen::closeOutput()
+{
+ _out.close();
+ _impl.close();
+}
+
+void
Slice::Gen::printHeader()
{
static const char* header =
diff --git a/cpp/src/slice2sl/Gen.h b/cpp/src/slice2sl/Gen.h
index 45d4bd90562..b0b85d77f63 100644
--- a/cpp/src/slice2sl/Gen.h
+++ b/cpp/src/slice2sl/Gen.h
@@ -55,6 +55,7 @@ public:
void generateTie(const UnitPtr&);
void generateImpl(const UnitPtr&);
void generateImplTie(const UnitPtr&);
+ void closeOutput();
private: