Home Comments

Pitfall in Ice::initialize

grembogrembo Member Michael GmelinOrganization: Grem Equity GmbHProject: E-Commerce platform
Hi,

not sure if this qualifies as a bug, but at least as a documentation glitch I guess.

Calling Ice::initialize in C++ calls the overloaded function
ICE_API CommunicatorPtr initialize(const InitializationData& = InitializationData(), 
                                   Int = ICE_INT_VERSION);

which does NOT honor the environment variable ICE_CONFIG. So if someone wants call to call Ice::initialize programmatically she always has to make sure to call the argc/argv version like
int argc = 0;
char** argv = 0;
ic = Ice::initialize(argc, argv);

Comments

  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi,

    This behavior is intentional. We mention this in the manual:
    Note that you must supply an argument vector if you want initialize to look for a configuration file in the ICE_CONFIG environment variable.
    The reasoning is that, if you supply an InitializationData value without an argument vector, then you've presumably already dealt with any command-line arguments and have established your configuration properties. Here's the typical use case:
    Ice::InitializationData init;
    init.properties = Ice::createProperties(argc, argv); // Uses ICE_CONFIG
    init.properties->setProperty(...); // Set additional properties
    Ice::CommunicatorPtr comm = Ice::initialize(init);
    
    In this situation, it would be pretty annoying if the call to initialize loaded the file referred to in ICE_CONFIG again, thereby overriding the existing contents of the property set you provided in the InitializationData value.

    Regards,
    Mark
  • grembogrembo Member Michael GmelinOrganization: Grem Equity GmbHProject: E-Commerce platform
    Hi Mark,

    I agree with your example that if initialization data is passed no parsing of ICE_CONFIG etc. should happen. I disagree on a design level with the choice to give InitializationData a default value, making it the default constructor. What got me was that I wasn't aware that Ice::initialize() would call that version of the constructor (I was just hoping it would call a "normal" version - whatever normal might mean).

    So in my opinion the signature should of initialize should be:
    ICE_API CommunicatorPtr initialize(const InitializationData&, 
                                       Int = ICE_INT_VERSION);
    

    instead of:
    ICE_API CommunicatorPtr initialize(const InitializationData& = InitializationData(), 
                                       Int = ICE_INT_VERSION);
    

    To make the call explicit.

    But of course, that's just me, plus changing this at this point probably won't make any sense anyway. Thanks for pointing out the correct section in the manual.

    cheers
    Michael
Sign In or Register to comment.