Commit fcd264fc authored by Brad King's avatar Brad King

Drop old C++ stream EOF workarounds

VTK no longer supports any compilers/platforms on which the
C++ streams have buggy EOF handling.  Drop our compatibility
layer for this case.
parent 3b3fa521
......@@ -72,23 +72,6 @@ SET( VTK_TYPE_CHAR_IS_SIGNED
CACHE STRING "Result from TRY_RUN" FORCE)
# VTK_ANSI_STREAM_EOF_RESULT
# indicates whether the executable would have been able to run on its
# target platform. If so, set VTK_ANSI_STREAM_EOF_RESULT to
# the exit code (in many cases 0 for success), otherwise enter "FAILED_TO_RUN".
# The VTK_ANSI_STREAM_EOF_COMPILED variable holds the build result for this TRY_RUN().
#
# Source file : /work/01642/sujin/Projects/Paraview/Master/builds/base/mic/VTK/CMake/vtkTestStreamEOF.cxx
# Executable : /work/01642/sujin/Projects/Paraview/Master/builds/base/mic/CMakeFiles/cmTryCompileExec1781768933-VTK_ANSI_STREAM_EOF_RESULT
# Run arguments :
# Called from: [2] /work/01642/sujin/Projects/Paraview/Master/ParaView/VTK/CMake/vtkTestStreamsLibrary.cmake
# [1] /work/01642/sujin/Projects/Paraview/Master/ParaView/VTK/CMakeLists.txt
SET( VTK_ANSI_STREAM_EOF_RESULT
"1"
CACHE STRING "Result from TRY_RUN" FORCE)
# KWSYS_LFS_WORKS
# indicates whether the executable would have been able to run on its
# target platform. If so, set KWSYS_LFS_WORKS to
......
......@@ -72,23 +72,6 @@ SET( VTK_TYPE_CHAR_IS_SIGNED
CACHE STRING "Result from TRY_RUN" FORCE)
# VTK_ANSI_STREAM_EOF_RESULT
# indicates whether the executable would have been able to run on its
# target platform. If so, set VTK_ANSI_STREAM_EOF_RESULT to
# the exit code (in many cases 0 for success), otherwise enter "FAILED_TO_RUN".
# The VTK_ANSI_STREAM_EOF_COMPILED variable holds the build result for this TRY_RUN().
#
# Source file : /gpfs/gpfs0/home/gevecb/alex/paraview/build/VTK-head-bgl-new/CMake/vtkTestStreamEOF.cxx
# Executable : /gpfs/gpfs0/home/gevecb/alex/paraview/build/VTK-head-bgl-new/cmTryCompileExec-VTK_ANSI_STREAM_EOF_RESULT
# Run arguments :
# Called from: [2] /gpfs/gpfs0/home/gevecb/alex/paraview/src/ParaView3/VTK/CMake/vtkTestStreamsLibrary.cmake
# [1] /gpfs/gpfs0/home/gevecb/alex/paraview/src/ParaView3/VTK/CMakeLists.txt
SET( VTK_ANSI_STREAM_EOF_RESULT
"0"
CACHE STRING "Result from TRY_RUN" FORCE)
# KWSYS_LFS_WORKS
# indicates whether the executable would have been able to run on its
# target platform. If so, set KWSYS_LFS_WORKS to
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkTestStreamEOF.cxx.in
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// Many C++ streams libraries have buggy conditions when reading
// reaches the end of a file. When an ifstream attempts to read past
// the end of the file, the "eof" and "fail" bits are set. Clearing
// the fail bit should be enough to allow seekg() to work and tellg()
// to report the file position. Some stream libraries have bugs in
// this case. This source file tests the severity of the eof
// conditions for a compiler.
//
// Severity levels are reported in terms of the extent of the
// work-around required:
//
// 0 - No bug exists.
// 1 - User must clear eof bit.
// 2 - User must clear eof bit and re-seek to end.
// 3 - User must clear eof bit and call _M_seek_return on the filebuf.
// 126 - Could not open sample input file.
// 127 - Unknown severity level.
//
// Severity level 3 is only known to exist for -LANG:std streams on
// the SGI MIPSpro 7.30 - 7.3.1.1 compiler versions. The cause of the
// bug is a code pattern like this:
//
// _M_in_error_mode = true;
// while(!_M_in_error_mode) { _M_in_error_mode = false; }
//
// It requires directly calling a non-public member function in the
// filebuf instance on the stream to escape the bad state.
// Unfortunately there is no way to detect the patch level of the
// compiler from the preprocessor, so we need to actually try the
// call.
#if defined(__sgi) && !defined(__GNUC__) && defined(_COMPILER_VERSION)
# if _COMPILER_VERSION == 730
# define VTK_SGI_730
# endif
#endif
#if defined(_MSC_VER)
# pragma warning (push, 1)
#endif
// Include the streams library. Hack access to SGI stream
// implementation for MIPSpro 7.3 compiler.
#if defined(VTK_SGI_730)
# define protected public
# define private public
#endif
#include <fstream>
using std::ifstream;
using std::ios;
#if defined(VTK_SGI_730)
# undef protected
# undef private
#endif
#if defined(_MSC_VER)
# pragma warning (pop)
#endif
int main()
{
const char* fname = "@VTK_TEST_STREAM_EOF_CXX@";
// Open the file.
#if defined(_WIN32)
ifstream fin(fname, ios::binary | ios::in);
#else
ifstream fin(fname, ios::in);
#endif
// Make sure we opened the file.
if(!fin)
{
return 126;
}
// Go to eof in a way that exposes the bug everywhere.
char c = 0;
fin.seekg(-1, ios::end);
while(fin.get(c));
// Clear the fail bit so tellg() is supposed to return something
// other than -1.
fin.clear(fin.rdstate() & ~ios::failbit);
if(fin.tellg() >= 0)
{
// Nothing is wrong with eof for this streams library.
return 0;
}
// Some streams return -1 from tellg() if eof is set.
fin.clear(fin.rdstate() & ~ios::failbit & ~ios::eofbit);
if(fin.tellg() >= 0)
{
return 1;
}
// Some streams still return -1 from tellg. Try seeking to get it
// out of this strange state.
fin.clear(fin.rdstate() & ~ios::failbit & ~ios::eofbit);
fin.seekg(0, ios::end);
if(fin.tellg() >= 0)
{
return 2;
}
// Only SGI 7.30 to 7.3.1.1 is known to get this far. Try to escape
// the bad state.
#if defined(VTK_SGI_730)
fin.clear(fin.rdstate() & ~ios::failbit & ~ios::eofbit);
fin.rdbuf()->_M_seek_return(0, 0);
if(fin.tellg() >= 0)
{
return 3;
}
#endif
return 127;
}
# Check the severity of EOF bugs in the streams library.
SET(VTK_TEST_STREAM_EOF_CXX ${VTK_CMAKE_DIR}/vtkTestStreamEOF.cxx.in)
CONFIGURE_FILE(${VTK_CMAKE_DIR}/vtkTestStreamEOF.cxx.in
${VTK_BINARY_DIR}/CMake/vtkTestStreamEOF.cxx @ONLY)
IF(NOT DEFINED VTK_ANSI_STREAM_EOF_RESULT)
MESSAGE(STATUS "Checking ANSI streams end-of-file bug level")
TRY_RUN(VTK_ANSI_STREAM_EOF_RESULT VTK_ANSI_STREAM_EOF_COMPILED
${VTK_BINARY_DIR}/CMakeTmp
${VTK_BINARY_DIR}/CMake/vtkTestStreamEOF.cxx)
IF(VTK_ANSI_STREAM_EOF_COMPILED)
MESSAGE(STATUS "Checking ANSI streams end-of-file bug level - ${VTK_ANSI_STREAM_EOF_RESULT}")
ELSE()
SET(VTK_ANSI_STREAM_EOF_RESULT 0)
MESSAGE(STATUS "Checking ANSI streams end-of-file bug level - failed to compile test")
ENDIF()
ENDIF()
SET(VTK_STREAM_EOF_SEVERITY ${VTK_ANSI_STREAM_EOF_RESULT})
......@@ -469,12 +469,6 @@ include(vtkTestExplicitInstantiation)
# Test for atomics and other compiler intrinsics
include(vtkTestBuiltins)
#-----------------------------------------------------------------------------
# Check the severity of EOF bugs in the streams library.
# this must be after the test for the long types
INCLUDE(vtkTestStreamsLibrary)
#-----------------------------------------------------------------------------
# Dispatch the build into the proper subdirectories.
SET(VTK_HAS_EXODUS 1)
......
......@@ -102,7 +102,6 @@
#cmakedefine VTK_NO_EXPLICIT_TEMPLATE_INSTANTIATION
#cmakedefine VTK_NO_FULL_TEMPLATE_SPECIALIZATION
#cmakedefine VTK_NO_ANSI_STRING_STREAM
#define VTK_STREAM_EOF_SEVERITY @VTK_STREAM_EOF_SEVERITY@
#cmakedefine VTK_HAVE_GETSOCKNAME_WITH_SOCKLEN_T
#cmakedefine VTK_HAVE_SO_REUSEADDR
......
......@@ -12,21 +12,6 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// Hack access to the fstream implementation if necessary. This is
// only needed on a few SGI MIPSpro compiler versions.
#if defined(__sgi) && !defined(__GNUC__) && defined(_COMPILER_VERSION)
# if _COMPILER_VERSION == 730
# include "vtkConfigure.h"
# if VTK_STREAM_EOF_SEVERITY == 3
# define protected public
# define private public
# include <fstream>
# undef private
# undef protected
# endif
# endif
#endif
#include "vtkXMLParser.h"
#include "vtkObjectFactory.h"
#include "vtk_expat.h"
......@@ -97,45 +82,7 @@ vtkTypeInt64 vtkXMLParser::TellG()
{
return -1;
}
#if VTK_STREAM_EOF_SEVERITY == 0
// No work-around required. Just return the position.
return this->Stream->tellg();
#else
std::streampos pos = this->Stream->tellg();
if(pos < 0)
{
// Clear the fail bit from failing tellg.
this->Stream->clear(this->Stream->rdstate() & ~ios::failbit);
// Save the eof bit.
int eof = this->Stream->eof()?1:0;
// Clear the eof bit.
if(eof)
{
this->Stream->clear(this->Stream->rdstate() & ~ios::eofbit);
}
# if VTK_STREAM_EOF_SEVERITY == 2
// Re-seek to the end to escape the buggy stream state.
this->Stream->seekg(0, ios::end);
# elif VTK_STREAM_EOF_SEVERITY == 3
// Call an internal filebuf method to escape the buggy stream
// state. This is a very ugly hack.
static_cast<ifstream*>(this->Stream)->rdbuf()->_M_seek_return(0,0);
# endif
// Call tellg to get the position.
pos = this->Stream->tellg();
// Restore the eof bit.
if(eof)
{
this->Stream->clear(this->Stream->rdstate() | ios::eofbit);
}
}
return pos;
#endif
}
//----------------------------------------------------------------------------
......@@ -146,40 +93,7 @@ void vtkXMLParser::SeekG(vtkTypeInt64 position)
{
return;
}
#if VTK_STREAM_EOF_SEVERITY == 0
// No work-around required. Just seek to the position.
this->Stream->seekg(std::streampos(position));
#else
// Save the eof bit.
int eof = this->Stream->eof()?1:0;
// Clear the eof bit.
if(eof)
{
this->Stream->clear(this->Stream->rdstate() & ~ios::eofbit);
}
# if VTK_STREAM_EOF_SEVERITY == 3
// Check if the stream is in the buggy state.
if(this->Stream->tellg() < 0)
{
// Call an internal filebuf method to escape the buggy stream
// state. This is a very ugly hack.
this->Stream->clear(this->Stream->rdstate() & ~ios::failbit);
this->Stream->clear(this->Stream->rdstate() & ~ios::eofbit);
static_cast<ifstream*>(this->Stream)->rdbuf()->_M_seek_return(0,0);
}
# endif
// Seek to the given position.
this->Stream->seekg(std::streampos(position));
// Restore the eof bit.
if(eof)
{
this->Stream->clear(this->Stream->rdstate() | ios::eofbit);
}
#endif
}
//----------------------------------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment