diff options
author | Marc Laukien <marc@zeroc.com> | 2002-07-30 21:11:37 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2002-07-30 21:11:37 +0000 |
commit | bbcd09d1d4e78ffa7e0b9b7455caabb16bbfcb2f (patch) | |
tree | 4ca9af035c84bb6333405fd1aa4bf7f2aa9b15fc /cpp/src | |
parent | Fix (diff) | |
download | ice-bbcd09d1d4e78ffa7e0b9b7455caabb16bbfcb2f.tar.bz2 ice-bbcd09d1d4e78ffa7e0b9b7455caabb16bbfcb2f.tar.xz ice-bbcd09d1d4e78ffa7e0b9b7455caabb16bbfcb2f.zip |
revised leak test
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/CommunicatorI.cpp | 64 | ||||
-rw-r--r-- | cpp/src/Ice/CommunicatorI.h | 2 | ||||
-rw-r--r-- | cpp/src/Ice/Instance.cpp | 36 | ||||
-rw-r--r-- | cpp/src/Ice/Instance.h | 3 | ||||
-rw-r--r-- | cpp/src/Ice/ObjectAdapterFactory.cpp | 9 | ||||
-rw-r--r-- | cpp/src/Ice/ObjectAdapterFactory.h | 3 | ||||
-rw-r--r-- | cpp/src/Ice/ObjectAdapterI.cpp | 7 | ||||
-rw-r--r-- | cpp/src/Ice/ObjectAdapterI.h | 3 | ||||
-rw-r--r-- | cpp/src/Ice/PluginManagerI.cpp | 46 | ||||
-rw-r--r-- | cpp/src/Ice/PluginManagerI.h | 20 | ||||
-rw-r--r-- | cpp/src/Ice/ProtocolPluginFacade.cpp | 15 | ||||
-rw-r--r-- | cpp/src/Slice/Scanner.l | 4 |
12 files changed, 118 insertions, 94 deletions
diff --git a/cpp/src/Ice/CommunicatorI.cpp b/cpp/src/Ice/CommunicatorI.cpp index 81bf20ddcad..79e72685229 100644 --- a/cpp/src/Ice/CommunicatorI.cpp +++ b/cpp/src/Ice/CommunicatorI.cpp @@ -30,23 +30,14 @@ Ice::CommunicatorI::destroy() { RecMutex::Lock sync(*this); - if(_instance) + if(!_destroyed) // Don't destroy twice. { - _serverThreadPool = 0; - - LoggerPtr logger = _instance->logger(); + _destroyed = true; _instance->objectAdapterFactory()->shutdown(); _instance->destroy(); - if(_instance->__getRef() > 1) - { - Warning warn(logger); - warn << "memory leak in the Ice core:\n"; - warn << "IceInteral::Instance is not deleted after Ice::Communicator::destroy()"; - } - - _instance = 0; + _serverThreadPool = 0; } } @@ -79,7 +70,7 @@ ObjectPrx Ice::CommunicatorI::stringToProxy(const string& s) { RecMutex::Lock sync(*this); - if(!_instance) + if(_destroyed) { throw CommunicatorDestroyedException(__FILE__, __LINE__); } @@ -90,7 +81,7 @@ string Ice::CommunicatorI::proxyToString(const ObjectPrx& proxy) { RecMutex::Lock sync(*this); - if(!_instance) + if(_destroyed) { throw CommunicatorDestroyedException(__FILE__, __LINE__); } @@ -101,7 +92,7 @@ ObjectAdapterPtr Ice::CommunicatorI::createObjectAdapter(const string& name) { RecMutex::Lock sync(*this); - if(!_instance) + if(_destroyed) { throw CommunicatorDestroyedException(__FILE__, __LINE__); } @@ -127,7 +118,7 @@ ObjectAdapterPtr Ice::CommunicatorI::createObjectAdapterFromProperty(const string& name, const string& property) { RecMutex::Lock sync(*this); - if(!_instance) + if(_destroyed) { throw CommunicatorDestroyedException(__FILE__, __LINE__); } @@ -141,7 +132,7 @@ ObjectAdapterPtr Ice::CommunicatorI::createObjectAdapterWithEndpoints(const string& name, const string& endpts) { RecMutex::Lock sync(*this); - if(!_instance) + if(_destroyed) { throw CommunicatorDestroyedException(__FILE__, __LINE__); } @@ -165,7 +156,7 @@ void Ice::CommunicatorI::addObjectFactory(const ObjectFactoryPtr& factory, const string& id) { RecMutex::Lock sync(*this); - if(!_instance) + if(_destroyed) { throw CommunicatorDestroyedException(__FILE__, __LINE__); } @@ -176,7 +167,7 @@ void Ice::CommunicatorI::removeObjectFactory(const string& id) { RecMutex::Lock sync(*this); - if(!_instance) + if(_destroyed) { throw CommunicatorDestroyedException(__FILE__, __LINE__); } @@ -187,7 +178,7 @@ ObjectFactoryPtr Ice::CommunicatorI::findObjectFactory(const string& id) { RecMutex::Lock sync(*this); - if(!_instance) + if(_destroyed) { throw CommunicatorDestroyedException(__FILE__, __LINE__); } @@ -198,7 +189,7 @@ void Ice::CommunicatorI::addUserExceptionFactory(const UserExceptionFactoryPtr& factory, const string& id) { RecMutex::Lock sync(*this); - if(!_instance) + if(_destroyed) { throw CommunicatorDestroyedException(__FILE__, __LINE__); } @@ -209,7 +200,7 @@ void Ice::CommunicatorI::removeUserExceptionFactory(const string& id) { RecMutex::Lock sync(*this); - if(!_instance) + if(_destroyed) { throw CommunicatorDestroyedException(__FILE__, __LINE__); } @@ -220,7 +211,7 @@ UserExceptionFactoryPtr Ice::CommunicatorI::findUserExceptionFactory(const string& id) { RecMutex::Lock sync(*this); - if(!_instance) + if(_destroyed) { throw CommunicatorDestroyedException(__FILE__, __LINE__); } @@ -231,7 +222,7 @@ PropertiesPtr Ice::CommunicatorI::getProperties() { RecMutex::Lock sync(*this); - if(!_instance) + if(_destroyed) { throw CommunicatorDestroyedException(__FILE__, __LINE__); } @@ -242,7 +233,7 @@ LoggerPtr Ice::CommunicatorI::getLogger() { RecMutex::Lock sync(*this); - if(!_instance) + if(_destroyed) { throw CommunicatorDestroyedException(__FILE__, __LINE__); } @@ -253,7 +244,7 @@ void Ice::CommunicatorI::setLogger(const LoggerPtr& logger) { RecMutex::Lock sync(*this); - if(!_instance) + if(_destroyed) { throw CommunicatorDestroyedException(__FILE__, __LINE__); } @@ -276,14 +267,15 @@ PluginManagerPtr Ice::CommunicatorI::getPluginManager() { RecMutex::Lock sync(*this); - if(!_instance) + if(_destroyed) { throw CommunicatorDestroyedException(__FILE__, __LINE__); } return _instance->pluginManager(); } -Ice::CommunicatorI::CommunicatorI(int& argc, char* argv[], const PropertiesPtr& properties) +Ice::CommunicatorI::CommunicatorI(int& argc, char* argv[], const PropertiesPtr& properties) : + _destroyed(false) { __setNoDelete(true); try @@ -300,10 +292,22 @@ Ice::CommunicatorI::CommunicatorI(int& argc, char* argv[], const PropertiesPtr& Ice::CommunicatorI::~CommunicatorI() { - if(_instance) + if(!_destroyed) { Warning out(_instance->logger()); - out << "communicator has not been destroyed"; + out << "Ice::Communicator::destroy() has not been called"; + } + + if(_instance->__getRef() > 1) + { + PropertiesPtr properties = _instance->properties(); + if(properties->getPropertyAsIntWithDefault("Ice.LeakWarnings", 1) > 0) + { + Warning warn(_instance->logger()); + warn << + "The communicator is not the last Ice object that is deleted. (You can\n" + "disable this warning by setting the property `Ice.LeakWarnings' to 0.)"; + } } } diff --git a/cpp/src/Ice/CommunicatorI.h b/cpp/src/Ice/CommunicatorI.h index d5c59327221..8b0c8cade17 100644 --- a/cpp/src/Ice/CommunicatorI.h +++ b/cpp/src/Ice/CommunicatorI.h @@ -69,6 +69,8 @@ private: friend ICE_API CommunicatorPtr initializeWithProperties(int&, char*[], const PropertiesPtr&, Int); friend ICE_API ::IceInternal::InstancePtr IceInternal::getInstance(const ::Ice::CommunicatorPtr&); + bool _destroyed; + ::IceInternal::InstancePtr _instance; // diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index 9f9557b6d4d..9c59f562170 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -29,7 +29,6 @@ #include <Ice/TcpEndpoint.h> #include <Ice/UdpEndpoint.h> #include <Ice/PluginManagerI.h> -#include <Ice/Communicator.h> #include <Ice/Initialize.h> #ifndef _WIN32 @@ -74,13 +73,6 @@ static GlobalStateMutexDestroyer destroyer; void IceInternal::incRef(Instance* p) { p->__incRef(); } void IceInternal::decRef(Instance* p) { p->__decRef(); } -CommunicatorPtr -IceInternal::Instance::communicator() -{ - IceUtil::RecMutex::Lock sync(*this); - return _communicator; -} - PropertiesPtr IceInternal::Instance::properties() { @@ -177,7 +169,7 @@ IceInternal::Instance::clientThreadPool() { IceUtil::RecMutex::Lock sync(*this); - if(_communicator) // Not destroyed? + if(!_destroyed) // Not destroyed? { if(!_clientThreadPool) // Lazy initialization. { @@ -193,7 +185,7 @@ IceInternal::Instance::serverThreadPool() { IceUtil::RecMutex::Lock sync(*this); - if(_communicator) // Not destroyed? + if(!_destroyed) // Not destroyed? { if(!_serverThreadPool) // Lazy initialization. { @@ -220,7 +212,7 @@ IceInternal::Instance::pluginManager() IceInternal::Instance::Instance(const CommunicatorPtr& communicator, int& argc, char* argv[], const PropertiesPtr& properties) : - _communicator(communicator), + _destroyed(false), _properties(properties) { IceUtil::Mutex::Lock sync(*_globalStateMutex); @@ -329,7 +321,7 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, int& argc, EndpointFactoryPtr udpEndpointFactory = new UdpEndpointFactory(this); _endpointFactoryManager->add(udpEndpointFactory); - _pluginManager = new PluginManagerI(this); + _pluginManager = new PluginManagerI(communicator); _outgoingConnectionFactory = new OutgoingConnectionFactory(this); @@ -337,7 +329,7 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, int& argc, _userExceptionFactoryManager = new UserExceptionFactoryManager(); - _objectAdapterFactory = new ObjectAdapterFactory(this); + _objectAdapterFactory = new ObjectAdapterFactory(this, communicator); __setNoDelete(false); } @@ -352,7 +344,7 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, int& argc, IceInternal::Instance::~Instance() { - assert(!_communicator); + assert(_destroyed); assert(!_referenceFactory); assert(!_proxyFactory); assert(!_outgoingConnectionFactory); @@ -486,19 +478,19 @@ IceInternal::Instance::destroy() { IceUtil::RecMutex::Lock sync(*this); + + if(_destroyed) + { + return; // Don't destroy twice. + } + + _destroyed = true; // // Destroy all contained objects. Then set all references to null, // to avoid cyclic object dependencies. // - - if(_communicator) - { - // Don't destroy the communicator -- the communicator destroys - // this object, not the other way. - _communicator = 0; - } - + if(_objectAdapterFactory) { // Don't shut down the object adapters -- the communicator diff --git a/cpp/src/Ice/Instance.h b/cpp/src/Ice/Instance.h index 3a4a4830a93..0d8121c0dba 100644 --- a/cpp/src/Ice/Instance.h +++ b/cpp/src/Ice/Instance.h @@ -47,7 +47,6 @@ class Instance : public ::IceUtil::Shared, public ::IceUtil::RecMutex { public: - ::Ice::CommunicatorPtr communicator(); ::Ice::PropertiesPtr properties(); ::Ice::LoggerPtr logger(); void logger(const ::Ice::LoggerPtr&); @@ -74,7 +73,7 @@ private: void destroy(); friend class ::Ice::CommunicatorI; - ::Ice::CommunicatorPtr _communicator; + bool _destroyed; ::Ice::PropertiesPtr _properties; // Immutable, not reset by destroy(). ::Ice::LoggerPtr _logger; // Not reset by destroy(). TraceLevelsPtr _traceLevels; // Immutable, not reset by destroy(). diff --git a/cpp/src/Ice/ObjectAdapterFactory.cpp b/cpp/src/Ice/ObjectAdapterFactory.cpp index ce5246d7443..2d19064514e 100644 --- a/cpp/src/Ice/ObjectAdapterFactory.cpp +++ b/cpp/src/Ice/ObjectAdapterFactory.cpp @@ -11,7 +11,6 @@ #include <Ice/ObjectAdapterFactory.h> #include <Ice/ObjectAdapterI.h> #include <Ice/Functional.h> -#include <Ice/Instance.h> using namespace std; using namespace Ice; @@ -42,7 +41,7 @@ IceInternal::ObjectAdapterFactory::createObjectAdapter(const string& name, const return p->second; } - ObjectAdapterIPtr adapter = new ObjectAdapterI(_instance, name, endpts); + ObjectAdapterIPtr adapter = new ObjectAdapterI(_instance, _communicator, name, endpts); _adapters.insert(make_pair(name, adapter)); return adapter; } @@ -63,7 +62,9 @@ IceInternal::ObjectAdapterFactory::findObjectAdapter(const ObjectPrx& proxy) return 0; } -IceInternal::ObjectAdapterFactory::ObjectAdapterFactory(const InstancePtr& instance) : - _instance(instance) +IceInternal::ObjectAdapterFactory::ObjectAdapterFactory(const InstancePtr& instance, + const CommunicatorPtr& communicator) : + _instance(instance), + _communicator(communicator) { } diff --git a/cpp/src/Ice/ObjectAdapterFactory.h b/cpp/src/Ice/ObjectAdapterFactory.h index cc23a3263a0..7657b955fa5 100644 --- a/cpp/src/Ice/ObjectAdapterFactory.h +++ b/cpp/src/Ice/ObjectAdapterFactory.h @@ -27,10 +27,11 @@ public: private: - ObjectAdapterFactory(const InstancePtr&); + ObjectAdapterFactory(const InstancePtr&, const ::Ice::CommunicatorPtr&); friend class Instance; InstancePtr _instance; + ::Ice::CommunicatorPtr _communicator; std::map<std::string, ::Ice::ObjectAdapterIPtr> _adapters; }; diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index b4dac6d00e3..a7b64d3877f 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -52,7 +52,7 @@ Ice::ObjectAdapterI::getCommunicator() throw ObjectAdapterDeactivatedException(__FILE__, __LINE__); } - return _instance->communicator(); + return _communicator; } void @@ -145,6 +145,7 @@ Ice::ObjectAdapterI::deactivate() _locatorMapHint = _locatorMap.end(); _instance = 0; + _communicator = 0; } void @@ -467,8 +468,10 @@ Ice::ObjectAdapterI::getIncomingConnections() const return connections; } -Ice::ObjectAdapterI::ObjectAdapterI(const InstancePtr& instance, const string& name, const string& endpts) : +Ice::ObjectAdapterI::ObjectAdapterI(const InstancePtr& instance, const CommunicatorPtr& communicator, + const string& name, const string& endpts) : _instance(instance), + _communicator(communicator), _printAdapterReadyDone(false), _name(name), _activeServantMapHint(_activeServantMap.end()), diff --git a/cpp/src/Ice/ObjectAdapterI.h b/cpp/src/Ice/ObjectAdapterI.h index 0c20704a54b..88009692b78 100644 --- a/cpp/src/Ice/ObjectAdapterI.h +++ b/cpp/src/Ice/ObjectAdapterI.h @@ -66,7 +66,7 @@ public: private: - ObjectAdapterI(const ::IceInternal::InstancePtr&, const std::string&, const std::string&); + ObjectAdapterI(const ::IceInternal::InstancePtr&, const CommunicatorPtr&, const std::string&, const std::string&); virtual ~ObjectAdapterI(); friend class ::IceInternal::ObjectAdapterFactory; @@ -75,6 +75,7 @@ private: bool isLocal(const ObjectPrx&) const; ::IceInternal::InstancePtr _instance; + CommunicatorPtr _communicator; bool _printAdapterReadyDone; std::string _name; bool _useEndpointsInProxy; diff --git a/cpp/src/Ice/PluginManagerI.cpp b/cpp/src/Ice/PluginManagerI.cpp index efc205f0b9f..b2e7124e8d5 100644 --- a/cpp/src/Ice/PluginManagerI.cpp +++ b/cpp/src/Ice/PluginManagerI.cpp @@ -10,8 +10,8 @@ #include <Ice/PluginManagerI.h> #include <Ice/DynamicLibrary.h> +#include <Ice/Communicator.h> #include <Ice/Properties.h> -#include <Ice/Instance.h> #include <Ice/LoggerUtil.h> #include <Ice/Initialize.h> #include <Ice/LocalException.h> @@ -22,21 +22,22 @@ using namespace IceInternal; typedef Ice::Plugin* (*PLUGIN_FACTORY)(const CommunicatorPtr&, const string&, const StringSeq&); -Ice::PluginManagerI::PluginManagerI(const InstancePtr& instance) - : _instance(instance) -{ -} - PluginPtr Ice::PluginManagerI::getPlugin(const string& name) { IceUtil::Mutex::Lock sync(*this); + if(!_communicator) + { + throw CommunicatorDestroyedException(__FILE__, __LINE__); + } + map<string, PluginInfo>::const_iterator r = _plugins.find(name); if(r != _plugins.end()) { return (*r).second.plugin; } + throw PluginNotFoundException(__FILE__, __LINE__); } @@ -45,6 +46,11 @@ Ice::PluginManagerI::addPlugin(const string& name, const PluginPtr& plugin) { IceUtil::Mutex::Lock sync(*this); + if(!_communicator) + { + throw CommunicatorDestroyedException(__FILE__, __LINE__); + } + map<string, PluginInfo>::const_iterator r = _plugins.find(name); if(r != _plugins.end()) { @@ -60,18 +66,30 @@ Ice::PluginManagerI::destroy() { IceUtil::Mutex::Lock sync(*this); - map<string, PluginInfo>::iterator r; - for(r = _plugins.begin(); r != _plugins.end(); ++r) + if(_communicator) { - (*r).second.plugin->destroy(); - (*r).second.plugin = 0; - (*r).second.library = 0; + map<string, PluginInfo>::iterator r; + for(r = _plugins.begin(); r != _plugins.end(); ++r) + { + r->second.plugin->destroy(); + r->second.plugin = 0; + r->second.library = 0; + } + + _communicator = 0; } } +Ice::PluginManagerI::PluginManagerI(const CommunicatorPtr& communicator) : + _communicator(communicator) +{ +} + void Ice::PluginManagerI::loadPlugins(int& argc, char* argv[]) { + assert(_communicator); + StringSeq cmdArgs = argsToStringSeq(argc, argv); // @@ -82,7 +100,7 @@ Ice::PluginManagerI::loadPlugins(int& argc, char* argv[]) // Ice.Plugin.name=entry_point [args] // const string prefix = "Ice.Plugin."; - PropertiesPtr properties = _instance->properties(); + PropertiesPtr properties = _communicator->getProperties(); PropertyDict plugins = properties->getPropertiesForPrefix(prefix); PropertyDict::const_iterator p; for(p = plugins.begin(); p != plugins.end(); ++p) @@ -137,6 +155,8 @@ Ice::PluginManagerI::loadPlugins(int& argc, char* argv[]) void Ice::PluginManagerI::loadPlugin(const string& name, const string& entryPoint, const StringSeq& args) { + assert(_communicator); + // // Load the entry point symbol. // @@ -163,7 +183,7 @@ Ice::PluginManagerI::loadPlugin(const string& name, const string& entryPoint, co PLUGIN_FACTORY factory = (PLUGIN_FACTORY)sym; try { - info.plugin = factory(_instance->communicator(), name, args); + info.plugin = factory(_communicator, name, args); } catch(const Exception& ex) { diff --git a/cpp/src/Ice/PluginManagerI.h b/cpp/src/Ice/PluginManagerI.h index db802754755..70f5f4043dd 100644 --- a/cpp/src/Ice/PluginManagerI.h +++ b/cpp/src/Ice/PluginManagerI.h @@ -27,26 +27,24 @@ class PluginManagerI : public PluginManager, public IceUtil::Mutex public: virtual PluginPtr getPlugin(const std::string&); - virtual void addPlugin(const std::string&, const PluginPtr&); - virtual void destroy(); - struct PluginInfo - { - PluginPtr plugin; - IceInternal::DynamicLibraryPtr library; - }; - private: - PluginManagerI(const IceInternal::InstancePtr&); - void loadPlugins(int&, char*[]); + PluginManagerI(const CommunicatorPtr&); friend class IceInternal::Instance; + void loadPlugins(int&, char*[]); void loadPlugin(const std::string&, const std::string&, const StringSeq&); - IceInternal::InstancePtr _instance; + CommunicatorPtr _communicator; + + struct PluginInfo + { + PluginPtr plugin; + IceInternal::DynamicLibraryPtr library; + }; std::map<std::string, PluginInfo> _plugins; }; diff --git a/cpp/src/Ice/ProtocolPluginFacade.cpp b/cpp/src/Ice/ProtocolPluginFacade.cpp index 54f69c08734..5d9f98134bb 100644 --- a/cpp/src/Ice/ProtocolPluginFacade.cpp +++ b/cpp/src/Ice/ProtocolPluginFacade.cpp @@ -25,18 +25,13 @@ void IceInternal::decRef(ProtocolPluginFacade* p) { p->__decRef(); } ProtocolPluginFacadePtr IceInternal::getProtocolPluginFacade(const CommunicatorPtr& communicator) { - return new ProtocolPluginFacade(getInstance(communicator)); -} - -IceInternal::ProtocolPluginFacade::ProtocolPluginFacade(const InstancePtr& instance) - : _instance(instance) -{ + return new ProtocolPluginFacade(communicator); } CommunicatorPtr IceInternal::ProtocolPluginFacade::getCommunicator() const { - return _instance->communicator(); + return _communicator; } string @@ -62,3 +57,9 @@ IceInternal::ProtocolPluginFacade::addEndpointFactory(const EndpointFactoryPtr& { _instance->endpointFactoryManager()->add(factory); } + +IceInternal::ProtocolPluginFacade::ProtocolPluginFacade(const CommunicatorPtr& communicator) : + _instance(getInstance(communicator)), + _communicator(communicator) +{ +} diff --git a/cpp/src/Slice/Scanner.l b/cpp/src/Slice/Scanner.l index 7635bce2fa6..22de810fd60 100644 --- a/cpp/src/Slice/Scanner.l +++ b/cpp/src/Slice/Scanner.l @@ -125,10 +125,12 @@ floating_literal (({fractional_constant}{exponent_part}?)|([[:digit:]]+{exponent StringTokPtr ident = new StringTok; ident->v = *yytext == '\\' ? yytext + 1 : yytext; *yylvalp = ident; + if(ident->v.find('_') != string::npos) { - unit->warning("illegal underscore in identifier `" + ident->v + "'"); + unit->warning("illegal underscore in identifier `" + ident->v + "'"); } + static const string suffixBlacklist[] = { "Helper", "Holder", "Operations", "Prx", "Ptr" }; for(size_t i = 0; i < sizeof(suffixBlacklist) / sizeof(*suffixBlacklist); ++i) { |