This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] Minor tweaks to mt/bitmap allocators


Hi,

tested x86-linux, committed to mainline.

Paolo.

/////////////
2004-10-15  Paolo Carlini  <pcarlini@suse.de>

	* 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.
diff -urN libstdc++-v3-orig/include/ext/bitmap_allocator.h libstdc++-v3/include/ext/bitmap_allocator.h
--- libstdc++-v3-orig/include/ext/bitmap_allocator.h	2004-10-14 23:44:13.000000000 +0200
+++ libstdc++-v3/include/ext/bitmap_allocator.h	2004-10-15 12:22:11.000000000 +0200
@@ -674,14 +674,14 @@
 	      // 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<void*>(__addr));
+	      ::operator delete(static_cast<void*>(__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<void*>(_S_free_list.back()));
+	      ::operator delete(static_cast<void*>(_S_free_list.back()));
 	      _S_free_list.pop_back();
 	    }
 	}
@@ -1095,10 +1095,13 @@
       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 -urN libstdc++-v3-orig/src/bitmap_allocator.cc libstdc++-v3/src/bitmap_allocator.cc
--- libstdc++-v3-orig/src/bitmap_allocator.cc	2004-10-14 19:52:18.000000000 +0200
+++ libstdc++-v3/src/bitmap_allocator.cc	2004-10-15 11:43:58.000000000 +0200
@@ -121,7 +121,7 @@
     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 -urN libstdc++-v3-orig/src/mt_allocator.cc libstdc++-v3/src/mt_allocator.cc
--- libstdc++-v3-orig/src/mt_allocator.cc	2004-10-14 23:05:24.000000000 +0200
+++ libstdc++-v3/src/mt_allocator.cc	2004-10-15 11:50:27.000000000 +0200
@@ -61,10 +61,10 @@
 		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 @@
 		    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 @@
 		    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 -urN libstdc++-v3-orig/testsuite/ext/bitmap_allocator/check_deallocate_null.cc libstdc++-v3/testsuite/ext/bitmap_allocator/check_deallocate_null.cc
--- libstdc++-v3-orig/testsuite/ext/bitmap_allocator/check_deallocate_null.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/ext/bitmap_allocator/check_deallocate_null.cc	2004-10-15 12:25:09.000000000 +0200
@@ -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 <ext/bitmap_allocator.h>
+#include <testsuite_allocator.h>
+
+int main()
+{ 
+  typedef int value_type;
+  typedef __gnu_cxx::bitmap_allocator<value_type> allocator_type;
+  __gnu_test::check_deallocate_null<allocator_type>(); 
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/testsuite_allocator.h libstdc++-v3/testsuite/testsuite_allocator.h
--- libstdc++-v3-orig/testsuite/testsuite_allocator.h	2004-10-15 01:03:24.000000000 +0200
+++ libstdc++-v3/testsuite/testsuite_allocator.h	2004-10-15 12:23:18.000000000 +0200
@@ -202,6 +202,7 @@
     {
       // Let's not core here...
       Alloc  a;
+      a.deallocate(NULL, 1);
       a.deallocate(NULL, 10);
     }
 }; // namespace __gnu_test

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]