MantisBT - ITK
View Issue Details
0005880ITKpublic2007-10-13 16:052007-11-26 10:51
S Pieper 
Bill Lorensen 
normalminoralways
closedfixed 
 
 
0005880: ITK_AUTOLOAD_PATH doesn't work when more than one separator
If I add the print statements in ObjectFactoryBase::LoadDynamicFactories()as shown in the Additional Information section below, and then I set ITK_AUTOLOAD_PATH to a string with more than one separator character I get the following:

path is /Users/pieper/slicer3/latest/Slicer3-build/bin:/tmp:/usr
CurrentPath is /Users/pieper/slicer3/latest/Slicer3-build/bin
CurrentPath is /tmp:/usr
CurrentPath is /usr
done loading

That is, the middle path is not correctly extracted.
/**
 * Load all libraries in ITK_AUTOLOAD_PATH
 */
void
ObjectFactoryBase
::LoadDynamicFactories()
{
  /**
   * follow PATH conventions
   */
#ifdef _WIN32
  char PathSeparator = ';';
#else
  char PathSeparator = ':';
#endif
  
  std::string LoadPath;
  if (getenv("ITK_AUTOLOAD_PATH"))
    {
    LoadPath = getenv("ITK_AUTOLOAD_PATH");
    }
  else
    {
    return;
    }

  if(LoadPath.size() == 0)
    {
    return;
    }
  std::string::size_type EndSeparatorPosition = 0;
  std::string::size_type StartSeparatorPosition = 0;
std::cerr << "path is " << LoadPath << "\n";
  while ( StartSeparatorPosition != std::string::npos )
    {
    StartSeparatorPosition = EndSeparatorPosition;
    /**
     * find PathSeparator in LoadPath
     */
    EndSeparatorPosition = LoadPath.find(PathSeparator,
                                         StartSeparatorPosition);
    if(EndSeparatorPosition == std::string::npos)
      {
      EndSeparatorPosition = LoadPath.size();
      }
    std::string CurrentPath =
      LoadPath.substr(StartSeparatorPosition, EndSeparatorPosition);
std::cerr << "CurrentPath is " << CurrentPath << "\n";
    ObjectFactoryBase::LoadLibrariesInPath(CurrentPath.c_str());
    /**
     * move past separator
     */
    if(EndSeparatorPosition == LoadPath.size())
      {
      StartSeparatorPosition = std::string::npos;
      }
    else
      {
      EndSeparatorPosition++;
      }
    }
std::cerr << "done loading\n";
}
No tags attached.
Issue History
2007-10-13 16:05S PieperNew Issue
2007-10-27 12:15Bill LorensenStatusnew => assigned
2007-10-27 12:15Bill LorensenAssigned To => Bill Lorensen
2007-11-04 20:36Bill LorensenNote Added: 0009629
2007-11-04 20:36Bill LorensenStatusassigned => confirmed
2007-11-04 20:39Bill LorensenStatusconfirmed => resolved
2007-11-04 20:39Bill LorensenResolutionopen => fixed
2007-11-04 20:39Bill LorensenNote Added: 0009630
2007-11-26 10:51Bill LorensenStatusresolved => closed

Notes
(0009629)
Bill Lorensen   
2007-11-04 20:36   
I added the print statements suggested by Steve and reproduced the problem.
(0009630)
Bill Lorensen   
2007-11-04 20:39   
The logic in the path parsing was flawed. The std::string substr method was being used incorrectly. The second argument is the length of the substring, not the position of the end of the substring.