summaryrefslogtreecommitdiff
path: root/cpp/src/slice2py
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/slice2py')
-rw-r--r--cpp/src/slice2py/.depend2
-rw-r--r--cpp/src/slice2py/Main.cpp245
-rw-r--r--cpp/src/slice2py/Makefile2
-rw-r--r--cpp/src/slice2py/Makefile.mak2
-rw-r--r--cpp/src/slice2py/Slice2Py.rc10
5 files changed, 137 insertions, 124 deletions
diff --git a/cpp/src/slice2py/.depend b/cpp/src/slice2py/.depend
index 613cd9bedeb..11436074b75 100644
--- a/cpp/src/slice2py/.depend
+++ b/cpp/src/slice2py/.depend
@@ -1 +1 @@
-Main$(OBJEXT): Main.cpp $(includedir)/IceUtil/DisableWarnings.h $(includedir)/IceUtil/IceUtil.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/AbstractMutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/Cache.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/CountDownLatch.h $(includedir)/IceUtil/Cond.h $(includedir)/IceUtil/CtrlCHandler.h $(includedir)/IceUtil/Functional.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/RWRecMutex.h $(includedir)/IceUtil/Thread.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/RecMutex.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/UUID.h $(includedir)/IceUtil/Unicode.h $(includedir)/IceUtil/Options.h $(includedir)/IceUtil/StringUtil.h $(includedir)/Slice/Preprocessor.h $(includedir)/Slice/PythonUtil.h $(includedir)/Slice/Parser.h $(includedir)/IceUtil/OutputUtil.h $(includedir)/Slice/SignalHandler.h
+Main$(OBJEXT): Main.cpp $(includedir)/IceUtil/DisableWarnings.h $(includedir)/IceUtil/IceUtil.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/AbstractMutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/Cache.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/CountDownLatch.h $(includedir)/IceUtil/Cond.h $(includedir)/IceUtil/CtrlCHandler.h $(includedir)/IceUtil/Functional.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/RWRecMutex.h $(includedir)/IceUtil/Thread.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/RecMutex.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/UUID.h $(includedir)/IceUtil/Unicode.h $(includedir)/IceUtil/Options.h $(includedir)/IceUtil/StringUtil.h $(includedir)/Slice/Preprocessor.h $(includedir)/Slice/PythonUtil.h $(includedir)/Slice/Parser.h $(includedir)/IceUtil/OutputUtil.h
diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp
index 226ebea9c86..7343ea9f812 100644
--- a/cpp/src/slice2py/Main.cpp
+++ b/cpp/src/slice2py/Main.cpp
@@ -1,6 +1,6 @@
// **********************************************************************
//
-// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
@@ -11,9 +11,11 @@
#include <IceUtil/IceUtil.h>
#include <IceUtil/Options.h>
#include <IceUtil/StringUtil.h>
+#include <IceUtil/CtrlCHandler.h>
+#include <IceUtil/StaticMutex.h>
#include <Slice/Preprocessor.h>
+#include <Slice/FileTracker.h>
#include <Slice/PythonUtil.h>
-#include <Slice/SignalHandler.h>
#include <cstring>
#include <fstream>
@@ -33,14 +35,15 @@ using namespace std;
using namespace Slice;
using namespace Slice::Python;
-//
-// Callback for Crtl-C signal handling
-//
-static IceUtilInternal::Output _out;
+static IceUtil::StaticMutex _mutex = ICE_STATIC_MUTEX_INITIALIZER;
+static bool _interrupted = false;
-static void closeCallback()
+void
+interruptedCallback(int signal)
{
- _out.close();
+ IceUtil::StaticMutex::Lock lock(_mutex);
+
+ _interrupted = true;
}
//
@@ -70,7 +73,7 @@ class PackageVisitor : public ParserVisitor
{
public:
- PackageVisitor(const string&, const string&, const string&);
+ PackageVisitor(const string&, const string&);
virtual bool visitModuleStart(const ModulePtr&);
virtual void visitModuleEnd(const ModulePtr&);
@@ -82,15 +85,14 @@ private:
static const char* _moduleTag;
static const char* _submoduleTag;
- bool createDirectory(const string&);
+ void createDirectory(const string&);
- bool addModule(const string&, const string&);
- bool addSubmodule(const string&, const string&);
+ void addModule(const string&, const string&);
+ void addSubmodule(const string&, const string&);
- bool readInit(const string&, StringList&, StringList&);
- bool writeInit(const string&, const StringList&, const StringList&);
+ void readInit(const string&, StringList&, StringList&);
+ void writeInit(const string&, const StringList&, const StringList&);
- string _name;
string _module;
StringList _pathStack;
};
@@ -98,8 +100,8 @@ private:
const char* PackageVisitor::_moduleTag = "# Modules:";
const char* PackageVisitor::_submoduleTag = "# Submodules:";
-PackageVisitor::PackageVisitor(const string& name, const string& module, const string& dir) :
- _name(name), _module(module)
+PackageVisitor::PackageVisitor(const string& module, const string& dir) :
+ _module(module)
{
if(dir.empty())
{
@@ -136,27 +138,18 @@ PackageVisitor::visitModuleStart(const ModulePtr& p)
}
for(vector<string>::iterator q = v.begin(); q != v.end(); ++q)
{
- if(q != v.begin() && !addSubmodule(path, fixIdent(*q)))
+ if(q != v.begin())
{
- return false;
+ addSubmodule(path, fixIdent(*q));
}
path += "/" + *q;
- if(!createDirectory(path))
- {
- return false;
- }
+ createDirectory(path);
- if(!addModule(path, _module))
- {
- return false;
- }
+ addModule(path, _module);
}
- if(!addSubmodule(path, name))
- {
- return false;
- }
+ addSubmodule(path, name);
}
path += "/" + name;
@@ -169,26 +162,20 @@ PackageVisitor::visitModuleStart(const ModulePtr& p)
string parentPath = _pathStack.front();
_pathStack.push_front(path);
- if(!createDirectory(path))
- {
- return false;
- }
+ createDirectory(path);
//
// If necessary, add this module to the set of imported modules in __init__.py.
//
- if(!addModule(path, _module))
- {
- return false;
- }
+ addModule(path, _module);
//
// If this is a submodule, then modify the parent's __init__.py to import us.
//
ModulePtr mod = ModulePtr::dynamicCast(p->container());
- if(mod && !addSubmodule(parentPath, name))
+ if(mod)
{
- return false;
+ addSubmodule(parentPath, name);
}
return true;
@@ -201,75 +188,72 @@ PackageVisitor::visitModuleEnd(const ModulePtr& p)
_pathStack.pop_front();
}
-bool
+void
PackageVisitor::createDirectory(const string& dir)
{
struct stat st;
int result;
result = stat(dir.c_str(), &st);
- if(result != 0)
+ if(result == 0)
{
+ if(!(st.st_mode & S_IFDIR))
+ {
+ ostringstream os;
+ os << "failed to create package directory `" << dir
+ << "': file already exists and is not a directory";
+ throw FileException(__FILE__, __LINE__, os.str());
+ }
+ return;
+ }
#ifdef _WIN32
- result = _mkdir(dir.c_str());
+ result = _mkdir(dir.c_str());
#else
- result = mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
+ result = mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
#endif
- if(result != 0)
- {
- cerr << _name << ": unable to create `" << dir << "': " << strerror(errno) << endl;
- return false;
- }
+ if(result != 0)
+ {
+ ostringstream os;
+ os << "cannot create directory `" << dir << "': " << strerror(errno);
+ throw FileException(__FILE__, __LINE__, os.str());
}
- return true;
+ FileTracker::instance()->addDirectory(dir);
}
-bool
+void
PackageVisitor::addModule(const string& dir, const string& name)
{
//
// Add a module to the set of imported modules in __init__.py.
//
StringList modules, submodules;
- if(readInit(dir, modules, submodules))
+ readInit(dir, modules, submodules);
+ StringList::iterator p = find(modules.begin(), modules.end(), name);
+ if(p == modules.end())
{
- StringList::iterator p = find(modules.begin(), modules.end(), name);
- if(p == modules.end())
- {
- modules.push_back(name);
- return writeInit(dir, modules, submodules);
- }
-
- return true;
+ modules.push_back(name);
+ writeInit(dir, modules, submodules);
}
-
- return false;
}
-bool
+void
PackageVisitor::addSubmodule(const string& dir, const string& name)
{
//
// Add a submodule to the set of imported modules in __init__.py.
//
StringList modules, submodules;
- if(readInit(dir, modules, submodules))
+ readInit(dir, modules, submodules);
+ StringList::iterator p = find(submodules.begin(), submodules.end(), name);
+ if(p == submodules.end())
{
- StringList::iterator p = find(submodules.begin(), submodules.end(), name);
- if(p == submodules.end())
- {
- submodules.push_back(name);
- return writeInit(dir, modules, submodules);
- }
-
- return true;
+ submodules.push_back(name);
+ writeInit(dir, modules, submodules);
}
-
- return false;
}
-bool
+void
PackageVisitor::readInit(const string& dir, StringList& modules, StringList& submodules)
{
string initPath = dir + "/__init__.py";
@@ -280,8 +264,9 @@ PackageVisitor::readInit(const string& dir, StringList& modules, StringList& sub
ifstream in(initPath.c_str());
if(!in)
{
- cerr << _name << ": unable to open `" << initPath << "': " << strerror(errno) << endl;
- return false;
+ ostringstream os;
+ os << "cannot open file `" << initPath << "': " << strerror(errno);
+ throw FileException(__FILE__, __LINE__, os.str());
}
ReadState state = PreModules;
@@ -314,8 +299,9 @@ PackageVisitor::readInit(const string& dir, StringList& modules, StringList& sub
if(s.size() < 8)
{
- cerr << _name << ": invalid line `" << s << "' in `" << initPath << "'" << endl;
- return false;
+ ostringstream os;
+ os << "invalid line `" << s << "' in `" << initPath << "'";
+ throw os.str();
}
string name = s.substr(7);
@@ -332,15 +318,14 @@ PackageVisitor::readInit(const string& dir, StringList& modules, StringList& sub
if(state != InSubmodules)
{
- cerr << _name << ": invalid format in `" << initPath << "'" << endl;
- return false;
+ ostringstream os;
+ os << "invalid format in `" << initPath << "'" << endl;
+ throw os.str();
}
}
-
- return true;
}
-bool
+void
PackageVisitor::writeInit(const string& dir, const StringList& modules, const StringList& submodules)
{
string initPath = dir + "/__init__.py";
@@ -348,8 +333,11 @@ PackageVisitor::writeInit(const string& dir, const StringList& modules, const St
ofstream os(initPath.c_str());
if(!os)
{
- return false;
+ ostringstream os;
+ os << "cannot open file `" << initPath << "': " << strerror(errno);
+ throw FileException(__FILE__, __LINE__, os.str());
}
+ FileTracker::instance()->addFile(initPath);
StringList::const_iterator p;
@@ -367,8 +355,6 @@ PackageVisitor::writeInit(const string& dir, const StringList& modules, const St
{
os << "import " << *p << endl;
}
-
- return true;
}
void
@@ -434,7 +420,7 @@ main(int argc, char* argv[])
if(opts.isSet("version"))
{
- cout << ICE_STRING_VERSION << endl;
+ cerr << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
}
@@ -485,10 +471,12 @@ main(int argc, char* argv[])
int status = EXIT_SUCCESS;
+ IceUtil::CtrlCHandler ctrlCHandler;
+ ctrlCHandler.setCallback(interruptedCallback);
+
+
for(i = args.begin(); i != args.end(); ++i)
{
- SignalHandler sigHandler;
-
Preprocessor icecpp(argv[0], *i, cppArgs);
FILE* cppHandle = icecpp.preprocess(false);
@@ -547,42 +535,67 @@ main(int argc, char* argv[])
{
file = output + '/' + file;
}
- SignalHandler::addFile(file);
-
- SignalHandler::setCallback(closeCallback);
- _out.open(file.c_str());
- if(!_out)
+ try
+ {
+ IceUtilInternal::Output out;
+ out.open(file.c_str());
+ if(!out)
+ {
+ ostringstream os;
+ os << "cannot open`" << file << "': " << strerror(errno);
+ throw FileException(__FILE__, __LINE__, os.str());
+ }
+ FileTracker::instance()->addFile(file);
+
+ printHeader(out);
+ out << "\n# Generated from file `" << base << ".ice'\n";
+
+ //
+ // Generate the Python mapping.
+ //
+ generate(u, all, checksum, includePaths, out);
+
+ out.close();
+
+ //
+ // Create or update the Python package hierarchy.
+ //
+ if(!noPackage)
+ {
+ PackageVisitor visitor(prefix + base + "_ice", output);
+ u->visit(&visitor, false);
+ }
+ }
+ catch(const Slice::FileException& ex)
{
- cerr << argv[0] << ": can't open `" << file << "' for writing" << endl;
+ // If a file could not be created, then cleanup any
+ // created files.
+ FileTracker::instance()->cleanup();
u->destroy();
+ cerr << argv[0] << ": " << ex.reason() << endl;
return EXIT_FAILURE;
}
-
- printHeader(_out);
- _out << "\n# Generated from file `" << base << ".ice'\n";
-
- //
- // Generate the Python mapping.
- //
- generate(u, all, checksum, includePaths, _out);
-
- _out.close();
- SignalHandler::setCallback(0);
-
- //
- // Create or update the Python package hierarchy.
- //
- if(!noPackage)
+ catch(const string& err)
{
- PackageVisitor visitor(argv[0], prefix + base + "_ice", output);
- u->visit(&visitor, false);
+ FileTracker::instance()->cleanup();
+ cerr << argv[0] << ": " << err << endl;
+ status = EXIT_FAILURE;
}
-
}
u->destroy();
}
+
+ {
+ IceUtil::StaticMutex::Lock lock(_mutex);
+
+ if(_interrupted)
+ {
+ FileTracker::instance()->cleanup();
+ return EXIT_FAILURE;
+ }
+ }
}
return status;
diff --git a/cpp/src/slice2py/Makefile b/cpp/src/slice2py/Makefile
index 5686d40cc77..05b3cec5dc5 100644
--- a/cpp/src/slice2py/Makefile
+++ b/cpp/src/slice2py/Makefile
@@ -1,6 +1,6 @@
# **********************************************************************
#
-# Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+# Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
diff --git a/cpp/src/slice2py/Makefile.mak b/cpp/src/slice2py/Makefile.mak
index b31812043df..96b024beb14 100644
--- a/cpp/src/slice2py/Makefile.mak
+++ b/cpp/src/slice2py/Makefile.mak
@@ -1,6 +1,6 @@
# **********************************************************************
#
-# Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+# Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
diff --git a/cpp/src/slice2py/Slice2Py.rc b/cpp/src/slice2py/Slice2Py.rc
index 7087b550a1e..31db7dfc054 100644
--- a/cpp/src/slice2py/Slice2Py.rc
+++ b/cpp/src/slice2py/Slice2Py.rc
@@ -1,8 +1,8 @@
#include "winver.h"
VS_VERSION_INFO VERSIONINFO
- FILEVERSION 3,3,0,0
- PRODUCTVERSION 3,3,0,0
+ FILEVERSION 3,3,1,0
+ PRODUCTVERSION 3,3,1,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
@@ -19,12 +19,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "ZeroC, Inc.\0"
VALUE "FileDescription", "Slice To Python Translator\0"
- VALUE "FileVersion", "3.3.0\0"
+ VALUE "FileVersion", "3.3.1\0"
VALUE "InternalName", "slice2py\0"
- VALUE "LegalCopyright", "Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.\0"
+ VALUE "LegalCopyright", "Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.\0"
VALUE "OriginalFilename", "slice2py.exe\0"
VALUE "ProductName", "Ice\0"
- VALUE "ProductVersion", "3.3.0\0"
+ VALUE "ProductVersion", "3.3.1\0"
END
END
BLOCK "VarFileInfo"