diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedListIO.C b/src/OpenFOAM/containers/Bits/PackedList/PackedListIO.C index 0e36d3aec171a8dd9b81259360498ee696458e1b..92f979ab4986cd8d90a145639478c6913c764785 100644 --- a/src/OpenFOAM/containers/Bits/PackedList/PackedListIO.C +++ b/src/OpenFOAM/containers/Bits/PackedList/PackedListIO.C @@ -119,6 +119,8 @@ Foam::Istream& Foam::PackedList<Width>::read(Istream& is) } else { + // NOTE: binary content should be independent of WM_LABEL_SIZE + if (len) { is.read diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C index 337736e54a4048a898e10372b851999b1b8d54de..851767a933a78140428514b615e6686e763e0bc1 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C @@ -223,7 +223,12 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, N>& list) { // Binary and contiguous - is.read(reinterpret_cast<char*>(list.data()), N*sizeof(T)); + Detail::readContiguous<T> + ( + is, + reinterpret_cast<char*>(list.data()), + N*sizeof(T) + ); is.fatalCheck ( diff --git a/src/OpenFOAM/containers/Lists/List/ListIO.C b/src/OpenFOAM/containers/Lists/List/ListIO.C index 696d90ad8ed067d2c662168afa108e21fcbf8598..ca2065e43e522575b5479856f156d516d7f10b22 100644 --- a/src/OpenFOAM/containers/Lists/List/ListIO.C +++ b/src/OpenFOAM/containers/Lists/List/ListIO.C @@ -126,7 +126,12 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& list) { // Non-empty, binary, contiguous - is.read(reinterpret_cast<char*>(list.data()), len*sizeof(T)); + Detail::readContiguous<T> + ( + is, + reinterpret_cast<char*>(list.data()), + len*sizeof(T) + ); is.fatalCheck ( diff --git a/src/OpenFOAM/containers/Lists/UList/UListIO.C b/src/OpenFOAM/containers/Lists/UList/UListIO.C index 1560032ff4d969d3fd363f16cb88e2308ec89beb..bc5b436bdea3776b9ceefdbb7a1ab14562730fe8 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListIO.C +++ b/src/OpenFOAM/containers/Lists/UList/UListIO.C @@ -259,7 +259,12 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& list) { // Non-empty, binary, contiguous - is.read(reinterpret_cast<char*>(list.data()), len*sizeof(T)); + Detail::readContiguous<T> + ( + is, + reinterpret_cast<char*>(list.data()), + len*sizeof(T) + ); is.fatalCheck ( diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H index c178447ab4792d667b6a41fc644ac8f9ed3dac5a..e158091fb398ba869d4cde37afae3ddb0d52c711 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H @@ -47,6 +47,7 @@ SourceFiles #include "IOstream.H" #include "token.H" +#include "contiguous.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -194,10 +195,50 @@ inline Istream& operator>>(Istream& is, IOstreamManip f) } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Detail +{ + //- Read binary block of contiguous data, possibly with conversion + template<class T> + void readContiguous(Istream& is, char* data, std::streamsize byteCount) + { + is.beginRawRead(); + + if (is_contiguous_label<T>::value) + { + readRawLabel + ( + is, + reinterpret_cast<label*>(data), + byteCount/sizeof(label) + ); + } + else if (is_contiguous_scalar<T>::value) + { + readRawScalar + ( + is, + reinterpret_cast<scalar*>(data), + byteCount/sizeof(scalar) + ); + } + else + { + is.readRaw(data, byteCount); + } + + is.endRawRead(); + } + +} // End namespace Detail + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository diff --git a/src/OpenFOAM/matrices/Matrix/MatrixIO.C b/src/OpenFOAM/matrices/Matrix/MatrixIO.C index 7f363acfe4a20e81eb7a5c3f3f95d2b8b6c3f06a..06fad30be4af66c79b859f9ea3b4db63cd7f0eec 100644 --- a/src/OpenFOAM/matrices/Matrix/MatrixIO.C +++ b/src/OpenFOAM/matrices/Matrix/MatrixIO.C @@ -112,7 +112,12 @@ bool Foam::Matrix<Form, Type>::readMatrix(Istream& is) { if (len) { - is.read(reinterpret_cast<char*>(v_), len*sizeof(Type)); + Detail::readContiguous<Type> + ( + is, + reinterpret_cast<char*>(v_), + len*sizeof(Type) + ); is.fatalCheck("readMatrix : reading the binary block"); } diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.C b/src/OpenFOAM/meshes/boundBox/boundBox.C index 63022fa85721745fdacf34bdf9702947924d626c..9d7d594e8d304d6b316c6d9478b8b55a2723b93b 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBox.C +++ b/src/OpenFOAM/meshes/boundBox/boundBox.C @@ -305,8 +305,9 @@ Foam::Istream& Foam::operator>>(Istream& is, boundBox& bb) } else { - is.read + Detail::readContiguous<boundBox> ( + is, reinterpret_cast<char*>(&bb.min_), sizeof(boundBox) ); diff --git a/src/OpenFOAM/meshes/meshShapes/labelledTri/labelledTriI.H b/src/OpenFOAM/meshes/meshShapes/labelledTri/labelledTriI.H index 75017a13bbe83f85f197df4e6c044d2630d3cb4e..cfeebd69fb1843f85b5bba6a235add7fbcb97b66 100644 --- a/src/OpenFOAM/meshes/meshShapes/labelledTri/labelledTriI.H +++ b/src/OpenFOAM/meshes/meshShapes/labelledTri/labelledTriI.H @@ -134,7 +134,12 @@ inline Foam::Istream& Foam::operator>>(Istream& is, labelledTri& t) } else { - is.read(reinterpret_cast<char*>(&t), sizeof(labelledTri)); + Detail::readContiguous<labelledTri> + ( + is, + reinterpret_cast<char*>(&t), + sizeof(labelledTri) + ); } is.check(FUNCTION_NAME); diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/refinementData.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/refinementData.C index 87472ce2fcc87bebeb4dd9d9fcdb2201be4692ae..d796f09367fd87ad68af1bbe2eedc695fd447e39 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/refinementData.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/refinementData.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | + \\ / A nd | Copyright (C) 2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011 OpenFOAM Foundation @@ -61,8 +61,9 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, Foam::refinementData& wDist) } else { - is.read + Detail::readContiguous<refinementData> ( + is, reinterpret_cast<char*>(&wDist.refinementCount_), sizeof(refinementData) ); diff --git a/src/meshTools/AABBTree/AABBTree.C b/src/meshTools/AABBTree/AABBTree.C index 4a5247460ec59fed353df31998c33e100438b2af..e2b15f77de0378d22bc9571b4fe4453896661def 100644 --- a/src/meshTools/AABBTree/AABBTree.C +++ b/src/meshTools/AABBTree/AABBTree.C @@ -495,22 +495,21 @@ Foam::Istream& Foam::operator>>(Istream& is, AABBTree<Type>& tree) if (is.format() == IOstream::ASCII) { is >> tree.maxLevel_ - >> tree.minLeafSize_ - >> tree.boundBoxes_ - >> tree.addressing_; + >> tree.minLeafSize_; } else { - is.read - ( - reinterpret_cast<char*>(&tree.maxLevel_), - sizeof(tree.maxLevel_) - + sizeof(tree.minLeafSize_) - ); - is >> tree.boundBoxes_ - >> tree.addressing_; + is.beginRawRead(); + + readRawLabel(is, &tree.maxLevel_); + readRawLabel(is, &tree.minLeafSize_); + + is.endRawRead(); } + is >> tree.boundBoxes_ + >> tree.addressing_; + is.check(FUNCTION_NAME); return is; }