diff options
author | Michi Henning <michi@zeroc.com> | 2006-07-13 06:02:58 +0000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2006-07-13 06:02:58 +0000 |
commit | 20087fd26e253755d9ea223ede49a4416fa2a0da (patch) | |
tree | 4e9509ca022c91e1013c7c00f60fed42a141a189 /cpp/src/slice2cpp/Gen.cpp | |
parent | changing icephp embedded libpath to refer to the intended Ice installation (diff) | |
download | ice-20087fd26e253755d9ea223ede49a4416fa2a0da.tar.bz2 ice-20087fd26e253755d9ea223ede49a4416fa2a0da.tar.xz ice-20087fd26e253755d9ea223ede49a4416fa2a0da.zip |
Added protected destructor to non-abstract Slice classes.
Diffstat (limited to 'cpp/src/slice2cpp/Gen.cpp')
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 8f51fc4173e..d6eae4aa3b3 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -3108,6 +3108,19 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) C << nl << "extern \"C\" { void " << initfuncname << "() {} }"; C << nl << "#endif"; } + + // + // We add a protected destructor to force heap instantiation of the class. + // + H.dec(); + H << sp << nl << "protected:"; + H.inc(); + H << sp << nl << "virtual ~" << fixKwd(p->name()) << "() {}"; + + if(!p->isAbstract() && !_doneStaticSymbol) + { + H << sp << nl << "friend class " << p->name() << "__staticInit;"; + } } H << eb << ';'; @@ -3115,14 +3128,23 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) if(!p->isAbstract() && !p->isLocal()) { // - // We need an instance here to trigger initialization if the implementation is in a shared libarry. + // We need an instance here to trigger initialization if the implementation is in a shared library. // 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. + // For a Slice class Foo, we instantiate a dummy class Foo__staticInit instead of using a static + // Foo instance directly because Foo has a protected destructor. // if(!_doneStaticSymbol) { + H << sp << nl << "class " << p->name() << "__staticInit"; + H << sb; + H.dec(); + H << nl << "public:"; + H.inc(); + H << sp << nl << scoped << " _init;"; + H << eb << ';'; _doneStaticSymbol = true; - H << sp << nl << "static " << scoped << " __" << p->name() << "_init;"; + H << sp << nl << "static " << scoped << "__staticInit _" << p->name() << "_init;"; } } |