Thanks Ulrich, changes make the handle of closing much cleaner and
robust thanks :-)  Changes now merged and submitted to svn/trunk and
OSG-3.2 branch

On 24 July 2013 18:15, Ulrich Hertlein <[email protected]> wrote:
> Hi Robert,
>
> Based on the exchange on osg-users I went ahead and reworked shp/XBaseParser 
> to avoid
> weird behaviour (closing stdin) and leaking file descriptors, as well as some 
> const-ness.
>
> Cheers,
> /ulrich
>
> Index: ESRIShapeReaderWriter.cpp
> ===================================================================
> --- ESRIShapeReaderWriter.cpp   (revision 13686)
> +++ ESRIShapeReaderWriter.cpp   (working copy)
> @@ -67,7 +67,7 @@
>                      osg::Geode * geode = sp.getGeode();
>                      unsigned int i = 0;
>
> -                    ESRIShape::XBaseParser::ShapeAttributeListList::iterator 
> it, end =
> xbp.getAttributeList().end();
> +                    
> ESRIShape::XBaseParser::ShapeAttributeListList::const_iterator it,
> end = xbp.getAttributeList().end();
>                      for (it = xbp.getAttributeList().begin(); it != end; 
> ++it, ++i)
>                      {
>                          geode->getDrawable(i)->setUserData(it->get());
> Index: XBaseParser.cpp
> ===================================================================
> --- XBaseParser.cpp     (revision 13686)
> +++ XBaseParser.cpp     (working copy)
> @@ -80,12 +80,12 @@
>  }
>
>
> -XBaseParser::XBaseParser(const std::string fileName):
> +XBaseParser::XBaseParser(const std::string& fileName):
>      _valid(false)
>  {
> -    int fd = 0;
> -    if (fileName.empty() == false)
> +    if (!fileName.empty())
>      {
> +        int fd = 0;
>  #ifdef WIN32
>          if( (fd = open( fileName.c_str(), O_RDONLY | O_BINARY )) < 0 )
>  #else
> @@ -93,11 +93,13 @@
>  #endif
>          {
>              perror( fileName.c_str() );
> -            return;
>          }
> +        else
> +        {
> +            _valid = parse(fd);
> +            close(fd);
> +        }
>      }
> -
> -    _valid = parse(fd);
>  }
>
>  bool XBaseParser::parse(int fd)
> @@ -208,8 +210,6 @@
>
>      delete [] record;
>
> -    close (fd);
> -
>      return true;
>  }
>
> Index: XBaseParser.h
> ===================================================================
> --- XBaseParser.h       (revision 13686)
> +++ XBaseParser.h       (working copy)
> @@ -62,10 +62,11 @@
>
>          typedef std::vector< osg::ref_ptr<osgSim::ShapeAttributeList> >
> ShapeAttributeListList;
>
> -        XBaseParser(const std::string fileName);
> +        XBaseParser(const std::string& fileName);
>          ~XBaseParser() {}
> -        ShapeAttributeListList & getAttributeList() { return 
> _shapeAttributeListList; }
>
> +        const ShapeAttributeListList & getAttributeList() const { return
> _shapeAttributeListList; }
> +
>      private:
>
>          XBaseParser();
>
> _______________________________________________
> osg-submissions mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
>
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to