aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2006-07-12 00:05:50 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2006-07-12 00:05:50 +0000
commit420644ea2302aefb91349fc30b94b88a56530ef7 (patch)
tree2ffe945cca2fd5a687ad44cc83b2dd53fb6ddfbd /libstdc++-v3
parentad084e9d07b907cfe52961a1d43155d24626c415 (diff)
downloadgcc-420644ea2302aefb91349fc30b94b88a56530ef7.zip
gcc-420644ea2302aefb91349fc30b94b88a56530ef7.tar.gz
gcc-420644ea2302aefb91349fc30b94b88a56530ef7.tar.bz2
locale_facets.tcc (collate<>::do_transform( const _CharT*, const _CharT*)): Simplify previous fix for libstdc++/28277, always allocate memory dynamically.
2006-07-11 Paolo Carlini <pcarlini@suse.de> * include/bits/locale_facets.tcc (collate<>::do_transform( const _CharT*, const _CharT*)): Simplify previous fix for libstdc++/28277, always allocate memory dynamically. From-SVN: r115356
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog6
-rw-r--r--libstdc++-v3/include/bits/locale_facets.tcc37
2 files changed, 21 insertions, 22 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 6f143dc..4d6cfc3 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,11 @@
2006-07-11 Paolo Carlini <pcarlini@suse.de>
+ * include/bits/locale_facets.tcc (collate<>::do_transform(
+ const _CharT*, const _CharT*)): Simplify previous fix for
+ libstdc++/28277, always allocate memory dynamically.
+
+2006-07-11 Paolo Carlini <pcarlini@suse.de>
+
PR libstdc++/28344
* include/tr1/random (gamma_distribution<>::
gamma_distribution(const result_type&)): Don't use __alpha as
diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc
index ad45863..af2263b 100644
--- a/libstdc++-v3/include/bits/locale_facets.tcc
+++ b/libstdc++-v3/include/bits/locale_facets.tcc
@@ -2457,28 +2457,18 @@ _GLIBCXX_END_LDBL_NAMESPACE
{
string_type __ret;
- // Use alloca for an _M_transform temporary buffer up to an arbitrary,
- // but limited, asize, to avoid abusing the stack. Otherwise fall back
- // to dynamic memory allocation. This means splitting the computation
- // itself in hunks: a size <= 8k (thus <= 16k asize) appear sufficient
- // for optimal performance.
- const size_t __size = std::min(size_t(__hi - __lo), size_t(8192));
- const size_t __asize = 2 * __size;
+ // strxfrm assumes zero-terminated strings so we make a copy
+ const string_type __str(__lo, __hi);
- size_t __len = __asize;
+ const _CharT* __p = __str.c_str();
+ const _CharT* __pend = __str.data() + __str.length();
- _CharT* __c =
- static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __len));
+ size_t __len = (__hi - __lo) * 2;
- for (size_t __hunk = __size; __lo < __hi;
- __lo += __hunk, __hunk = std::min(size_t(__hi - __lo), __hunk))
- {
- // strxfrm assumes zero-terminated strings so we make a copy
- const string_type __str(__lo, __lo + __hunk);
-
- const _CharT* __p = __str.c_str();
- const _CharT* __pend = __str.data() + __hunk;
+ _CharT* __c = new _CharT[__len];
+ try
+ {
// strxfrm stops when it sees a nul character so we break
// the string into zero-terminated substrings and pass those
// to strxfrm.
@@ -2490,9 +2480,8 @@ _GLIBCXX_END_LDBL_NAMESPACE
// correct size.
if (__res >= __len)
{
- if (__len > __asize)
- delete [] __c;
__len = __res + 1;
+ delete [] __c, __c = 0;
__c = new _CharT[__len];
__res = _M_transform(__c, __p, __len);
}
@@ -2506,9 +2495,13 @@ _GLIBCXX_END_LDBL_NAMESPACE
__ret.push_back(_CharT());
}
}
+ catch(...)
+ {
+ delete [] __c;
+ __throw_exception_again;
+ }
- if (__len > __asize)
- delete [] __c;
+ delete [] __c;
return __ret;
}