Changeset 19811

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

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/trunk/modules/jackal/config/jccl/Config/Configuration.cpp

    r19801 r19811  
    176176      << "' with parent file '" << parentfile << "'\n" << vprDEBUG_FLUSH; 
    177177 
    178    mFileName = ParseUtil::expandFileName(filename, parentfile); 
    179  
    180    vprDEBUG_OutputGuard(jcclDBG_CONFIG, vprDBG_CONFIG_LVL, 
    181                         std::string("Loading config file ") + mFileName + 
    182                            std::string("\n"), 
    183                         std::string("")); 
     178   const std::string expanded_filename = ParseUtil::expandFileName(filename, 
     179                                                                   parentfile); 
     180 
     181   std::ostringstream msg; 
     182   msg << "Loading config file '" << expanded_filename << "'\n"; 
     183   vprDEBUG_OutputGuard(jcclDBG_CONFIG, vprDBG_CONFIG_LVL, msg.str(), ""); 
    184184 
    185185   // XXX: Previously, this used ElementFactory::createXMLDocument(), but for 
     
    190190   try 
    191191   { 
    192       cfg_doc.loadFile(mFileName); 
     192      cfg_doc.loadFile(expanded_filename); 
    193193 
    194194      cppdom::NodePtr cfg_node(cfg_doc.getChild(tokens::CONFIGURATION)); 
     
    216216 
    217217         // Load the file by making a recursive call to this method. We use 
    218          // mFileName so that the fully expanded path to the including file is 
    219          // used as the "parent" file. 
    220          load(cfg_filename, mFileName); 
     218         // expanded_filename so that the fully expanded path to the including 
     219         // file is used as the "parent" file. 
     220         load(cfg_filename, expanded_filename); 
    221221      } 
    222222 
    223223      // Load in the elements in the original file. 
    224       loadFromElementNode(cfg_node->getChild(tokens::ELEMENTS), mFileName); 
     224      loadFromElementNode(cfg_node->getChild(tokens::ELEMENTS), 
     225                          expanded_filename); 
     226 
     227      // This is a recursive method, and we want to set mFileName as the last 
     228      // step of the loading process since that will end up using the 
     229      // original file name as the configuration file. 
     230      mFileName = expanded_filename; 
     231      vprDEBUG(jcclDBG_CONFIG, vprDBG_CONFIG_LVL) 
     232         << "Configuration file name: '" << mFileName << "'" << std::endl 
     233         << vprDEBUG_FLUSH; 
    225234 
    226235      status = true; 
     
    237246      vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL) 
    238247         << clrOutBOLD(clrRED, "Configuration XML Error:") << " " 
    239          << mFileName << ": line " << line_num << " at position " << pos 
    240          << std::endl << vprDEBUG_FLUSH; 
     248         << expanded_filename << ": line " << line_num << " at position " 
     249         << pos << std::endl << vprDEBUG_FLUSH; 
    241250      vprDEBUG_NEXT(vprDBG_ERROR, vprDBG_CRITICAL_LVL) 
    242251         << "Error: " << errmsg << std::endl << vprDEBUG_FLUSH; 
    243252 
    244253      // Print out the actual failed XML. 
    245       std::ifstream errfile(mFileName.c_str()); 
     254      std::ifstream errfile(expanded_filename.c_str()); 
    246255      if ( errfile ) 
    247256      {