Changeset 19812

Show
Ignore:
Timestamp:
02/14/07 11:28:11 (2 years ago)
Author:
patrick
Message:

MFT [rev 19811]:

Be more careful about the setting of mFileName. Since load() is called
recursively for loading included files, we have to be sure that mFileName
is set as the last step of loading rather than as the first so that the
originally named file is the one that gets associated with the
jccl::Configuration instance. Furthermore, during recursion, we cannot read
from mFileName because its value is invalid at that point. Instead, we need
to make careful use of scoping provided by the call stack to keep track of
which file name really refers to the parent file.

A better way of handling this may be to have a separate method used for
the recursive inclusion process. Making this change would require breaking
up load() so that its code can be reused more effectively. The need for a
separate method to do the recursive inclusion is debatable.

This fixes Trac Ticket #2.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/branches/2.0/modules/jackal/config/jccl/Config/Configuration.cpp

    r19802 r19812  
    182182      << "' with parent file '" << parentfile << "'\n" << vprDEBUG_FLUSH; 
    183183 
    184    mFileName = ParseUtil::expandFileName(filename, parentfile); 
    185  
    186    vprDEBUG_OutputGuard(jcclDBG_CONFIG, vprDBG_CONFIG_LVL, 
    187                         std::string("Loading config file ") + mFileName + 
    188                            std::string("\n"), 
    189                         std::string("")); 
     184   const std::string expanded_filename = ParseUtil::expandFileName(filename, 
     185                                                                   parentfile); 
     186 
     187   std::ostringstream msg; 
     188   msg << "Loading config file '" << expanded_filename << "'\n"; 
     189   vprDEBUG_OutputGuard(jcclDBG_CONFIG, vprDBG_CONFIG_LVL, msg.str(), ""); 
    190190 
    191191   // XXX: Previously, this used ElementFactory::createXMLDocument(), but for 
     
    196196   try 
    197197   { 
    198       cfg_doc.loadFile(mFileName); 
     198      cfg_doc.loadFile(expanded_filename); 
    199199 
    200200      cppdom::NodePtr cfg_node(cfg_doc.getChild(tokens::CONFIGURATION)); 
     
    222222 
    223223         // Load the file by making a recursive call to this method. We use 
    224          // mFileName so that the fully expanded path to the including file is 
    225          // used as the "parent" file. 
    226          load(cfg_filename, mFileName); 
     224         // expanded_filename so that the fully expanded path to the including 
     225         // file is used as the "parent" file. 
     226         load(cfg_filename, expanded_filename); 
    227227      } 
    228228 
    229229      // Load in the elements in the original file. 
    230       loadFromElementNode(cfg_node->getChild(tokens::ELEMENTS), mFileName); 
     230      loadFromElementNode(cfg_node->getChild(tokens::ELEMENTS), 
     231                          expanded_filename); 
     232 
     233      // This is a recursive method, and we want to set mFileName as the last 
     234      // step of the loading process since that will end up using the 
     235      // original file name as the configuration file. 
     236      mFileName = expanded_filename; 
     237      vprDEBUG(jcclDBG_CONFIG, vprDBG_CONFIG_LVL) 
     238         << "Configuration file name: '" << mFileName << "'" << std::endl 
     239         << vprDEBUG_FLUSH; 
    231240 
    232241      status = true; 
     
    243252      vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL) 
    244253         << clrOutBOLD(clrRED, "Configuration XML Error:") << " " 
    245          << mFileName << ": line " << line_num << " at position " << pos 
    246          << std::endl << vprDEBUG_FLUSH; 
     254         << expanded_filename << ": line " << line_num << " at position " 
     255         << pos << std::endl << vprDEBUG_FLUSH; 
    247256      vprDEBUG_NEXT(vprDBG_ERROR, vprDBG_CRITICAL_LVL) 
    248257         << "Error: " << errmsg << std::endl << vprDEBUG_FLUSH; 
    249258 
    250259      // Print out the actual failed XML. 
    251       std::ifstream errfile(mFileName.c_str()); 
     260      std::ifstream errfile(expanded_filename.c_str()); 
    252261      if ( errfile ) 
    253262      {