This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos 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]

Re: uSTL 1.4 update


On 06/28/2010 11:34 AM, Simon Kallweit wrote:
Hi John

Sorry, that was pretty bad testing on my side ;) only did some tests on
the synth target. The shortcomings are pretty obvious!

I'll fix the mistakes and post an updated patch.

Here is the updated patch.


Added a generic implementation for the NextPow2, which is currently suboptimal but mimics what the x86 implementation is doing. Also removed the introduced change in include/ustl/uctrstrm.h so it should build again with -fno-rtti.

Simon
diff --git a/packages/language/cxx/ustl/current/ChangeLog b/packages/language/cxx/ustl/current/ChangeLog
index 7fdc5de..88c1d5c 100644
--- a/packages/language/cxx/ustl/current/ChangeLog
+++ b/packages/language/cxx/ustl/current/ChangeLog
@@ -1,3 +1,10 @@
+2010-06-25  Simon Kallweit <simon.kallweit@intefo.ch>
+
+	* include/*:
+	* tests/*:
+	* HISTORY:
+	* LICENSE: Updated to uSTL 1.4 sources.
+
 2009-10-06  Uwe Kindler <uwe_kindler@web.de>
 
 	* doc/ustl.sgml: Removed cout.flush() from example and from note.
diff --git a/packages/language/cxx/ustl/current/HISTORY b/packages/language/cxx/ustl/current/HISTORY
index f7177a1..3540e89 100644
--- a/packages/language/cxx/ustl/current/HISTORY
+++ b/packages/language/cxx/ustl/current/HISTORY
@@ -1,3 +1,9 @@
+2010-03-21 Release 1.4
+	* Fixed crash in destructor of empty vector, introduced by 1.3
+	* Fixed list merge, which previously did not compile
+	* Some portability changes to configure so it will work with dash
+	    when escape char processing bug is fixed (Ubuntu bug #268929)
+
 2009-08-04 Release 1.3
 	* Some API changes to comply with the current C++ standard
 	    binary_search algo returns true, not the found iterator
diff --git a/packages/language/cxx/ustl/current/LICENSE b/packages/language/cxx/ustl/current/LICENSE
index e80e7a8..857a9b4 100644
--- a/packages/language/cxx/ustl/current/LICENSE
+++ b/packages/language/cxx/ustl/current/LICENSE
@@ -1,24 +1,22 @@
 
 			The MIT License
 
-Copyright (C) 2005 by Mike Sharov <msharov@users.sourceforge.net>
+Copyright (c) 2005-2009 by Mike Sharov <msharov@users.sourceforge.net>
 
 Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included
 in all copies or substantial portions of the Software.
 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
diff --git a/packages/language/cxx/ustl/current/include/ustl/sistream.h b/packages/language/cxx/ustl/current/include/ustl/sistream.h
index 08e86e0..13fbf4b 100644
--- a/packages/language/cxx/ustl/current/include/ustl/sistream.h
+++ b/packages/language/cxx/ustl/current/include/ustl/sistream.h
@@ -8,6 +8,9 @@
 
 #include "mistream.h"
 #include "ustring.h"
+#ifndef EOF
+#define EOF (-1)
+#endif
 
 namespace ustl {
 
@@ -38,7 +41,7 @@ public:
     inline string		str (void) const	{ string s; s.link (*this); return (s); }
     inline istringstream&	str (const string& s)	{ link (s); return (*this); }
     inline istringstream&	get (char& c)	{ return (read (&c, sizeof(c))); }
-    inline int			get (void)	{ char c; get(c); return (c); }
+    inline int			get (void)	{ char c = EOF; get(c); return (c); }
     istringstream&		get (char* p, size_type n, char delim = '\n');
     istringstream&		get (string& s, char delim = '\n');
     istringstream&		getline (char* p, size_type n, char delim = '\n');
@@ -137,9 +140,6 @@ ISTRSTREAM_CAST_OPERATOR (char,		int8_t)
 ISTRSTREAM_CAST_OPERATOR (uint64_t,	int64_t)
 #endif
 #if SIZE_OF_LONG == SIZE_OF_INT
-// This works only properly if stdint.h typedefs int to int32_t. If stdint.h
-// typedefs long to int32_t then this causes compiler errors. So make shure
-// that your stdint.h file typedefs int to int32_t.
 ISTRSTREAM_CAST_OPERATOR (long,		int)
 ISTRSTREAM_CAST_OPERATOR (unsigned long,int)
 #endif
diff --git a/packages/language/cxx/ustl/current/include/ustl/ulist.h b/packages/language/cxx/ustl/current/include/ustl/ulist.h
index eedf632..97de7a9 100644
--- a/packages/language/cxx/ustl/current/include/ustl/ulist.h
+++ b/packages/language/cxx/ustl/current/include/ustl/ulist.h
@@ -50,9 +50,8 @@ public:
 template <typename T>
 void list<T>::merge (list& l)
 {
-    list<T>::resize (size() + l.size());
-    iterator me = merge (begin(), end(), l.begin(), l.end(), begin());
-    list<T>::resize (distance (begin(), me));
+    insert_space (begin(), l.size());
+    ::ustl::merge (iat(l.size()), end(), l.begin(), l.end(), begin());
 }
 
 /// Moves the range [first, last) from \p l to this list at \p ip.
diff --git a/packages/language/cxx/ustl/current/include/ustl/umemory.h b/packages/language/cxx/ustl/current/include/ustl/umemory.h
index 238f5d3..05e8c34 100644
--- a/packages/language/cxx/ustl/current/include/ustl/umemory.h
+++ b/packages/language/cxx/ustl/current/include/ustl/umemory.h
@@ -75,8 +75,10 @@ template <typename ForwardIterator>
 inline void construct (ForwardIterator first, ForwardIterator last)
 {
     typedef typename iterator_traits<ForwardIterator>::value_type value_type;
-    if (!numeric_limits<value_type>::is_integral && first)
-	for (--last; first <= last; ++first)
+    if (numeric_limits<value_type>::is_integral)
+	memset (first, 0, distance(first,last)*sizeof(value_type));
+    else
+	for (--last; intptr_t(first) <= intptr_t(last); ++first)
 	    construct (&*first);
 }
 
@@ -101,7 +103,7 @@ inline void destroy (T* p) throw()
 // Helper templates to not instantiate anything for integral types.
 template <typename T>
 void dtors (T first, T last) throw()
-    { for (--last; first <= last; ++first) destroy (&*first); }
+    { for (--last; intptr_t(first) <= intptr_t(last); ++first) destroy (&*first); }
 template <typename T, bool bIntegral>
 struct Sdtorsr {
     inline void operator()(T first, T last) throw() { dtors (first, last); }
diff --git a/packages/language/cxx/ustl/current/include/ustl/uutility.h b/packages/language/cxx/ustl/current/include/ustl/uutility.h
index 40567dd..7cb5139 100644
--- a/packages/language/cxx/ustl/current/include/ustl/uutility.h
+++ b/packages/language/cxx/ustl/current/include/ustl/uutility.h
@@ -145,11 +145,13 @@ UNVOID_DISTANCE(const,)
 #undef UNVOID_DISTANCE
 #endif
 
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
 // The compiler issues a warning if an unsigned type is compared to 0.
 template <typename T, bool IsSigned> struct __is_negative { inline bool operator()(const T& v) { return (v < 0); } };
 template <typename T> struct __is_negative<T,false> { inline bool operator()(const T&) { return (false); } };
 /// Warning-free way to check if \p v is negative, even if for unsigned types.
 template <typename T> inline bool is_negative (const T& v) { return (__is_negative<T,numeric_limits<T>::is_signed>()(v)); }
+#endif
 
 /// \brief Returns the absolute value of \p v
 /// Unlike the stdlib functions, this is inline and works with all types.
@@ -339,6 +341,26 @@ inline bool TestAndSet (int* pm)
 #endif
 }
 
+inline uint32_t NextPow2 (uint32_t v)
+{
+#if __i386__ || __x86_64__
+	asm("dec\t%1\n\t"
+	"mov\t$1,%0\n\t"
+	"bsr\t%1,%1\n\t"
+	"inc\t%1\n\t"
+	"rol\t%b1,%0":"=&r"(v):"c"(v));
+    return (v);
+#else
+    // The following code is sub-optimal but mimics the x86 implementation
+    int i = 31;
+    v--;
+    while (!(v & (1 << i)) && i > 0) i--;
+    if (i == 31)
+    	return 1;
+    return (1 << (i + 1));
+#endif
+}
+
 /// \brief This template is to be used for dereferencing a type-punned pointer without a warning.
 ///
 /// When casting a local variable to an unrelated type through a pointer (for
diff --git a/packages/language/cxx/ustl/current/include/ustl/uvector.h b/packages/language/cxx/ustl/current/include/ustl/uvector.h
index 5acbfdf..fb50e40 100644
--- a/packages/language/cxx/ustl/current/include/ustl/uvector.h
+++ b/packages/language/cxx/ustl/current/include/ustl/uvector.h
@@ -98,7 +98,7 @@ public:
     inline void			write (ostream& os) const		{ container_write (os, *this); }
     inline void			text_write (ostringstream& os) const	{ container_text_write (os, *this); }
     inline size_t		stream_size (void) const		{ return (container_stream_size (*this)); }
-private:
+protected:
     inline iterator		insert_space (iterator ip, size_type n);
 private:
     memblock			m_Data;	///< Raw element data, consecutively stored.
diff --git a/packages/language/cxx/ustl/current/tests/bvt21.cpp b/packages/language/cxx/ustl/current/tests/bvt21.cpp
index 051bbe4..48b96fa 100644
--- a/packages/language/cxx/ustl/current/tests/bvt21.cpp
+++ b/packages/language/cxx/ustl/current/tests/bvt21.cpp
@@ -33,6 +33,12 @@ void TestUtility (void)
     cout << "Align(17,7) = " << Align(17,7) << endl;
     cout << "Align(14,7) = " << Align(14,7) << endl;
     cout << endl;
+    cout << "NextPow2(0) = " << NextPow2(0) << endl;
+    cout << "NextPow2(1) = " << NextPow2(1) << endl;
+    cout << "NextPow2(4) = " << NextPow2(4) << endl;
+    cout << "NextPow2(3827) = " << NextPow2(3827) << endl;
+    cout << "NextPow2(0xFFFFFFF0) = " << NextPow2(0xFFFFFFF0) << endl;
+    cout << endl;
     cout << "advance(42,0) = " << advance(42,0) << endl;
     cout << "advance(42,3) = " << advance(42,3) << endl;
     const void *cvp = (const void*) 0x1234;
diff --git a/packages/language/cxx/ustl/current/tests/bvt21.std b/packages/language/cxx/ustl/current/tests/bvt21.std
index 7c60a5d..82b15a2 100644
--- a/packages/language/cxx/ustl/current/tests/bvt21.std
+++ b/packages/language/cxx/ustl/current/tests/bvt21.std
@@ -7,6 +7,12 @@ Align(5,2) = 6
 Align(17,7) = 21
 Align(14,7) = 14
 
+NextPow2(0) = 1
+NextPow2(1) = 2
+NextPow2(4) = 4
+NextPow2(3827) = 4096
+NextPow2(0xFFFFFFF0) = 1
+
 advance(42,0) = 42
 advance(42,3) = 45
 cvp = 1234

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