From 9c15ed1a2f1856a880e47ab4b395680c540cb312 Mon Sep 17 00:00:00 2001 From: Markus Blatt <mblatt@dune-project.org> Date: Tue, 22 Jan 2013 08:45:58 +0000 Subject: [PATCH] Fix FS#1041 and use Allocator::destroy instead of ~<type>() [[Imported from SVN: r1767]] --- dune/istl/bcrsmatrix.hh | 22 ++++++++++++---------- dune/istl/test/bcrsbuild.cc | 9 +++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/dune/istl/bcrsmatrix.hh b/dune/istl/bcrsmatrix.hh index 97f2a7faa..2f34d85db 100644 --- a/dune/istl/bcrsmatrix.hh +++ b/dune/istl/bcrsmatrix.hh @@ -549,9 +549,8 @@ namespace Dune { // reallocate the rows if required if (n>0 && n!=Mat.n) { // free rows - int i=n; - while (i) - r[--i].~row_type(); + for(row_type *riter=r+(n-1), *rend=r-1; riter!=rend; --riter) + rowAllocator_.destroy(riter); rowAllocator_.deallocate(r,n); } @@ -1342,8 +1341,8 @@ namespace Dune { // a,j have been allocated as one long vector j.reset(); int i=nnz; - while (i) - a[--i].~B(); + for(B *aiter=a+(nnz-1), *aend=a-1; aiter!=aend; --aiter) + allocator_.destroy(aiter); allocator_.deallocate(a,n); } else @@ -1353,9 +1352,9 @@ namespace Dune { if (r[i].getsize()>0) { int j=r[i].getsize(); - while (j) { - r[i].getindexptr()[--j].~size_type(); - r[i].getptr()[j].~B(); + for (B *col=r[i].getptr()+(r[i].getsize()-1), + *colend = r[i].getptr()-1; col!=colend; --col) { + allocator_.destroy(col); } sizeAllocator_.deallocate(r[i].getindexptr(),1); allocator_.deallocate(r[i].getptr(),1); @@ -1365,8 +1364,8 @@ namespace Dune { // deallocate the rows if (n>0 && deallocateRows) { int i=n; - while (i) - r[--i].~row_type(); + for(row_type *riter=r+(n-1), *rend=r-1; riter!=rend; --riter) + rowAllocator_.destroy(riter); rowAllocator_.deallocate(r,n); } @@ -1437,7 +1436,10 @@ namespace Dune { }else{ a = 0; j.reset(); + for(row_type* ri=r; ri!=r+rows; ++ri) + rowAllocator_.construct(ri, row_type()); } + // Mark the matrix as not built. ready = notbuilt; } diff --git a/dune/istl/test/bcrsbuild.cc b/dune/istl/test/bcrsbuild.cc index 03ad14407..e388d3277 100644 --- a/dune/istl/test/bcrsbuild.cc +++ b/dune/istl/test/bcrsbuild.cc @@ -79,11 +79,20 @@ struct Builder<Dune::BCRSMatrix<B,A> > } }; +void testDoubleSetSize() +{ + Dune::BCRSMatrix<Dune::FieldMatrix<double,1,1> > foo; + foo.setSize(5,5); + foo.setSize(5,5); +} + + int main() { try{ Builder<Dune::BCRSMatrix<Dune::FieldMatrix<double,1,1> > > builder; builder.randomBuild(5,4); + testDoubleSetSize(); }catch(Dune::Exception e) { std::cerr << e<<std::endl; return 1; -- GitLab