summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/slice2cpp/Gen.cpp26
-rw-r--r--cpp/src/slice2cpp/Gen.h2
-rw-r--r--cpp/src/slice2cppe/Gen.cpp13
-rw-r--r--cpp/src/slice2cppe/Gen.h1
4 files changed, 36 insertions, 6 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 1581902013b..c8546ca257c 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -340,7 +340,7 @@ Slice::Gen::generate(const UnitPtr& p)
}
Slice::Gen::TypesVisitor::TypesVisitor(Output& h, Output& c, const string& dllExport, bool stream) :
- H(h), C(c), _dllExport(dllExport), _stream(stream)
+ H(h), C(c), _dllExport(dllExport), _stream(stream), _doneStaticSymbol(false)
{
}
@@ -715,7 +715,16 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
if(!p->isLocal())
{
- H << sp << nl << "static " << name << " __" << p->name() << "_init;";
+ //
+ // We need an instance here to trigger initialization if the implementation is in a shared libarry.
+ // But we do this only once per source file, because a single instance is sufficient to initialize
+ // all of the globals in a shared library.
+ //
+ if(!_doneStaticSymbol)
+ {
+ _doneStaticSymbol = true;
+ H << sp << nl << "static " << name << " __" << p->name() << "_init;";
+ }
}
}
@@ -2191,7 +2200,7 @@ Slice::Gen::ObjectDeclVisitor::visitClassDecl(const ClassDeclPtr& p)
}
Slice::Gen::ObjectVisitor::ObjectVisitor(Output& h, Output& c, const string& dllExport, bool stream) :
- H(h), C(c), _dllExport(dllExport), _stream(stream)
+ H(h), C(c), _dllExport(dllExport), _stream(stream), _doneStaticSymbol(false)
{
}
@@ -2785,7 +2794,16 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
if(!p->isAbstract() && !p->isLocal())
{
- H << sp << nl << "static " << scoped << " __" << p->name() << "_init;";
+ //
+ // We need an instance here to trigger initialization if the implementation is in a shared libarry.
+ // But we do this only once per source file, because a single instance is sufficient to initialize
+ // all of the globals in a shared library.
+ //
+ if(!_doneStaticSymbol)
+ {
+ _doneStaticSymbol = true;
+ H << sp << nl << "static " << scoped << " __" << p->name() << "_init;";
+ }
}
if(p->isLocal())
diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h
index f57b6adeca9..3f8a1c8dfc9 100644
--- a/cpp/src/slice2cpp/Gen.h
+++ b/cpp/src/slice2cpp/Gen.h
@@ -83,6 +83,7 @@ private:
std::string _dllExport;
bool _stream;
+ bool _doneStaticSymbol;
};
class ProxyDeclVisitor : private ::IceUtil::noncopyable, public ParserVisitor
@@ -238,6 +239,7 @@ private:
std::string _dllExport;
bool _stream;
+ bool _doneStaticSymbol;
};
class IceInternalVisitor : private ::IceUtil::noncopyable, public ParserVisitor
diff --git a/cpp/src/slice2cppe/Gen.cpp b/cpp/src/slice2cppe/Gen.cpp
index 02323403aba..a68f7e16936 100644
--- a/cpp/src/slice2cppe/Gen.cpp
+++ b/cpp/src/slice2cppe/Gen.cpp
@@ -303,7 +303,7 @@ Slice::Gen::generate(const UnitPtr& p)
}
Slice::Gen::TypesVisitor::TypesVisitor(Output& h, Output& c, const string& dllExport) :
- H(h), C(c), _dllExport(dllExport)
+ H(h), C(c), _dllExport(dllExport), _doneStaticSymbol(false)
{
}
@@ -611,7 +611,16 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
if(!p->isLocal())
{
- H << sp << nl << "static " << name << " __" << p->name() << "_init;";
+ //
+ // We need an instance here to trigger initialization if the implementation is in a shared libarry.
+ // But we do this only once per source file, because a single instance is sufficient to initialize
+ // all of the globals in a shared library.
+ //
+ if(!_doneStaticSymbol)
+ {
+ _doneStaticSymbol = true;
+ H << sp << nl << "static " << name << " __" << p->name() << "_init;";
+ }
}
}
diff --git a/cpp/src/slice2cppe/Gen.h b/cpp/src/slice2cppe/Gen.h
index d8b6ab74aab..3d97d7c572d 100644
--- a/cpp/src/slice2cppe/Gen.h
+++ b/cpp/src/slice2cppe/Gen.h
@@ -84,6 +84,7 @@ private:
::IceUtil::Output& C;
std::string _dllExport;
+ bool _doneStaticSymbol;
};
class ProxyDeclVisitor : private ::IceUtil::noncopyable, public ParserVisitor