stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r413946 - in /incubator/stdcxx/trunk/tests: include/rw_char.h src/char.cpp
Date Tue, 13 Jun 2006 18:43:53 GMT
Author: sebor
Date: Tue Jun 13 11:43:53 2006
New Revision: 413946

URL: http://svn.apache.org/viewvc?rev=413946&view=rev
Log:
2006-06-13  Martin Sebor  <sebor@roguewave.com>

	* rw_char.h (UserTraits): Removed the definition of the primary
	template and replaced it with definitions of the two required
	specializations (on char and wchar_t) to avoid Sun C++ 5.8 bugs
	described at http://issues.apache.org/jira/browse/STDCXX-177.
	(TraitsMemFunc): Moved from the primary template to file scope
	and renamed from TraitsFun.
	* char.cpp: Same.

Modified:
    incubator/stdcxx/trunk/tests/include/rw_char.h
    incubator/stdcxx/trunk/tests/src/char.cpp

Modified: incubator/stdcxx/trunk/tests/include/rw_char.h
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/include/rw_char.h?rev=413946&r1=413945&r2=413946&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/include/rw_char.h (original)
+++ incubator/stdcxx/trunk/tests/include/rw_char.h Tue Jun 13 11:43:53 2006
@@ -172,116 +172,80 @@
 };
 
 
-// user-defined character traits
+// user-defined character traits template
+// (declared but not defined)
 template <class charT>
-struct UserTraits: std::char_traits<charT>
+struct UserTraits;
+
+
+struct TraitsMemFunc
 {
-    typedef std::char_traits<charT>  Base;
-    typedef typename Base::char_type char_type;
-    typedef typename Base::int_type  int_type;
-
-    struct MemFun {
-        enum {
-            assign, eq, lt, compare, length, find, copy, move,
-            assign2, not_eof, to_char_type, to_int_type, eq_int_type,
-            eof,
-            n_funs
-        };
+    enum {
+        assign, eq, lt, compare, length, find, copy, move,
+        assign2, not_eof, to_char_type, to_int_type, eq_int_type,
+        eof,
+        n_funs
     };
+};
 
-    static _RWSTD_SIZE_T n_calls_ [MemFun::n_funs];
+
+// required specialization on char
+_RWSTD_SPECIALIZED_CLASS
+struct _TEST_EXPORT UserTraits<char>: std::char_traits<char>
+{
+    typedef std::char_traits<char> Base;
+    typedef Base::char_type        char_type;
+    typedef Base::int_type         int_type;
+    typedef TraitsMemFunc          MemFun;
 
     // avoid any dependency on the library
     typedef int                   off_type;     // std::streamoff
     typedef int                   state_type;   // std::mbstate_t
     typedef std::fpos<state_type> pos_type;     // std::fpos<state_type>
 
-    // accesses to the char_type::f member may trigger a SIGBUS
-    // on some architectures (e.g., PA or SPARC) if the member
-    // isn't appropriately aligned
-
     static void
-    assign (char_type &dst, const char_type &src) {
-        ++n_calls_ [MemFun::assign];
-        Base::assign (dst, src);
-    }
-
-    static bool
-    eq (const char_type &ch1, const char_type &ch2) {
-        ++n_calls_ [MemFun::eq];
-        return Base::eq (ch1, ch2);
-    }
-
-    static bool
-    lt (const char_type &ch1, const char_type &ch2) {
-        ++n_calls_ [MemFun::lt];
-        return Base::lt (ch1, ch2);
-    }
+    assign (char_type&, const char_type&);
+
+    static bool
+    eq (const char_type&, const char_type&);
+
+    static bool
+    lt (const char_type&, const char_type&);
 
     static int
-    compare (const char_type *s1, const char_type *s2, _RWSTD_SIZE_T n) {
-        ++n_calls_ [MemFun::compare];
-        return Base::compare (s1, s2, n);
-    }
+    compare (const char_type*, const char_type*, _RWSTD_SIZE_T);
         
     static _RWSTD_SIZE_T
-    length (const char_type *s) {
-        ++n_calls_ [MemFun::length];
-        return Base::length (s);
-    }
+    length (const char_type*);
  
     static const char_type*
-    find (const char_type *s, _RWSTD_SIZE_T n, const char_type &ch) {
-        ++n_calls_ [MemFun::find];
-        return Base::find (s, n, ch);
-    }
+    find (const char_type*, _RWSTD_SIZE_T, const char_type&);
 
     static char_type*
-    copy (char_type *dst, const char_type *src, _RWSTD_SIZE_T n) {
-        ++n_calls_ [MemFun::copy];
-        return Base::copy (dst, src, n);
-    }
+    copy (char_type*, const char_type*, _RWSTD_SIZE_T);
 
     static char_type*
-    move (char_type *dst, const char_type *src, _RWSTD_SIZE_T n) {
-        ++n_calls_ [MemFun::move];
-        return Base::move (dst, src, n);
-    }
+    move (char_type*, const char_type*, _RWSTD_SIZE_T);
 
     static char_type*
-    assign (char_type *s, _RWSTD_SIZE_T n, char_type ch) {
-        ++n_calls_ [MemFun::assign];
-        return Base::assign (s, n, ch);
-    }
+    assign (char_type*, _RWSTD_SIZE_T, char_type);
 
     static int_type
-    not_eof (const int_type &i) {
-        ++n_calls_ [MemFun::not_eof];
-        return eof () == i ? ~i : i;
-    }
+    not_eof (const int_type&);
 
     static char_type
-    to_char_type (const int_type &i) {
-        ++n_calls_ [MemFun::to_char_type];
-        return Base::to_char_type (i);
-    }
+    to_char_type (const int_type&);
       
     static int_type
-    to_int_type (const char_type &ch) {
-        ++n_calls_ [MemFun::to_int_type];
-        return Base::to_int_type (ch);
-    }
+    to_int_type (const char_type&);
 
     static bool
-    eq_int_type (const int_type &i1, const int_type &i2) {
-        ++n_calls_ [MemFun::eq_int_type];
-        return Base::eq_int_type (i1, i2);
-    }
+    eq_int_type (const int_type&, const int_type&);
 
     static int_type
-    eof () {
-        return eof_;
-    }
+    eof ();
+
+    static _RWSTD_SIZE_T n_calls_ [];
 
     static int_type eof_;
 
@@ -294,28 +258,83 @@
 };
 
 
-template <class charT>
-_RWSTD_SIZE_T
-UserTraits<charT>::n_calls_ [ /* UserTraits<charT>::MemFun::n_funs */];
+#ifndef _RWSTD_NO_WCHAR_T
 
-template <class charT>
-typename UserTraits<charT>::int_type
-UserTraits<charT>::eof_ = std::char_traits<charT>::eof ();
+// required specialization on wchar_t
+_RWSTD_SPECIALIZED_CLASS
+struct _TEST_EXPORT UserTraits<wchar_t>: std::char_traits<wchar_t>
+{
+    typedef std::char_traits<wchar_t> Base;
+    typedef Base::char_type           char_type;
+    typedef Base::int_type            int_type;
+    typedef TraitsMemFunc             MemFun;
+
+    // avoid any dependency on the library
+    typedef int                   off_type;     // std::streamoff
+    typedef int                   state_type;   // std::mbstate_t
+    typedef std::fpos<state_type> pos_type;     // std::fpos<state_type>
+
+    static void
+    assign (char_type&, const char_type&);
+
+    static bool
+    eq (const char_type&, const char_type&);
+
+    static bool
+    lt (const char_type&, const char_type&);
+
+    static int
+    compare (const char_type*, const char_type*, _RWSTD_SIZE_T);
+        
+    static _RWSTD_SIZE_T
+    length (const char_type*);
+ 
+    static const char_type*
+    find (const char_type*, _RWSTD_SIZE_T, const char_type&);
+
+    static char_type*
+    copy (char_type*, const char_type*, _RWSTD_SIZE_T);
+
+    static char_type*
+    move (char_type*, const char_type*, _RWSTD_SIZE_T);
+
+    static char_type*
+    assign (char_type*, _RWSTD_SIZE_T, char_type);
+
+    static int_type
+    not_eof (const int_type&);
+
+    static char_type
+    to_char_type (const int_type&);
+      
+    static int_type
+    to_int_type (const char_type&);
+
+    static bool
+    eq_int_type (const int_type&, const int_type&);
+
+    static int_type
+    eof ();
+
+    static _RWSTD_SIZE_T n_calls_ [];
+
+    static int_type eof_;
+
+private:
+
+    // not defined to detect bad assumptions made by the library
+    UserTraits ();
+    ~UserTraits ();
+    void operator= (UserTraits&);
+};
+
+#endif   // _RWSTD_NO_WCHAR_T
 
 
 _RWSTD_SPECIALIZED_CLASS
 struct _TEST_EXPORT UserTraits<UserChar>   // user-defined character traits
 {
-    struct MemFun {
-        enum {
-            assign, eq, lt, compare, length, find, copy, move,
-            assign2, not_eof, to_char_type, to_int_type, eq_int_type,
-            eof,
-            n_funs
-        };
-    };
-
-    static _RWSTD_SIZE_T n_calls_ [];
+    typedef TraitsMemFunc MemFun;
 
     typedef UserChar char_type;
     typedef UserInt  int_type;
@@ -361,6 +380,8 @@
     static bool eq_int_type (const int_type&, const int_type&);
 
     static int_type eof ();
+
+    static _RWSTD_SIZE_T n_calls_ [];
 
 private:
 

Modified: incubator/stdcxx/trunk/tests/src/char.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/char.cpp?rev=413946&r1=413945&r2=413946&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/char.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/char.cpp Tue Jun 13 11:43:53 2006
@@ -41,6 +41,266 @@
 typedef unsigned char UChar;
 
 
+void UserTraits<char>::
+assign (char_type &dst, const char_type &src)
+{
+    ++n_calls_ [MemFun::assign];
+    Base::assign (dst, src);
+}
+
+
+bool UserTraits<char>::
+eq (const char_type &ch1, const char_type &ch2)
+{
+    ++n_calls_ [MemFun::eq];
+    return Base::eq (ch1, ch2);
+}
+
+
+bool UserTraits<char>::
+lt (const char_type &ch1, const char_type &ch2)
+{
+    ++n_calls_ [MemFun::lt];
+    return Base::lt (ch1, ch2);
+}
+
+
+int UserTraits<char>::
+compare (const char_type *s1, const char_type *s2, size_t n)
+{
+    ++n_calls_ [MemFun::compare];
+    return Base::compare (s1, s2, n);
+}
+
+        
+size_t UserTraits<char>::
+length (const char_type *s)
+{
+    ++n_calls_ [MemFun::length];
+    return Base::length (s);
+}
+ 
+
+const UserTraits<char>::char_type*
+UserTraits<char>::
+find (const char_type *s, size_t n, const char_type &ch)
+{
+    ++n_calls_ [MemFun::find];
+    return Base::find (s, n, ch);
+}
+
+
+UserTraits<char>::char_type*
+UserTraits<char>::
+copy (char_type *dst, const char_type *src, size_t n)
+{
+    ++n_calls_ [MemFun::copy];
+    return Base::copy (dst, src, n);
+}
+
+
+UserTraits<char>::char_type*
+UserTraits<char>::
+move (char_type *dst, const char_type *src, size_t n)
+{
+    ++n_calls_ [MemFun::move];
+    return Base::move (dst, src, n);
+}
+
+
+UserTraits<char>::char_type*
+UserTraits<char>::
+assign (char_type *s, size_t n, char_type ch)
+{
+    ++n_calls_ [MemFun::assign];
+    return Base::assign (s, n, ch);
+}
+
+
+UserTraits<char>::int_type
+UserTraits<char>::
+not_eof (const int_type &i)
+{
+    ++n_calls_ [MemFun::not_eof];
+    return eof () == i ? ~i : i;
+}
+
+
+UserTraits<char>::char_type
+UserTraits<char>::
+to_char_type (const int_type &i)
+{
+    ++n_calls_ [MemFun::to_char_type];
+    return Base::to_char_type (i);
+}
+
+      
+UserTraits<char>::int_type
+UserTraits<char>::
+to_int_type (const char_type &ch)
+{
+    ++n_calls_ [MemFun::to_int_type];
+    return Base::to_int_type (ch);
+}
+
+
+bool UserTraits<char>::
+eq_int_type (const int_type &i1, const int_type &i2)
+{
+    ++n_calls_ [MemFun::eq_int_type];
+    return Base::eq_int_type (i1, i2);
+}
+
+
+UserTraits<char>::int_type
+UserTraits<char>::
+eof ()
+{
+    return eof_;
+}
+
+
+size_t UserTraits<char>::
+n_calls_ [UserTraits<char>::MemFun::n_funs];
+
+
+UserTraits<char>::int_type
+UserTraits<char>::
+eof_ = std::char_traits<char>::eof ();
+
+
+#ifndef _RWSTD_NO_WCHAR_T
+
+void UserTraits<wchar_t>::
+assign (char_type &dst, const char_type &src)
+{
+    ++n_calls_ [MemFun::assign];
+    Base::assign (dst, src);
+}
+
+
+bool UserTraits<wchar_t>::
+eq (const char_type &ch1, const char_type &ch2)
+{
+    ++n_calls_ [MemFun::eq];
+    return Base::eq (ch1, ch2);
+}
+
+
+bool UserTraits<wchar_t>::
+lt (const char_type &ch1, const char_type &ch2)
+{
+    ++n_calls_ [MemFun::lt];
+    return Base::lt (ch1, ch2);
+}
+
+
+int UserTraits<wchar_t>::
+compare (const char_type *s1, const char_type *s2, size_t n)
+{
+    ++n_calls_ [MemFun::compare];
+    return Base::compare (s1, s2, n);
+}
+
+        
+size_t UserTraits<wchar_t>::
+length (const char_type *s)
+{
+    ++n_calls_ [MemFun::length];
+    return Base::length (s);
+}
+ 
+
+const UserTraits<wchar_t>::char_type*
+UserTraits<wchar_t>::
+find (const char_type *s, size_t n, const char_type &ch)
+{
+    ++n_calls_ [MemFun::find];
+    return Base::find (s, n, ch);
+}
+
+
+UserTraits<wchar_t>::char_type*
+UserTraits<wchar_t>::
+copy (char_type *dst, const char_type *src, size_t n)
+{
+    ++n_calls_ [MemFun::copy];
+    return Base::copy (dst, src, n);
+}
+
+
+UserTraits<wchar_t>::char_type*
+UserTraits<wchar_t>::
+move (char_type *dst, const char_type *src, size_t n)
+{
+    ++n_calls_ [MemFun::move];
+    return Base::move (dst, src, n);
+}
+
+
+UserTraits<wchar_t>::char_type*
+UserTraits<wchar_t>::
+assign (char_type *s, size_t n, char_type ch)
+{
+    ++n_calls_ [MemFun::assign];
+    return Base::assign (s, n, ch);
+}
+
+
+UserTraits<wchar_t>::int_type
+UserTraits<wchar_t>::
+not_eof (const int_type &i)
+{
+    ++n_calls_ [MemFun::not_eof];
+    return eof () == i ? ~i : i;
+}
+
+
+UserTraits<wchar_t>::char_type
+UserTraits<wchar_t>::
+to_char_type (const int_type &i)
+{
+    ++n_calls_ [MemFun::to_char_type];
+    return Base::to_char_type (i);
+}
+
+      
+UserTraits<wchar_t>::int_type
+UserTraits<wchar_t>::
+to_int_type (const char_type &ch)
+{
+    ++n_calls_ [MemFun::to_int_type];
+    return Base::to_int_type (ch);
+}
+
+
+bool UserTraits<wchar_t>::
+eq_int_type (const int_type &i1, const int_type &i2)
+{
+    ++n_calls_ [MemFun::eq_int_type];
+    return Base::eq_int_type (i1, i2);
+}
+
+
+UserTraits<wchar_t>::int_type
+UserTraits<wchar_t>::
+eof ()
+{
+    return eof_;
+}
+
+
+size_t UserTraits<wchar_t>::
+n_calls_ [UserTraits<wchar_t>::MemFun::n_funs];
+
+
+UserTraits<wchar_t>::int_type
+UserTraits<wchar_t>::
+eof_ = std::char_traits<wchar_t>::eof ();
+
+#endif   // _RWSTD_NO_WCHAR_T
+
+
 size_t
 UserTraits<UserChar>::
 n_calls_ [UserTraits<UserChar>::MemFun::n_funs];



Mime
View raw message