You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by vi...@apache.org on 2008/03/20 23:53:30 UTC
svn commit: r639495 - in /stdcxx/trunk: include/rw/_tree.cc
tests/regress/23.set.stdcxx-216.cpp
Author: vitek
Date: Thu Mar 20 15:53:27 2008
New Revision: 639495
URL: http://svn.apache.org/viewvc?rev=639495&view=rev
Log:
2008-03-20 Travis Vitek <vi...@roguewave.com>
* tests/regress/23.set.stdcxx-216.cpp: Add regression test for
issue caused by fix to STDCXX-216.
* include/rw/_tree.cc: (insert): Ensure tree is not empty before
comparing keys to avoid umr.
Added:
stdcxx/trunk/tests/regress/23.set.stdcxx-216.cpp (with props)
Modified:
stdcxx/trunk/include/rw/_tree.cc
Modified: stdcxx/trunk/include/rw/_tree.cc
URL: http://svn.apache.org/viewvc/stdcxx/trunk/include/rw/_tree.cc?rev=639495&r1=639494&r2=639495&view=diff
==============================================================================
--- stdcxx/trunk/include/rw/_tree.cc (original)
+++ stdcxx/trunk/include/rw/_tree.cc Thu Mar 20 15:53:27 2008
@@ -350,11 +350,15 @@
const _C_link_t __hint = _ITER_NODE (__it);
- // if __hint is the right most child and __key is greater,
- // then insert on the right
+ // if __hint is the right most child, or tree is empty
if (__hint == _C_end->_C_child [1]) {
- if (_C_cmp (__hint->_C_key (), _KeyOf ()(__v)))
+
+ // if tree is not empty and __key is greater
+ // then insert on the right
+ if (_C_size && _C_cmp (__hint->_C_key (), _KeyOf ()(__v)))
return _C_insert (0, __hint, __v);
+
+ // otherwise just insert
return insert (__v, __dup).first;
}
@@ -366,10 +370,10 @@
return insert (__v, __dup).first;
}
- // if __hint is the leftmost child and __key is less
+ // if __hint is the left most child and __key is less
// then insert on the left
if (__hint == _C_end->_C_child [0]) {
- if (size () && _C_cmp (_KeyOf ()(__v), __hint->_C_key ()))
+ if (_C_cmp (_KeyOf ()(__v), __hint->_C_key ()))
return _C_insert (__hint, __hint, __v);
return insert (__v, __dup).first;
}
Added: stdcxx/trunk/tests/regress/23.set.stdcxx-216.cpp
URL: http://svn.apache.org/viewvc/stdcxx/trunk/tests/regress/23.set.stdcxx-216.cpp?rev=639495&view=auto
==============================================================================
--- stdcxx/trunk/tests/regress/23.set.stdcxx-216.cpp (added)
+++ stdcxx/trunk/tests/regress/23.set.stdcxx-216.cpp Thu Mar 20 15:53:27 2008
@@ -0,0 +1,135 @@
+/***************************************************************************
+ *
+ * 23.set.stdcxx-216.cpp - regression test for STDCXX-216
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software.
+ *
+ **************************************************************************/
+
+#include <set>
+#include <cassert>
+
+struct Value
+{
+ static const unsigned magic = 0x12344321;
+
+ Value (unsigned value = 0)
+ : value (value)
+ , valid (magic)
+ {
+ }
+
+ Value (const Value& key)
+ : value (key.value)
+ , valid (key.magic)
+ {
+ }
+
+ Value& operator= (const Value& rhs)
+ {
+ // assignment only valid from valid values
+ assert (rhs.is_valid ());
+
+ value = rhs.value;
+ valid = rhs.valid;
+ return *this;
+ }
+
+ ~Value ()
+ {
+ // destruction only allowed for valid values
+ assert (is_valid ());
+
+ valid = 0;
+ }
+
+ bool is_valid () const
+ {
+ return valid == magic;
+ }
+
+ friend
+ bool operator< (const Value& lhs, const Value& rhs)
+ {
+ // comparing against an invalid value is forbidden
+ assert (lhs.is_valid ());
+ assert (rhs.is_valid ());
+
+ const int lhs_is_odd = lhs.value & 1;
+ const int rhs_is_odd = rhs.value & 1;
+
+ // sort all even numbers in ascending order
+ // followed by odd numbers in ascending order
+ return lhs_is_odd != rhs_is_odd
+ ? lhs_is_odd < rhs_is_odd
+ : lhs.value < rhs.value;
+ }
+
+ unsigned value;
+ unsigned valid;
+};
+
+//#include <iostream>
+//
+//void dump (const std::set<Value>& s)
+//{
+// std::set<Value>::const_iterator b = s.begin ();
+// std::set<Value>::const_iterator e = s.end ();
+//
+// for (/**/; b != e; ++b)
+// std::cout << b->value << ' ';
+// std::cout << std::endl;
+//}
+
+int main ()
+{
+ // insert at begin
+ {
+ std::set<Value> s;
+
+ std::set<Value>::iterator i (s.begin ());
+ for (unsigned n = 0; n < 10; ++n)
+ s.insert (i, n);
+ }
+
+ // insert after last
+ {
+ std::set<Value> s;
+
+ std::set<Value>::iterator i (s.end ());
+ for (unsigned n = 0; n < 10; ++n)
+ i = s.insert (i, n);
+ }
+
+ // insert at end
+ {
+ std::set<Value> s;
+
+ std::set<Value>::iterator i (s.end ());
+ for (unsigned n = 0; n < 10; ++n)
+ s.insert (i, n);
+ }
+
+ return 0;
+}
+
Propchange: stdcxx/trunk/tests/regress/23.set.stdcxx-216.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: stdcxx/trunk/tests/regress/23.set.stdcxx-216.cpp
------------------------------------------------------------------------------
svn:keywords = Id