This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

[Patch/RFC] libstdc++/19495


Hi everyone, hi Benjamin,

In order to "fix" for 4.0 this PR (basically, ext/array_allocator/2.cc
fails on powerpc), one possible approach is the following:

1- Generalize a bit ext/array_allocator to avoid using begin() and size(),
thus accepting also memory allocated via tr1/aligned_storage not only
tr1/array. Seems to me a nice idea, per se.

2- Tweak the ext/array_allocator testcases to actually use tr1/aligned_storage,
which (at variance with tr1/array) allows to specify the alignment.


For 4.1, or when the ABI can change, anyway, we can consider changing
basic_string to make use of memory aligned only as CharT requires, not
more, but, for the time being, the below seems to me a viable approach...

Opinions? Disagreements?

(regtested x86/x86_64)

Paolo.

////////////
diff -urN libstdc++-v3-orig/include/ext/array_allocator.h libstdc++-v3/include/ext/array_allocator.h
--- libstdc++-v3-orig/include/ext/array_allocator.h	2004-11-24 05:11:11.000000000 +0100
+++ libstdc++-v3/include/ext/array_allocator.h	2005-01-19 14:26:29.000000000 +0100
@@ -1,6 +1,6 @@
 // array allocator -*- C++ -*-
 
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 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
@@ -96,9 +96,9 @@
       typedef const _Tp& const_reference;
       typedef _Tp        value_type;
 
-      typedef _Array	array_type;
+      typedef _Array	 array_type;
 
-      array_type* _M_array;
+      array_type*        _M_array;
       
      template<typename _Tp1, typename _Array1 = _Array>
         struct rebind
@@ -121,9 +121,9 @@
       allocate(size_type __n, const void* = 0)
       {
 	static size_type __used;
-	if (_M_array == 0 || __used + __n > _M_array->size())
+	if (_M_array == 0 || __used + __n > sizeof(*_M_array) / sizeof(_Tp))
 	  std::__throw_bad_alloc();
-	pointer __ret = _M_array->begin() + __used;
+	pointer __ret = reinterpret_cast<_Tp*>(_M_array) + __used;
 	__used += __n;
 	return __ret;
       }
diff -urN libstdc++-v3-orig/testsuite/ext/array_allocator/1.cc libstdc++-v3/testsuite/ext/array_allocator/1.cc
--- libstdc++-v3-orig/testsuite/ext/array_allocator/1.cc	2004-11-18 20:11:40.000000000 +0100
+++ libstdc++-v3/testsuite/ext/array_allocator/1.cc	2005-01-19 14:31:02.000000000 +0100
@@ -1,4 +1,4 @@
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 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
@@ -27,11 +27,12 @@
 
 #include <string>
 #include <ext/array_allocator.h>
+#include <tr1/type_traits>
 #include <testsuite_hooks.h>
 
 typedef char char_type;
 typedef std::char_traits<char_type> traits_type;
-typedef std::tr1::array<char_type, 4> array_type;
+typedef std::tr1::aligned_storage<4 * sizeof(char_type), 8>::type array_type;
 
 array_type extern_array;
 
diff -urN libstdc++-v3-orig/testsuite/ext/array_allocator/2.cc libstdc++-v3/testsuite/ext/array_allocator/2.cc
--- libstdc++-v3-orig/testsuite/ext/array_allocator/2.cc	2004-11-18 20:11:41.000000000 +0100
+++ libstdc++-v3/testsuite/ext/array_allocator/2.cc	2005-01-19 14:19:05.000000000 +0100
@@ -1,4 +1,4 @@
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 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
@@ -28,11 +28,12 @@
 #include <string>
 #include <iostream>
 #include <ext/array_allocator.h>
+#include <tr1/type_traits>
 #include <testsuite_hooks.h>
 
 typedef char char_type;
 typedef std::char_traits<char_type> traits_type;
-typedef std::tr1::array<char_type, 32> array_type;
+typedef std::tr1::aligned_storage<32 * sizeof(char_type), 8>::type array_type;
 
 array_type extern_array;
 
@@ -44,7 +45,6 @@
   typedef __gnu_cxx::array_allocator<char_type, array_type> allocator_type;
   typedef basic_string<char_type, traits_type, allocator_type> string_type;
 
-  size_t index = array_type::_S_index;
   allocator_type a(&extern_array);
   string_type s(a);
     
diff -urN libstdc++-v3-orig/testsuite/ext/array_allocator/3.cc libstdc++-v3/testsuite/ext/array_allocator/3.cc
--- libstdc++-v3-orig/testsuite/ext/array_allocator/3.cc	2004-11-18 20:11:41.000000000 +0100
+++ libstdc++-v3/testsuite/ext/array_allocator/3.cc	2005-01-19 14:20:26.000000000 +0100
@@ -1,4 +1,4 @@
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 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
@@ -27,11 +27,12 @@
 
 #include <string>
 #include <ext/array_allocator.h>
+#include <tr1/type_traits>
 #include <testsuite_hooks.h>
 
 typedef char char_type;
 typedef std::char_traits<char_type> traits_type;
-typedef std::tr1::array<char_type, 4> array_type;
+typedef std::tr1::aligned_storage<4 * sizeof(char_type), 8>::type array_type;
 
 array_type extern_array;
 
diff -urN libstdc++-v3-orig/testsuite/ext/array_allocator/check_delete.cc libstdc++-v3/testsuite/ext/array_allocator/check_delete.cc
--- libstdc++-v3-orig/testsuite/ext/array_allocator/check_delete.cc	2004-10-29 23:03:04.000000000 +0200
+++ libstdc++-v3/testsuite/ext/array_allocator/check_delete.cc	2005-01-19 14:19:38.000000000 +0100
@@ -1,6 +1,6 @@
 // 2001-11-25  Phil Edwards  <pme@gcc.gnu.org>
 //
-// Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2003, 2004, 2005 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
@@ -22,6 +22,7 @@
 
 #include <cstdlib>
 #include <ext/array_allocator.h>
+#include <tr1/type_traits>
 #include <testsuite_hooks.h>
 #include <testsuite_allocator.h>
 
@@ -46,7 +47,7 @@
 { 
   bool test __attribute__((unused)) = true;
   typedef unsigned int value_type;
-  typedef std::tr1::array<value_type, 15> array_type;
+  typedef std::tr1::aligned_storage<15 * sizeof(value_type), 8>::type array_type;
   typedef array_allocator<value_type, array_type> allocator_type;
   array_type store;
   allocator_type a(&store);
diff -urN libstdc++-v3-orig/testsuite/ext/array_allocator/check_new.cc libstdc++-v3/testsuite/ext/array_allocator/check_new.cc
--- libstdc++-v3-orig/testsuite/ext/array_allocator/check_new.cc	2004-10-29 23:03:04.000000000 +0200
+++ libstdc++-v3/testsuite/ext/array_allocator/check_new.cc	2005-01-19 14:19:46.000000000 +0100
@@ -1,6 +1,6 @@
 // 2001-11-25  Phil Edwards  <pme@gcc.gnu.org>
 //
-// Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2003, 2004, 2005 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
@@ -22,6 +22,7 @@
 
 #include <cstdlib>
 #include <ext/array_allocator.h>
+#include <tr1/type_traits>
 #include <testsuite_hooks.h>
 #include <testsuite_allocator.h>
 
@@ -46,7 +47,7 @@
 { 
   bool test __attribute__((unused)) = true;
   typedef unsigned int value_type;
-  typedef std::tr1::array<value_type, 15> array_type;
+  typedef std::tr1::aligned_storage<15 * sizeof(value_type), 8>::type array_type;
   typedef array_allocator<value_type, array_type> allocator_type;
   array_type store;
   allocator_type a(&store);

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