From c2f8c8b74b069571d8b616db7d5c7e708e39fbf8 Mon Sep 17 00:00:00 2001 From: paolo Date: Fri, 15 Oct 2004 10:54:57 +0000 Subject: [PATCH] 2004-10-15 Paolo Carlini * include/ext/bitmap_allocator.h: Qualify ::operator delete. * src/bitmap_allocator.cc: Likewise. * src/mt_allocator.cc: Use ::operator delete, not delete, consistently with ::operator new. * include/ext/bitmap_allocator.h (deallocate): Check for null pointer. * testsuite/ext/bitmap_allocator/check_deallocate_null.cc: New. * testsuite/testsuite_allocator.h (check_deallocate_null): Add test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@89089 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 12 +++++++++ libstdc++-v3/include/ext/bitmap_allocator.h | 15 ++++++----- libstdc++-v3/src/bitmap_allocator.cc | 2 +- libstdc++-v3/src/mt_allocator.cc | 20 +++++++------- .../ext/bitmap_allocator/check_deallocate_null.cc | 31 ++++++++++++++++++++++ libstdc++-v3/testsuite/testsuite_allocator.h | 1 + 6 files changed, 64 insertions(+), 17 deletions(-) create mode 100644 libstdc++-v3/testsuite/ext/bitmap_allocator/check_deallocate_null.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index d5bdab551b0..7819e9e679a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,15 @@ +2004-10-15 Paolo Carlini + + * include/ext/bitmap_allocator.h: Qualify ::operator delete. + * src/bitmap_allocator.cc: Likewise. + * src/mt_allocator.cc: Use ::operator delete, not delete, + consistently with ::operator new. + + * include/ext/bitmap_allocator.h (deallocate): Check for null + pointer. + * testsuite/ext/bitmap_allocator/check_deallocate_null.cc: New. + * testsuite/testsuite_allocator.h (check_deallocate_null): Add test. + 2004-10-14 Benjamin Kosnik * include/ext/mt_allocator.h (__mt_alloc::deallocate): Check for diff --git a/libstdc++-v3/include/ext/bitmap_allocator.h b/libstdc++-v3/include/ext/bitmap_allocator.h index dfb7cba1871..2328e145c95 100644 --- a/libstdc++-v3/include/ext/bitmap_allocator.h +++ b/libstdc++-v3/include/ext/bitmap_allocator.h @@ -674,14 +674,14 @@ namespace __gnu_cxx // Ok, the new block is greater than or equal to the // last block in the list of free blocks. We just free // the new block. - operator delete(static_cast(__addr)); + ::operator delete(static_cast(__addr)); return; } else { // Deallocate the last block in the list of free lists, // and insert the new one in it's correct position. - operator delete(static_cast(_S_free_list.back())); + ::operator delete(static_cast(_S_free_list.back())); _S_free_list.pop_back(); } } @@ -1095,10 +1095,13 @@ namespace __gnu_cxx void deallocate(pointer __p, size_type __n) throw() { - if (__builtin_expect(__n == 1, true)) - this->_M_deallocate_single_object(__p); - else - ::operator delete(__p); + if (__builtin_expect(__p != 0, true)) + { + if (__builtin_expect(__n == 1, true)) + this->_M_deallocate_single_object(__p); + else + ::operator delete(__p); + } } pointer diff --git a/libstdc++-v3/src/bitmap_allocator.cc b/libstdc++-v3/src/bitmap_allocator.cc index f37c5dca28b..3cd0fb90e3f 100644 --- a/libstdc++-v3/src/bitmap_allocator.cc +++ b/libstdc++-v3/src/bitmap_allocator.cc @@ -121,7 +121,7 @@ namespace __gnu_cxx iterator __iter = _S_free_list.begin(); while (__iter != _S_free_list.end()) { - operator delete((void*)*__iter); + ::operator delete((void*)*__iter); ++__iter; } _S_free_list.clear(); diff --git a/libstdc++-v3/src/mt_allocator.cc b/libstdc++-v3/src/mt_allocator.cc index 7dff273ba12..08f5c87c0dd 100644 --- a/libstdc++-v3/src/mt_allocator.cc +++ b/libstdc++-v3/src/mt_allocator.cc @@ -61,10 +61,10 @@ namespace __gnu_cxx delete __bin._M_address; __bin._M_address = __tmp; } - delete __bin._M_first; + ::operator delete(__bin._M_first); } - delete _M_bin; - delete _M_binmap; + ::operator delete(_M_bin); + ::operator delete(_M_binmap); } } @@ -190,10 +190,10 @@ namespace __gnu_cxx delete __bin._M_address; __bin._M_address = __tmp; } - delete __bin._M_first; - delete __bin._M_free; - delete __bin._M_used; - delete __bin._M_mutex; + ::operator delete(__bin._M_first); + ::operator delete(__bin._M_free); + ::operator delete(__bin._M_used); + ::operator delete(__bin._M_mutex); } ::operator delete(_M_thread_freelist_initial); } @@ -209,11 +209,11 @@ namespace __gnu_cxx delete __bin._M_address; __bin._M_address = __tmp; } - delete __bin._M_first; + ::operator delete(__bin._M_first); } } - delete _M_bin; - delete _M_binmap; + ::operator delete(_M_bin); + ::operator delete(_M_binmap); } } diff --git a/libstdc++-v3/testsuite/ext/bitmap_allocator/check_deallocate_null.cc b/libstdc++-v3/testsuite/ext/bitmap_allocator/check_deallocate_null.cc new file mode 100644 index 00000000000..ebe8114793b --- /dev/null +++ b/libstdc++-v3/testsuite/ext/bitmap_allocator/check_deallocate_null.cc @@ -0,0 +1,31 @@ +// +// Copyright (C) 2004 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 20.4.1.1 allocator members + +#include +#include + +int main() +{ + typedef int value_type; + typedef __gnu_cxx::bitmap_allocator allocator_type; + __gnu_test::check_deallocate_null(); + return 0; +} diff --git a/libstdc++-v3/testsuite/testsuite_allocator.h b/libstdc++-v3/testsuite/testsuite_allocator.h index ecb210e1fde..c10be5315d9 100644 --- a/libstdc++-v3/testsuite/testsuite_allocator.h +++ b/libstdc++-v3/testsuite/testsuite_allocator.h @@ -202,6 +202,7 @@ namespace __gnu_test { // Let's not core here... Alloc a; + a.deallocate(NULL, 1); a.deallocate(NULL, 10); } }; // namespace __gnu_test -- 2.11.0