Usermode/libc++ - STL Fix string termination, silence map debug
authorJohn Hodge <[email protected]>
Sun, 8 Jun 2014 06:01:55 +0000 (14:01 +0800)
committerJohn Hodge <[email protected]>
Sun, 8 Jun 2014 06:01:55 +0000 (14:01 +0800)
Usermode/Libraries/libc++.so_src/include_exp/_libcxx_helpers.h
Usermode/Libraries/libc++.so_src/include_exp/map
Usermode/Libraries/libc++.so_src/include_exp/string

index 0537537..d2f8b23 100644 (file)
@@ -8,7 +8,15 @@
 # define _CXX11_AVAIL  0
 #endif
 
+#define _libcxx_assert(cnd) do { \
+       if(!(cnd)) {\
+               ::_sys::debug("libc++ assert failure %s:%i - %s", __FILE__, __LINE__, #cnd);\
+               ::_sys::abort(); \
+       } \
+} while(0)
+
 namespace _sys {
+extern void abort() __asm__ ("abort") __attribute__((noreturn));
 extern void debug(const char *, ...);
 };
 
index 7a1cf3e..10bae93 100644 (file)
@@ -319,6 +319,7 @@ private:
                pos_out = pos;
                return false;
                #else
+               //::_sys::debug("map::_search (m_size=%i)", m_size);
                for( size_type pos = 0; pos < m_size; pos ++ )
                {
                        const key_type& item_key = m_items[pos].first;
@@ -326,14 +327,17 @@ private:
                                continue;
                        }
                        else if( m_comp(k, item_key) ) {
+                               //::_sys::debug("map::_search - Passed %i", pos);
                                pos_out = pos;
                                return false;
                        }
                        else {
+                               //::_sys::debug("map::_search - Found %i", pos);
                                pos_out = pos;
                                return true;
                        }
                }
+               //::_sys::debug("map::_search - Off end %i", m_size);
                pos_out = m_size;
                return false;
                #endif
@@ -341,7 +345,7 @@ private:
        void insert_at(size_type ofs, const value_type& val) {
                //assert( ofs == 0 || m_comp(m_items[ofs-1].first, val.first) );
                //assert( ofs == m_size || m_comp(m_items[ofs].first, val.first) );
-               ::_sys::debug("map::insert_at(%i,)", ofs);
+               //::_sys::debug("map::insert_at(%i,)", ofs);
                // Resize up
                reserve( m_size + 1 );
                // Move following items up
index ac9e5f3..3d289d6 100644 (file)
@@ -8,6 +8,7 @@
 #ifndef _LIBCXX_STRING_
 #define _LIBCXX_STRING_
 
+#include "_libcxx_helpers.h"
 #include <allocator>
 
 namespace std {
@@ -98,6 +99,9 @@ private:
                }
        };
 
+       allocator_type  m_allocator;
+       dynamic_info    *m_content;
+
 public:
        basic_string(const allocator_type& alloc = allocator_type()):
                m_allocator(alloc),
@@ -109,6 +113,15 @@ public:
        {
                *this = str;
        }
+       #if _CXX11_AVAIL
+       basic_string(basic_string&& str):
+               m_allocator(str.m_allocator),
+               m_content(str.m_content)
+       {
+               str.m_content = 0;
+               ::_sys::debug("basic_string(move) %p %s", m_content, c_str());
+       }
+       #endif
        basic_string(const basic_string& str, const allocator_type& alloc):
                basic_string(str, 0, str.length(), alloc)
        {
@@ -138,6 +151,7 @@ public:
                        reserve(n);
                        for( size_type i = 0; i < n; i ++ )
                                m_content->m_data[i] = s[i];
+                       m_content->m_data[n] = 0;
                        m_content->m_size = n;
                }
        }
@@ -149,6 +163,7 @@ public:
                        reserve(n);
                        for( size_type i = 0; i < n; i ++ )
                                m_content->m_data[i] = c;
+                       m_content->m_data[n] = 0;
                        m_content->m_size = n;
                }
        }
@@ -195,6 +210,7 @@ public:
                if( m_content->m_size < size ) {
                        for( size_type ofs = m_content->m_size; ofs < size; ofs ++ )
                                m_content->m_data[ofs] = c;
+                       m_content->m_data[size] = 0;
                }
                m_content->m_size = size;
                m_content->m_data[size] = 0;
@@ -326,6 +342,9 @@ public:
        // String operations
        const char *c_str() const {
                // TODO: this is const, but also might need to do processing
+               if(m_content) {
+                       _libcxx_assert(m_content->m_data[m_content->m_size] == '\0');
+               }
                return (m_content ? m_content->m_data : "");
        }
        const char *data() const {
@@ -334,9 +353,6 @@ public:
        
        static const size_type npos = -1;
 private:
-       allocator_type  m_allocator;
-       dynamic_info    *m_content;
-
        void own_content() {
                if(!m_content)
                {

UCC git Repository :: git.ucc.asn.au