From 9e8966483f6cf6364dcdbaa955fbc7e258dcc59d Mon Sep 17 00:00:00 2001 From: Danial Khazaei Date: Mon, 8 Jul 2019 19:08:47 +0430 Subject: [PATCH 1/5] [bugfix]: writing to an object with no trivial copy-assignment [wclass-memaccess]. --- .../constraint/processor/ProcessorPointPatchField.C | 2 +- .../processorLduInterface/processorLduInterfaceTemplates.C | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/foam/fields/PointPatchFieldTemplates/constraint/processor/ProcessorPointPatchField.C b/src/foam/fields/PointPatchFieldTemplates/constraint/processor/ProcessorPointPatchField.C index 603211464..346951975 100644 --- a/src/foam/fields/PointPatchFieldTemplates/constraint/processor/ProcessorPointPatchField.C +++ b/src/foam/fields/PointPatchFieldTemplates/constraint/processor/ProcessorPointPatchField.C @@ -170,7 +170,7 @@ receivePointField outstandingSendRequest_ = -1; outstandingRecvRequest_ = -1; - memcpy(tf().begin(), receiveBuf_.begin(), tf().byteSize()); + memcpy(static_cast(tf().begin()), receiveBuf_.begin(), tf().byteSize()); } else { diff --git a/src/foam/matrices/lduMatrix/lduAddressing/lduInterfaces/processorLduInterface/processorLduInterfaceTemplates.C b/src/foam/matrices/lduMatrix/lduAddressing/lduInterfaces/processorLduInterface/processorLduInterfaceTemplates.C index 9cc74ee76..1896b1056 100644 --- a/src/foam/matrices/lduMatrix/lduAddressing/lduInterfaces/processorLduInterface/processorLduInterfaceTemplates.C +++ b/src/foam/matrices/lduMatrix/lduAddressing/lduInterfaces/processorLduInterface/processorLduInterfaceTemplates.C @@ -107,7 +107,7 @@ void Foam::processorLduInterface::receive } else if (commsType == Pstream::nonBlocking) { - memcpy(f.begin(), receiveBuf_.begin(), f.byteSize()); + memcpy(static_cast(f.begin()), receiveBuf_.begin(), f.byteSize()); } else { From 69192ae1f4f1bf0874c0b27de2eb9f1f9278235b Mon Sep 17 00:00:00 2001 From: Danial Khazaei Date: Mon, 8 Jul 2019 19:13:27 +0430 Subject: [PATCH 2/5] [port]: re-write List container to suppress [-Walloc-size-larger-than=]. - Changes are ported from OpenFOAM-dev project. --- src/foam/containers/Lists/List/List.C | 114 ++++++------------------- src/foam/containers/Lists/List/List.H | 23 ++++- src/foam/containers/Lists/List/ListI.H | 75 ++++++++++++++++ 3 files changed, 121 insertions(+), 91 deletions(-) diff --git a/src/foam/containers/Lists/List/List.C b/src/foam/containers/Lists/List/List.C index 5c1d5a256..fd5efb256 100644 --- a/src/foam/containers/Lists/List/List.C +++ b/src/foam/containers/Lists/List/List.C @@ -50,15 +50,12 @@ Foam::List::List(const label s) { if (this->size_ < 0) { - FatalErrorIn("List::List(const label size)") + FatalErrorInFunction << "bad size " << this->size_ << abort(FatalError); } - if (this->size_) - { - this->v_ = new T[this->size_]; - } + alloc(); } @@ -70,15 +67,15 @@ Foam::List::List(const label s, const T& a) { if (this->size_ < 0) { - FatalErrorIn("List::List(const label size, const T&)") + FatalErrorInFunction << "bad size " << this->size_ << abort(FatalError); } + alloc(); + if (this->size_) { - this->v_ = new T[this->size_]; - List_ACCESS(T, (*this), vp); List_FOR_ALL((*this), i) List_ELEM((*this), vp, i) = a; @@ -95,15 +92,15 @@ Foam::List::List(const List& a) { if (this->size_) { - this->v_ = new T[this->size_]; + alloc(); -# ifdef USEMEMCPY + #ifdef USEMEMCPY if (contiguous()) { memcpy(this->v_, a.v_, this->byteSize()); } else -# endif + #endif { List_ACCESS(T, (*this), vp); List_CONST_ACCESS(T, a, ap); @@ -125,11 +122,11 @@ Foam::List::List(const Xfer< List >& lst) // Construct as copy or re-use as specified. template -Foam::List::List(List& a, bool reUse) +Foam::List::List(List& a, bool reuse) : UList(nullptr, a.size_) { - if (reUse) + if (reuse) { this->v_ = a.v_; a.v_ = 0; @@ -137,15 +134,15 @@ Foam::List::List(List& a, bool reUse) } else if (this->size_) { - this->v_ = new T[this->size_]; + alloc(); -# ifdef USEMEMCPY + #ifdef USEMEMCPY if (contiguous()) { memcpy(this->v_, a.v_, this->byteSize()); } else -# endif + #endif { List_ACCESS(T, (*this), vp); List_CONST_ACCESS(T, a, ap); @@ -167,11 +164,11 @@ Foam::List::List(const UList& a, const unallocLabelList& map) { // Note:cannot use List_ELEM since third argument has to be index. - this->v_ = new T[this->size_]; + alloc(); forAll(*this, i) { - this->v_[i] = a[map[i]]; + this->operator[](i) = a[map[i]]; } } } @@ -181,32 +178,9 @@ Foam::List::List(const UList& a, const unallocLabelList& map) template template Foam::List::List(InputIterator first, InputIterator last) -{ - label s = 0; - for - ( - InputIterator iter = first; - iter != last; - ++iter - ) - { - s++; - } - - setSize(s); - - s = 0; - - for - ( - InputIterator iter = first; - iter != last; - ++iter - ) - { - this->operator[](s++) = iter(); - } -} +: + List(first, last, std::distance(first, last)) +{} // Construct as copy of FixedList @@ -216,15 +190,7 @@ Foam::List::List(const FixedList& lst) : UList(nullptr, Size) { - if (this->size_) - { - this->v_ = new T[this->size_]; - - forAll(*this, i) - { - this->operator[](i) = lst[i]; - } - } + allocCopyList(lst); } @@ -234,15 +200,7 @@ Foam::List::List(const PtrList& lst) : UList(nullptr, lst.size()) { - if (this->size_) - { - this->v_ = new T[this->size_]; - - forAll(*this, i) - { - this->operator[](i) = lst[i]; - } - } + allocCopyList(lst); } @@ -254,7 +212,7 @@ Foam::List::List(const SLList& lst) { if (this->size_) { - this->v_ = new T[this->size_]; + alloc(); label i = 0; for @@ -276,15 +234,7 @@ Foam::List::List(const IndirectList& lst) : UList(nullptr, lst.size()) { - if (this->size_) - { - this->v_ = new T[this->size_]; - - forAll(*this, i) - { - this->operator[](i) = lst[i]; - } - } + allocCopyList(lst); } @@ -294,15 +244,7 @@ Foam::List::List(const UIndirectList& lst) : UList(nullptr, lst.size()) { - if (this->size_) - { - this->v_ = new T[this->size_]; - - forAll(*this, i) - { - this->operator[](i) = lst[i]; - } - } + allocCopyList(lst); } @@ -312,15 +254,7 @@ Foam::List::List(const BiIndirectList& lst) : UList(nullptr, lst.size()) { - if (this->size_) - { - this->v_ = new T[this->size_]; - - forAll(*this, i) - { - this->operator[](i) = lst[i]; - } - } + allocCopyList(lst); } diff --git a/src/foam/containers/Lists/List/List.H b/src/foam/containers/Lists/List/List.H index ec667b2a8..2a37e5c35 100644 --- a/src/foam/containers/Lists/List/List.H +++ b/src/foam/containers/Lists/List/List.H @@ -80,6 +80,27 @@ class List public UList { + // Private member functions + + //- Allocate list storage + inline void alloc(); + + //- Reallocate list storage to the given size + inline void reAlloc(const label s); + + //- Copy list of given type + template + inline void copyList(const List2&); + + //- Allocate storage and copy list of given type + template + inline void allocCopyList(const List2&); + + //- Construct given start and end iterators and number of elements + template + inline List(InputIterator first, InputIterator last, const label s); + + protected: //- Override size to be inconsistent with allocated storage. @@ -118,7 +139,7 @@ public: List(const Xfer< List >&); //- Construct as copy or re-use as specified. - List(List&, bool reUse); + List(List&, bool reuse); //- Construct as subset. List(const UList&, const unallocLabelList& mapAddressing); diff --git a/src/foam/containers/Lists/List/ListI.H b/src/foam/containers/Lists/List/ListI.H index 74c501891..05bacc9d0 100644 --- a/src/foam/containers/Lists/List/ListI.H +++ b/src/foam/containers/Lists/List/ListI.H @@ -23,6 +23,81 @@ License \*---------------------------------------------------------------------------*/ +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +inline void Foam::List::alloc() +{ + if (this->size_ > 0) + { + this->v_ = new T[this->size_]; + } +} + + +template +inline void Foam::List::reAlloc(const label s) +{ + if (this->size_ != s) + { + clear(); + this->size_ = s; + alloc(); + } +} + + +template +template +inline void Foam::List::copyList(const List2& lst) +{ + if (this->size_) + { + forAll(*this, i) + { + this->operator[](i) = lst[i]; + } + } +} + + +template +template +inline void Foam::List::allocCopyList(const List2& lst) +{ + if (this->size_) + { + alloc(); + copyList(lst); + } +} + + +template +template +inline Foam::List::List +( + InputIterator first, + InputIterator last, + const label s +) +: + UList(nullptr, s) +{ + if (this->size_) + { + alloc(); + + InputIterator iter = first; + forAll(*this, i) + { + this->operator[](i) = *iter; + ++iter; + } + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template From 314069356ed6d387e0283567bd46bf804d1dcaa5 Mon Sep 17 00:00:00 2001 From: Danial Khazaei Date: Mon, 8 Jul 2019 19:34:33 +0430 Subject: [PATCH 3/5] [port]: disabled flex++ warnings during foam compile. --- wmake/rules/General/flex++ | 4 ++-- wmake/rules/SiCortex64Gcc/c++ | 3 +++ wmake/rules/SunOS64Gcc/c++ | 3 +++ wmake/rules/linux64Gcc/c++ | 3 +++ wmake/rules/linux64Icc/c++ | 3 +++ wmake/rules/linuxARM7Gcc/c++ | 3 +++ wmake/rules/linuxARM8Arm/c++ | 3 +++ wmake/rules/linuxARM8Gcc/c++ | 3 +++ wmake/rules/linuxGcc/c++ | 3 +++ wmake/rules/linuxIA64Gcc/c++ | 3 +++ wmake/rules/linuxIA64I64/c++ | 3 +++ wmake/rules/linuxIA64Icc/c++ | 3 +++ wmake/rules/linuxIcc/c++ | 3 +++ wmake/rules/linuxPPC64Gcc/c++ | 3 +++ wmake/rules/mingwGcc/c++ | 3 +++ wmake/rules/solarisGcc/c++ | 3 +++ 16 files changed, 47 insertions(+), 2 deletions(-) diff --git a/wmake/rules/General/flex++ b/wmake/rules/General/flex++ index 9af740a96..aabf584fb 100644 --- a/wmake/rules/General/flex++ +++ b/wmake/rules/General/flex++ @@ -2,8 +2,8 @@ # For older versions of flex, the option --c++ is not avaliable # Switching to flex++ is an alternative -#Ltoo = flex++ -f $$SOURCE ; mv lex.yy.cc $*.C ; $(CC) $(c++FLAGS) -c $*.C -o $@ -Ltoo = flex -+ -f $$SOURCE ; mv lex.yy.cc $*.C ; $(CC) $(c++FLAGS) -c $*.C -o $@ +#Ltoo = flex++ -f $$SOURCE ; mv lex.yy.cc $*.C ; $(CC) $(c++FLAGS) $(c++LESSWARN) -c $*.C -o $@ +Ltoo = flex -+ -f $$SOURCE ; mv lex.yy.cc $*.C ; $(CC) $(c++FLAGS) $(c++LESSWARN) -c $*.C -o $@ .L.dep: $(MAKE_DEP) diff --git a/wmake/rules/SiCortex64Gcc/c++ b/wmake/rules/SiCortex64Gcc/c++ index dafa8f5c3..04ce02186 100644 --- a/wmake/rules/SiCortex64Gcc/c++ +++ b/wmake/rules/SiCortex64Gcc/c++ @@ -2,6 +2,9 @@ c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast +# Suppress some warnings for flex++ and CGAL +c++LESSWARN = -Wno-old-style-cast -Wno-unused-local-typedefs -Wno-array-bounds + CC = g++ -mabi=64 #CC = scg++ -mabi=64 diff --git a/wmake/rules/SunOS64Gcc/c++ b/wmake/rules/SunOS64Gcc/c++ index 936a030ee..046f21c1e 100644 --- a/wmake/rules/SunOS64Gcc/c++ +++ b/wmake/rules/SunOS64Gcc/c++ @@ -2,6 +2,9 @@ c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast +# Suppress some warnings for flex++ and CGAL +c++LESSWARN = -Wno-old-style-cast -Wno-unused-local-typedefs -Wno-array-bounds + CC = g++ -m64 include $(RULES)/c++$(WM_COMPILE_OPTION) diff --git a/wmake/rules/linux64Gcc/c++ b/wmake/rules/linux64Gcc/c++ index 2f00832b7..19e6f87ce 100644 --- a/wmake/rules/linux64Gcc/c++ +++ b/wmake/rules/linux64Gcc/c++ @@ -2,6 +2,9 @@ c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor +# Suppress some warnings for flex++ and CGAL +c++LESSWARN = -Wno-old-style-cast -Wno-unused-local-typedefs -Wno-array-bounds + CC = g++ -std=c++11 -m64 include $(RULES)/c++$(WM_COMPILE_OPTION) diff --git a/wmake/rules/linux64Icc/c++ b/wmake/rules/linux64Icc/c++ index c8b3d7ca9..7f5906d90 100644 --- a/wmake/rules/linux64Icc/c++ +++ b/wmake/rules/linux64Icc/c++ @@ -2,6 +2,9 @@ c++WARN = -wd327,584,654,819,1125,1476,1505,1572 +# Suppress some warnings for flex++ and CGAL +c++LESSWARN = -diag-disable 1224,2026,2305 + CC = icpc -DIntel include $(RULES)/c++$(WM_COMPILE_OPTION) diff --git a/wmake/rules/linuxARM7Gcc/c++ b/wmake/rules/linuxARM7Gcc/c++ index f1f70ab80..381a65c60 100644 --- a/wmake/rules/linuxARM7Gcc/c++ +++ b/wmake/rules/linuxARM7Gcc/c++ @@ -2,6 +2,9 @@ c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast +# Suppress some warnings for flex++ and CGAL +c++LESSWARN = -Wno-old-style-cast -Wno-unused-local-typedefs -Wno-array-bounds + CC = g++ -std=c++11 include $(RULES)/c++$(WM_COMPILE_OPTION) diff --git a/wmake/rules/linuxARM8Arm/c++ b/wmake/rules/linuxARM8Arm/c++ index fe83a320f..6333d9a4f 100644 --- a/wmake/rules/linuxARM8Arm/c++ +++ b/wmake/rules/linuxARM8Arm/c++ @@ -2,6 +2,9 @@ c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wno-undefined-var-template -Wno-deprecated-register -Wno-overloaded-virtual -Wno-null-dereference +# Suppress some warnings for flex++ and CGAL +c++LESSWARN = -Wno-old-style-cast -Wno-unused-local-typedefs -Wno-array-bounds + CC = armclang++ -std=c++11 -DARM_CLANG include $(RULES)/c++$(WM_COMPILE_OPTION) diff --git a/wmake/rules/linuxARM8Gcc/c++ b/wmake/rules/linuxARM8Gcc/c++ index f1f70ab80..381a65c60 100644 --- a/wmake/rules/linuxARM8Gcc/c++ +++ b/wmake/rules/linuxARM8Gcc/c++ @@ -2,6 +2,9 @@ c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast +# Suppress some warnings for flex++ and CGAL +c++LESSWARN = -Wno-old-style-cast -Wno-unused-local-typedefs -Wno-array-bounds + CC = g++ -std=c++11 include $(RULES)/c++$(WM_COMPILE_OPTION) diff --git a/wmake/rules/linuxGcc/c++ b/wmake/rules/linuxGcc/c++ index 9a972c577..f0ee56ac1 100644 --- a/wmake/rules/linuxGcc/c++ +++ b/wmake/rules/linuxGcc/c++ @@ -2,6 +2,9 @@ c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast +# Suppress some warnings for flex++ and CGAL +c++LESSWARN = -Wno-old-style-cast -Wno-unused-local-typedefs -Wno-array-bounds + CC = g++ -std=c++11 -m32 include $(RULES)/c++$(WM_COMPILE_OPTION) diff --git a/wmake/rules/linuxIA64Gcc/c++ b/wmake/rules/linuxIA64Gcc/c++ index eaf8972e1..bf274ffba 100644 --- a/wmake/rules/linuxIA64Gcc/c++ +++ b/wmake/rules/linuxIA64Gcc/c++ @@ -2,6 +2,9 @@ c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast +# Suppress some warnings for flex++ and CGAL +c++LESSWARN = -Wno-old-style-cast -Wno-unused-local-typedefs -Wno-array-bounds + CC = g++ -std=c++11 include $(RULES)/c++$(WM_COMPILE_OPTION) diff --git a/wmake/rules/linuxIA64I64/c++ b/wmake/rules/linuxIA64I64/c++ index a5a65d79d..269630818 100644 --- a/wmake/rules/linuxIA64I64/c++ +++ b/wmake/rules/linuxIA64I64/c++ @@ -2,6 +2,9 @@ c++WARN = -wd654,819,1125,1476,1505,1572 +# Suppress some warnings for flex++ and CGAL +c++LESSWARN = -diag-disable 1224,2026,2305 + CC = icpc -DIntel include $(RULES)/c++$(WM_COMPILE_OPTION) diff --git a/wmake/rules/linuxIA64Icc/c++ b/wmake/rules/linuxIA64Icc/c++ index 625cbd186..8b1afeeb0 100644 --- a/wmake/rules/linuxIA64Icc/c++ +++ b/wmake/rules/linuxIA64Icc/c++ @@ -2,6 +2,9 @@ c++WARN = -wd327,654,819,1125,1476,1505,1572 +# Suppress some warnings for flex++ and CGAL +c++LESSWARN = -diag-disable 1224,2026,2305 + CC = icpc include $(RULES)/c++$(WM_COMPILE_OPTION) diff --git a/wmake/rules/linuxIcc/c++ b/wmake/rules/linuxIcc/c++ index 8a3abc689..7dbc865df 100644 --- a/wmake/rules/linuxIcc/c++ +++ b/wmake/rules/linuxIcc/c++ @@ -2,6 +2,9 @@ c++WARN = -wd654 -wd1125 -vec-report0 +# Suppress some warnings for flex++ and CGAL +c++LESSWARN = -diag-disable 1224,2026,2305 + CC = icpc -DIntel include $(RULES)/c++$(WM_COMPILE_OPTION) diff --git a/wmake/rules/linuxPPC64Gcc/c++ b/wmake/rules/linuxPPC64Gcc/c++ index d8af9b25f..ed213f57e 100644 --- a/wmake/rules/linuxPPC64Gcc/c++ +++ b/wmake/rules/linuxPPC64Gcc/c++ @@ -2,6 +2,9 @@ c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast +# Suppress some warnings for flex++ and CGAL +c++LESSWARN = -Wno-old-style-cast -Wno-unused-local-typedefs -Wno-array-bounds + CC = g++ -std=c++11 -m64 -mcpu=power5+ include $(RULES)/c++$(WM_COMPILE_OPTION) diff --git a/wmake/rules/mingwGcc/c++ b/wmake/rules/mingwGcc/c++ index a4c0fdfc2..fd754a354 100644 --- a/wmake/rules/mingwGcc/c++ +++ b/wmake/rules/mingwGcc/c++ @@ -2,6 +2,9 @@ c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor +# Suppress some warnings for flex++ and CGAL +c++LESSWARN = -Wno-old-style-cast -Wno-unused-local-typedefs -Wno-array-bounds + CC = g++ -std=c++11 include $(RULES)/c++$(WM_COMPILE_OPTION) diff --git a/wmake/rules/solarisGcc/c++ b/wmake/rules/solarisGcc/c++ index 56edcd7a8..c790448d3 100644 --- a/wmake/rules/solarisGcc/c++ +++ b/wmake/rules/solarisGcc/c++ @@ -2,6 +2,9 @@ c++WARN = -Wall -Wextra -Wno-unused-parameter +# Suppress some warnings for flex++ and CGAL +c++LESSWARN = + CC = g++ -std=c++11 include $(RULES)/c++$(WM_COMPILE_OPTION) From 4e8d74617bfa3eea92a4a888fa382531a08ae8fa Mon Sep 17 00:00:00 2001 From: Danial Khazaei Date: Mon, 8 Jul 2019 19:36:38 +0430 Subject: [PATCH 4/5] [bugfix]: corrected APPBIN path for RichardsFoam solver. --- applications/solvers/incompressible/RichardsFoam/Make/files | 2 +- .../RichardsFoam/spatialMeanValueRichardsonFoam/Make/files | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/solvers/incompressible/RichardsFoam/Make/files b/applications/solvers/incompressible/RichardsFoam/Make/files index f2b8d52a1..6d64d17d5 100755 --- a/applications/solvers/incompressible/RichardsFoam/Make/files +++ b/applications/solvers/incompressible/RichardsFoam/Make/files @@ -1,3 +1,3 @@ RichardsFoam.C -EXE = $(FOAM_USER_APPBIN)/RichardsFoam +EXE = $(FOAM_APPBIN)/RichardsFoam diff --git a/applications/solvers/incompressible/RichardsFoam/spatialMeanValueRichardsonFoam/Make/files b/applications/solvers/incompressible/RichardsFoam/spatialMeanValueRichardsonFoam/Make/files index 32c9117fd..c352bdb19 100755 --- a/applications/solvers/incompressible/RichardsFoam/spatialMeanValueRichardsonFoam/Make/files +++ b/applications/solvers/incompressible/RichardsFoam/spatialMeanValueRichardsonFoam/Make/files @@ -1,3 +1,3 @@ spatialMeanValueRichardsonFoam.C -EXE = $(FOAM_USER_APPBIN)/spatialMeanValueRichardsonFoam +EXE = $(FOAM_APPBIN)/spatialMeanValueRichardsonFoam From 9e401eedca3b365612eca744571438d4a89f18d0 Mon Sep 17 00:00:00 2001 From: Danial Khazaei Date: Mon, 8 Jul 2019 21:10:15 +0430 Subject: [PATCH 5/5] [port]: completed List container implementation with new functions. --- src/foam/containers/Lists/List/List.C | 80 ++++++-------------------- src/foam/containers/Lists/List/List.H | 4 +- src/foam/containers/Lists/List/ListI.H | 16 +++++- 3 files changed, 32 insertions(+), 68 deletions(-) diff --git a/src/foam/containers/Lists/List/List.C b/src/foam/containers/Lists/List/List.C index fd5efb256..47f3aa4de 100644 --- a/src/foam/containers/Lists/List/List.C +++ b/src/foam/containers/Lists/List/List.C @@ -264,7 +264,10 @@ Foam::List::List(const BiIndirectList& lst) template Foam::List::~List() { - if (this->v_) delete[] this->v_; + if (this->v_) + { + delete[] this->v_; + } } @@ -275,7 +278,7 @@ void Foam::List::setSize(const label newSize) { if (newSize < 0) { - FatalErrorIn("List::setSize(const label)") + FatalErrorInFunction << "bad set size " << newSize << abort(FatalError); } @@ -303,8 +306,8 @@ void Foam::List::setSize(const label newSize) while (i--) *--av = *--vv; } } - if (this->v_) delete[] this->v_; + clear(); this->size_ = newSize; this->v_ = nv; } @@ -331,21 +334,12 @@ void Foam::List::setSize(const label newSize, const T& a) } -template -void Foam::List::clear() -{ - if (this->v_) delete[] this->v_; - this->size_ = 0; - this->v_ = 0; -} - - // Transfer the contents of the argument List into this List // and anull the argument list template void Foam::List::transfer(List& a) { - if (this->v_) delete[] this->v_; + clear(); this->size_ = a.size_; this->v_ = a.v_; @@ -384,13 +378,7 @@ void Foam::List::transfer(SortableList& a) template void Foam::List::operator=(const UList& a) { - if (a.size_ != this->size_) - { - if (this->v_) delete[] this->v_; - this->v_ = 0; - this->size_ = a.size_; - if (this->size_) this->v_ = new T[this->size_]; - } + reAlloc(a.size_); if (this->size_) { @@ -418,7 +406,7 @@ void Foam::List::operator=(const List& a) { if (this == &a) { - FatalErrorIn("List::operator=(const List&)") + FatalErrorInFunction << "attempted assignment to self" << abort(FatalError); } @@ -431,13 +419,7 @@ void Foam::List::operator=(const List& a) template void Foam::List::operator=(const SLList& lst) { - if (lst.size() != this->size_) - { - if (this->v_) delete[] this->v_; - this->v_ = 0; - this->size_ = lst.size(); - if (this->size_) this->v_ = new T[this->size_]; - } + reAlloc(lst.size()); if (this->size_) { @@ -459,18 +441,8 @@ void Foam::List::operator=(const SLList& lst) template void Foam::List::operator=(const IndirectList& lst) { - if (lst.size() != this->size_) - { - if (this->v_) delete[] this->v_; - this->v_ = 0; - this->size_ = lst.size(); - if (this->size_) this->v_ = new T[this->size_]; - } - - forAll(*this, i) - { - this->operator[](i) = lst[i]; - } + reAlloc(lst.size()); + copyList(lst); } @@ -478,18 +450,8 @@ void Foam::List::operator=(const IndirectList& lst) template void Foam::List::operator=(const UIndirectList& lst) { - if (lst.size() != this->size_) - { - if (this->v_) delete[] this->v_; - this->v_ = 0; - this->size_ = lst.size(); - if (this->size_) this->v_ = new T[this->size_]; - } - - forAll(*this, i) - { - this->operator[](i) = lst[i]; - } + reAlloc(lst.size()); + copyList(lst); } @@ -497,18 +459,8 @@ void Foam::List::operator=(const UIndirectList& lst) template void Foam::List::operator=(const BiIndirectList& lst) { - if (lst.size() != this->size_) - { - if (this->v_) delete[] this->v_; - this->v_ = 0; - this->size_ = lst.size(); - if (this->size_) this->v_ = new T[this->size_]; - } - - forAll(*this, i) - { - this->operator[](i) = lst[i]; - } + reAlloc(lst.size()); + copyList(lst); } // * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * // diff --git a/src/foam/containers/Lists/List/List.H b/src/foam/containers/Lists/List/List.H index 2a37e5c35..67ba73ff7 100644 --- a/src/foam/containers/Lists/List/List.H +++ b/src/foam/containers/Lists/List/List.H @@ -205,8 +205,8 @@ public: //- Reset size of List and value for new elements. void setSize(const label, const T&); - //- Clear the list, i.e. set size to zero. - void clear(); + //- Clear the list, i.e. set size to zero + inline void clear(); //- Append an element at the end of the list inline void append(const T&); diff --git a/src/foam/containers/Lists/List/ListI.H b/src/foam/containers/Lists/List/ListI.H index 05bacc9d0..c4d827bcf 100644 --- a/src/foam/containers/Lists/List/ListI.H +++ b/src/foam/containers/Lists/List/ListI.H @@ -91,8 +91,7 @@ inline Foam::List::List InputIterator iter = first; forAll(*this, i) { - this->operator[](i) = *iter; - ++iter; + this->operator[](i) = *iter++; } } } @@ -121,6 +120,19 @@ inline const Foam::List& Foam::List::null() } +template +inline void Foam::List::clear() +{ + if (this->v_) + { + delete[] this->v_; + this->v_ = 0; + } + + this->size_ = 0; +} + + template inline void Foam::List::resize(const label newSize) {