summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2008-11-18 13:39:14 -0330
committerDwayne Boone <dwayne@zeroc.com>2008-11-18 13:39:14 -0330
commitac8bf31698d259127646a4e114deca1e7d5e334c (patch)
treef694a8fc9e17bbb0044082510e5d0dd5622cbedc /cpp
parentRemoved debug statements (diff)
downloadice-ac8bf31698d259127646a4e114deca1e7d5e334c.tar.bz2
ice-ac8bf31698d259127646a4e114deca1e7d5e334c.tar.xz
ice-ac8bf31698d259127646a4e114deca1e7d5e334c.zip
Bug 3541 - Slice signal handling unsafe
Diffstat (limited to 'cpp')
-rw-r--r--cpp/include/Slice/SignalHandler.h4
-rw-r--r--cpp/src/Slice/JavaUtil.cpp18
-rw-r--r--cpp/src/Slice/Preprocessor.cpp19
-rw-r--r--cpp/src/Slice/SignalHandler.cpp14
-rw-r--r--cpp/src/slice2cpp/Gen.cpp18
-rw-r--r--cpp/src/slice2cs/Gen.cpp18
-rw-r--r--cpp/src/slice2docbook/Gen.cpp17
-rw-r--r--cpp/src/slice2freeze/Main.cpp78
-rw-r--r--cpp/src/slice2html/Gen.cpp18
-rw-r--r--cpp/src/slice2py/Main.cpp26
-rw-r--r--cpp/src/slice2rb/Main.cpp26
11 files changed, 50 insertions, 206 deletions
diff --git a/cpp/include/Slice/SignalHandler.h b/cpp/include/Slice/SignalHandler.h
index 318547cf5ae..4914de3092d 100644
--- a/cpp/include/Slice/SignalHandler.h
+++ b/cpp/include/Slice/SignalHandler.h
@@ -24,8 +24,6 @@
namespace Slice
{
-typedef void (*SignalHandlerCallback)();
-
class SLICE_API SignalHandler
{
public:
@@ -33,8 +31,6 @@ public:
SignalHandler();
~SignalHandler();
- static void setCallback(SignalHandlerCallback);
-
static void addFile(const std::string&);
};
diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp
index 3f35bf1af32..3179c3df7c5 100644
--- a/cpp/src/Slice/JavaUtil.cpp
+++ b/cpp/src/Slice/JavaUtil.cpp
@@ -27,20 +27,6 @@ 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()
{
}
@@ -174,7 +160,7 @@ Slice::JavaGenerator::JavaGenerator(const string& dir) :
_dir(dir),
_out(0)
{
- SignalHandler::setCallback(closeCallback);
+ //SignalHandler::setCallback(closeCallback);
}
Slice::JavaGenerator::JavaGenerator(const string& dir, Slice::FeatureProfile profile) :
@@ -198,7 +184,6 @@ Slice::JavaGenerator::open(const string& absolute)
if(out->openClass(absolute, _dir))
{
_out = out;
- _javaGen = this; // For Ctrl-C handling
}
else
{
@@ -215,7 +200,6 @@ 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 ac62657e59a..8c7f1983413 100644
--- a/cpp/src/Slice/Preprocessor.cpp
+++ b/cpp/src/Slice/Preprocessor.cpp
@@ -29,20 +29,6 @@ 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
@@ -65,8 +51,6 @@ Slice::Preprocessor::Preprocessor(const string& path, const string& fileName, co
_args(args),
_cppHandle(0)
{
- _preprocess = this;
- SignalHandler::setCallback(closeCallback);
}
Slice::Preprocessor::~Preprocessor()
@@ -453,9 +437,6 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin
bool
Slice::Preprocessor::close()
{
- _preprocess = 0;
- SignalHandler::setCallback(0);
-
if(_cppHandle != 0)
{
int status = fclose(_cppHandle);
diff --git a/cpp/src/Slice/SignalHandler.cpp b/cpp/src/Slice/SignalHandler.cpp
index b1fa6486f97..fa693d88db7 100644
--- a/cpp/src/Slice/SignalHandler.cpp
+++ b/cpp/src/Slice/SignalHandler.cpp
@@ -24,7 +24,6 @@ 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
@@ -33,15 +32,12 @@ 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());
}
+
+ exit(1);
}
@@ -70,12 +66,6 @@ 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 340c9924a26..4c0eb293823 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -23,19 +23,6 @@ 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)
{
@@ -64,9 +51,6 @@ 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)
{
*p = fullPath(*p);
@@ -177,8 +161,6 @@ Slice::Gen::~Gen()
implH << "\n\n#endif\n";
implC << '\n';
}
-
- SignalHandler::setCallback(0);
}
bool
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp
index 77736cad662..8cd18659005 100644
--- a/cpp/src/slice2cs/Gen.cpp
+++ b/cpp/src/slice2cs/Gen.cpp
@@ -39,19 +39,6 @@ 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)
{
@@ -1072,9 +1059,6 @@ 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)
@@ -1146,8 +1130,6 @@ Slice::Gen::~Gen()
{
_impl << '\n';
}
-
- SignalHandler::setCallback(0);
}
bool
diff --git a/cpp/src/slice2docbook/Gen.cpp b/cpp/src/slice2docbook/Gen.cpp
index 3521184c01c..d68304a8942 100644
--- a/cpp/src/slice2docbook/Gen.cpp
+++ b/cpp/src/slice2docbook/Gen.cpp
@@ -22,28 +22,12 @@ 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";
@@ -63,7 +47,6 @@ Slice::Gen::Gen(const string& name, const string& file, bool standAlone, bool ch
Slice::Gen::~Gen()
{
- SignalHandler::setCallback(0);
}
bool
diff --git a/cpp/src/slice2freeze/Main.cpp b/cpp/src/slice2freeze/Main.cpp
index d89b03670eb..2cf304eb7bc 100644
--- a/cpp/src/slice2freeze/Main.cpp
+++ b/cpp/src/slice2freeze/Main.cpp
@@ -22,18 +22,6 @@ 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
@@ -1854,27 +1842,27 @@ main(int argc, char* argv[])
SignalHandler::addFile(fileH);
SignalHandler::addFile(fileC);
- SignalHandler::setCallback(closeCallback);
-
- _H.open(fileH.c_str());
- if(!_H)
+ Output H;
+ 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);
- _CPP.open(fileC.c_str());
- if(!_CPP)
+ Output CPP;
+ 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)
{
@@ -1888,57 +1876,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 += " ";
@@ -1949,7 +1937,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;
@@ -1968,7 +1956,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;
@@ -1984,8 +1972,8 @@ main(int argc, char* argv[])
}
- _H << "\n\n#endif\n";
- _CPP << '\n';
+ H << "\n\n#endif\n";
+ CPP << '\n';
}
diff --git a/cpp/src/slice2html/Gen.cpp b/cpp/src/slice2html/Gen.cpp
index c2a6ff52bbe..91a114601de 100644
--- a/cpp/src/slice2html/Gen.cpp
+++ b/cpp/src/slice2html/Gen.cpp
@@ -30,20 +30,6 @@ 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
{
@@ -52,8 +38,6 @@ 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::setCallback(closeCallback);
-
unit->mergeModules();
//
@@ -212,12 +196,10 @@ 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;
}
//
diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp
index 226ebea9c86..7951141b1b3 100644
--- a/cpp/src/slice2py/Main.cpp
+++ b/cpp/src/slice2py/Main.cpp
@@ -34,16 +34,6 @@ 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
@@ -549,26 +539,24 @@ main(int argc, char* argv[])
}
SignalHandler::addFile(file);
- SignalHandler::setCallback(closeCallback);
-
- _out.open(file.c_str());
- if(!_out)
+ IceUtilInternal::Output out;
+ 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);
+ out.close();
//
// Create or update the Python package hierarchy.
diff --git a/cpp/src/slice2rb/Main.cpp b/cpp/src/slice2rb/Main.cpp
index da01726693a..2e91d3c1d8a 100644
--- a/cpp/src/slice2rb/Main.cpp
+++ b/cpp/src/slice2rb/Main.cpp
@@ -30,16 +30,6 @@ 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)
{
@@ -204,26 +194,24 @@ main(int argc, char* argv[])
}
SignalHandler::addFile(file);
- SignalHandler::setCallback(closeCallback);
-
- _out.open(file.c_str());
- if(!_out)
+ IceUtilInternal::Output out;
+ 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);
+ out.close();
}
u->destroy();