summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2012-10-19 14:08:05 +0200
committerBenoit Foucher <benoit@zeroc.com>2012-10-19 14:08:05 +0200
commitd1003f44c83af7ff21e99410481d2b88ef1bfd28 (patch)
tree8ad00beabac66dc9c001d63b89ebabcf2c88252e /cpp/src
parentFixed ICE-4733 - connection failure throws SocketException (diff)
downloadice-d1003f44c83af7ff21e99410481d2b88ef1bfd28.tar.bz2
ice-d1003f44c83af7ff21e99410481d2b88ef1bfd28.tar.xz
ice-d1003f44c83af7ff21e99410481d2b88ef1bfd28.zip
Fixed ICE-3416, cleaned up generated code for user exceptions
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/FactoryTable.cpp50
-rw-r--r--cpp/src/slice2cpp/Gen.cpp136
2 files changed, 51 insertions, 135 deletions
diff --git a/cpp/src/Ice/FactoryTable.cpp b/cpp/src/Ice/FactoryTable.cpp
index a102c4ca1e8..9bfbd6ec127 100644
--- a/cpp/src/Ice/FactoryTable.cpp
+++ b/cpp/src/Ice/FactoryTable.cpp
@@ -10,10 +10,6 @@
#include <Ice/FactoryTable.h>
#include <Ice/UserExceptionFactory.h>
-#ifdef __APPLE__
-# include <dlfcn.h>
-#endif
-
//
// Add a factory to the exception factory table.
// If the factory is present already, increment its reference count.
@@ -22,6 +18,7 @@ void
IceInternal::FactoryTable::addExceptionFactory(const std::string& t, const IceInternal::UserExceptionFactoryPtr& f)
{
IceUtil::Mutex::Lock lock(_m);
+ assert(f);
EFTable::iterator i = _eft.find(t);
if(i == _eft.end())
{
@@ -41,28 +38,6 @@ IceInternal::FactoryTable::getExceptionFactory(const std::string& t) const
{
IceUtil::Mutex::Lock lock(_m);
EFTable::const_iterator i = _eft.find(t);
-#ifdef __APPLE__
- if(i == _eft.end())
- {
- lock.release();
-
- //
- // Try to find the symbol, if found this should trigger the
- // object static constructors to be called.
- //
- std::string symbol = "__F";
- for(std::string::const_iterator p = t.begin(); p != t.end(); ++p)
- {
- symbol += ((*p) == ':') ? '_' : *p;
- }
- symbol += "__initializer";
- dlsym(RTLD_DEFAULT, symbol.c_str());
-
- lock.acquire();
-
- i = _eft.find(t);
- }
-#endif
return i != _eft.end() ? i->second.first : IceInternal::UserExceptionFactoryPtr();
}
@@ -93,6 +68,7 @@ void
IceInternal::FactoryTable::addObjectFactory(const std::string& t, const Ice::ObjectFactoryPtr& f)
{
IceUtil::Mutex::Lock lock(_m);
+ assert(f);
OFTable::iterator i = _oft.find(t);
if(i == _oft.end())
{
@@ -112,28 +88,6 @@ IceInternal::FactoryTable::getObjectFactory(const std::string& t) const
{
IceUtil::Mutex::Lock lock(_m);
OFTable::const_iterator i = _oft.find(t);
-#ifdef __APPLE__
- if(i == _oft.end())
- {
- lock.release();
-
- //
- // Try to find the symbol, if found this should trigger the
- // object static constructors to be called.
- //
- std::string symbol = "__F";
- for(std::string::const_iterator p = t.begin(); p != t.end(); ++p)
- {
- symbol += ((*p) == ':') ? '_' : *p;
- }
- symbol += "__initializer";
- dlsym(RTLD_DEFAULT, symbol.c_str());
-
- lock.acquire();
-
- i = _oft.find(t);
- }
-#endif
return i != _oft.end() ? i->second.first : Ice::ObjectFactoryPtr();
}
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 7723b686ced..80f6b7deab1 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -733,6 +733,43 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
H << nl << "virtual ~" << name << "() throw();";
H << sp;
+ C << sp << nl << "namespace";
+ C << nl << "{";
+ string flatName = p->flattenedScope() + p->name() + "_name";
+ C << sp << nl << "const char* " << flatName << " = \"" << p->scoped().substr(2) << "\";";
+ if(!p->isLocal())
+ {
+ string factoryName = "__F" + p->flattenedScope() + p->name();
+
+ C << sp << nl << "struct " << factoryName << " : public ::IceInternal::UserExceptionFactory";
+ C << sb;
+ C << sp << nl << "virtual void";
+ C << nl << "createAndThrow(const ::std::string&)";
+ C << sb;
+ C << nl << "throw " << scoped << "();";
+ C << eb;
+ C << eb << ';';
+
+ C << sp << nl << "class " << factoryName << "__Init";
+ C << sb;
+ C.dec();
+ C << nl << "public:";
+ C.inc();
+ C << sp << nl << factoryName << "__Init()";
+ C << sb;
+ C << nl << "::IceInternal::factoryTable->addExceptionFactory(\"" << p->scoped() << "\", new "
+ << factoryName << ");";
+ C << eb;
+ C << sp << nl << "~" << factoryName << "__Init()";
+ C << sb;
+ C << nl << "::IceInternal::factoryTable->removeExceptionFactory(\"" << p->scoped() << "\");";
+ C << eb;
+ C << eb << ';';
+
+ C << sp << nl << "const " << factoryName << "__Init "<< factoryName << "__i;";
+ }
+ C << sp << nl << "}";
+
if(p->isLocal())
{
C << sp << nl << scoped.substr(2) << "::" << name << spar << "const char* __file" << "int __line" << epar
@@ -817,13 +854,6 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
C << eb;
H << nl << "virtual ::std::string ice_name() const;";
-
- string flatName = p->flattenedScope() + p->name() + "_name";
-
- C << sp << nl << "namespace";
- C << nl << "{";
- C << sp << nl << "const char* " << flatName << " = \"" << p->scoped().substr(2) << "\";";
- C << sp << nl << "}";
C << sp << nl << "::std::string" << nl << scoped.substr(2) << "::ice_name() const";
C << sb;
C << nl << "return " << flatName << ';';
@@ -847,10 +877,6 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
C << nl << "throw *this;";
C << eb;
- if(!p->isLocal())
- {
- H << sp << nl << "static const ::IceInternal::UserExceptionFactoryPtr& ice_factory();";
- }
if(!dataMembers.empty())
{
H << sp;
@@ -998,60 +1024,6 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
}
C << eb;
}
-
-
- factoryName = "__F" + p->flattenedScope() + p->name();
-
- C << sp << nl << "struct " << factoryName << " : public ::IceInternal::UserExceptionFactory";
- C << sb;
- C << sp << nl << "virtual void";
- C << nl << "createAndThrow(const ::std::string&)";
- C << sb;
- C << nl << "throw " << scoped << "();";
- C << eb;
- C << eb << ';';
-
- C << sp << nl << "namespace";
- C << nl << "{";
- C << sp << nl << "const ::IceInternal::UserExceptionFactoryPtr " << factoryName
- << "__Ptr = new " << factoryName << ';';
- C << sp << nl << "}";
-
- C << sp << nl << "const ::IceInternal::UserExceptionFactoryPtr&";
- C << nl << scoped.substr(2) << "::ice_factory()";
- C << sb;
- C << nl << "return " << factoryName << "__Ptr;";
- C << eb;
-
- C << sp << nl << "class " << factoryName << "__Init";
- C << sb;
- C.dec();
- C << nl << "public:";
- C.inc();
- C << sp << nl << factoryName << "__Init()";
- C << sb;
- C << nl << "::IceInternal::factoryTable->addExceptionFactory(\"" << p->scoped() << "\", " << scoped
- << "::ice_factory());";
- C << eb;
- C << sp << nl << "~" << factoryName << "__Init()";
- C << sb;
- C << nl << "::IceInternal::factoryTable->removeExceptionFactory(\"" << p->scoped() << "\");";
- C << eb;
- C << eb << ';';
- C << sp << nl << "namespace";
- C << nl << "{";
- C << sp << nl << "const " << factoryName << "__Init "<< factoryName << "__i;";
- C << sp << nl << "}";
- C << sp << nl << "#ifdef __APPLE__";
-
- string initfuncname = "__F" + p->flattenedScope() + p->name() + "__initializer";
- C << nl << "extern \"C\" {";
- C.inc();
- C << nl << "void " << initfuncname << "();";
- C << nl << "void " << initfuncname << "() {}";
- C.dec();
- C << nl << "}";
- C << nl << "#endif";
}
H << eb << ';';
@@ -3923,6 +3895,9 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
if(!p->isAbstract())
{
+ C << sp << nl << "namespace";
+ C << nl << "{";
+
string factoryName = "__F" + p->flattenedScope() + p->name();
C << sp;
C << nl << "class " << factoryName << " : public ::Ice::ObjectFactory";
@@ -3941,15 +3916,7 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
C << eb << ';';
string flatName = factoryName + "_Ptr";
- C << sp << nl << "namespace";
- C << nl << "{";
C << nl << "const ::Ice::ObjectFactoryPtr " << flatName << " = new " << factoryName << ';';
- C << sp << nl << "}";
-
- C << sp << nl << "const ::Ice::ObjectFactoryPtr&" << nl << scoped.substr(2) << "::ice_factory()";
- C << sb;
- C << nl << "return " << flatName << ';';
- C << eb;
C << sp;
C << nl << "class " << factoryName << "__Init";
@@ -3960,7 +3927,7 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
C << sp << nl << factoryName << "__Init()";
C << sb;
C << nl << "::IceInternal::factoryTable->addObjectFactory(" << scoped << "::ice_staticId(), "
- << scoped << "::ice_factory());";
+ << flatName << ");";
C << eb;
C << sp << nl << "~" << factoryName << "__Init()";
C << sb;
@@ -3968,19 +3935,14 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
C << eb;
C << eb << ';';
- C << sp << nl << "namespace";
- C << nl << "{";
- C << nl << "const " << factoryName << "__Init " << factoryName << "__i;";
+ C << sp << nl << "const " << factoryName << "__Init " << factoryName << "__i;";
+
C << sp << nl << "}";
- C << sp << nl << "#ifdef __APPLE__";
- string initfuncname = "__F" + p->flattenedScope() + p->name() + "__initializer";
- C << nl << "extern \"C\" {";
- C.inc();
- C << nl << "void " << initfuncname << "();";
- C << nl << "void " << initfuncname << "() {}";
- C.dec();
- C << nl << "}";
- C << nl << "#endif";
+
+ C << sp << nl << "const ::Ice::ObjectFactoryPtr&" << nl << scoped.substr(2) << "::ice_factory()";
+ C << sb;
+ C << nl << "return " << flatName << ';';
+ C << eb;
}
}
@@ -6105,7 +6067,7 @@ Slice::Gen::StreamVisitor::visitStructStart(const StructPtr& p)
C << nl << "#ifdef ICE_HAS_DECLSPEC_IMPORT_EXPORT";
C << nl << "template struct " << _dllExport << "StreamWriter< " << fullStructName << ", ::IceInternal::BasicStream>;";
C << nl << "template struct " << _dllExport << "StreamReader< " << fullStructName << ", ::IceInternal::BasicStream>;";
- C << nl << "#endif" << nl;
+ C << nl << "#endif";
}
}
return false;