summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Mesnier <mesnier_p@ociweb.com>2011-04-14 19:04:09 +0000
committerPhil Mesnier <mesnier_p@ociweb.com>2011-04-14 19:04:09 +0000
commitdeb1a0691f404eae0194012560c9bed2077f799b (patch)
tree877b0fff07dd9c879d5f24807d5006a3a6412543
parent8906913d2310026ed36e66be48681fa287e3dc63 (diff)
downloadATCD-deb1a0691f404eae0194012560c9bed2077f799b.tar.gz
Thu Apr 14 19:03:06 UTC 2011 Phil Mesnier <mesnier_p@ociweb.com>
* tao/Array_Traits_T.h: * tao/Generic_Sequence_T.h: * tao/Object_Reference_Traits_T.h: * tao/String_Traits_T.h: * tao/Value_Traits_T.h: * tao/Valuetype/Valuetype_Traits_T.h: * tests/Sequence_Unit_Tests/bounded_object_reference_sequence_ut.cpp: * tests/Sequence_Unit_Tests/string_sequence_tester.hpp: * tests/Sequence_Unit_Tests/unbounded_object_reference_sequence_ut.cpp: Reverted the shallow-copy optimizations, they caused a memory leak in some usages.
-rw-r--r--TAO/ChangeLog17
-rw-r--r--TAO/tao/Array_Traits_T.h5
-rw-r--r--TAO/tao/Generic_Sequence_T.h88
-rw-r--r--TAO/tao/Object_Reference_Traits_T.h5
-rw-r--r--TAO/tao/String_Traits_T.h3
-rw-r--r--TAO/tao/Value_Traits_T.h3
-rw-r--r--TAO/tao/Valuetype/Valuetype_Traits_T.h3
-rw-r--r--TAO/tests/Sequence_Unit_Tests/bounded_object_reference_sequence_ut.cpp4
-rw-r--r--TAO/tests/Sequence_Unit_Tests/string_sequence_tester.hpp12
-rw-r--r--TAO/tests/Sequence_Unit_Tests/unbounded_object_reference_sequence_ut.cpp4
10 files changed, 56 insertions, 88 deletions
diff --git a/TAO/ChangeLog b/TAO/ChangeLog
index 9e1ad254ba9..d63c2b29131 100644
--- a/TAO/ChangeLog
+++ b/TAO/ChangeLog
@@ -1,3 +1,20 @@
+Thu Apr 14 19:03:06 UTC 2011 Phil Mesnier <mesnier_p@ociweb.com>
+
+ * tao/Array_Traits_T.h:
+ * tao/Generic_Sequence_T.h:
+ * tao/Object_Reference_Traits_T.h:
+ * tao/String_Traits_T.h:
+ * tao/Value_Traits_T.h:
+
+ * tao/Valuetype/Valuetype_Traits_T.h:
+
+ * tests/Sequence_Unit_Tests/bounded_object_reference_sequence_ut.cpp:
+ * tests/Sequence_Unit_Tests/string_sequence_tester.hpp:
+ * tests/Sequence_Unit_Tests/unbounded_object_reference_sequence_ut.cpp:
+
+ Reverted the shallow-copy optimizations, they caused a memory
+ leak in some usages.
+
Thu Apr 14 11:55:01 UTC 2011 Johnny Willemsen <jwillemsen@remedy.nl>
* tao/Resume_Handle.h:
diff --git a/TAO/tao/Array_Traits_T.h b/TAO/tao/Array_Traits_T.h
index 40b39edf014..4abd34b0383 100644
--- a/TAO/tao/Array_Traits_T.h
+++ b/TAO/tao/Array_Traits_T.h
@@ -82,14 +82,11 @@ struct array_traits
}
// Allow MSVC++ >= 8 checked iterators to be used.
-
- /// @return true if shallow copy.
template <typename iter>
- inline static bool copy_swap_range(
+ inline static void copy_swap_range(
value_type * begin, value_type * end, iter dst)
{
copy_range(begin, end, dst);
- return false;
}
};
diff --git a/TAO/tao/Generic_Sequence_T.h b/TAO/tao/Generic_Sequence_T.h
index bb436cb788a..c29dcf9ee22 100644
--- a/TAO/tao/Generic_Sequence_T.h
+++ b/TAO/tao/Generic_Sequence_T.h
@@ -1,5 +1,3 @@
-// -*- C++ -*-
-
#ifndef guard_generic_sequence_hpp
#define guard_generic_sequence_hpp
/**
@@ -145,14 +143,29 @@ public:
, buffer_(0)
, release_(false)
{
- copy_internal(rhs);
+ if (rhs.maximum_ == 0 || rhs.buffer_ == 0)
+ {
+ maximum_ = rhs.maximum_;
+ length_ = rhs.length_;
+ return;
+ }
+ generic_sequence tmp(rhs.maximum_, rhs.length_,
+ allocation_traits::allocbuf_noinit(rhs.maximum_),
+ true);
+ element_traits::initialize_range(
+ tmp.buffer_ + tmp.length_, tmp.buffer_ + tmp.maximum_);
+ element_traits::copy_range(
+ rhs.buffer_,
+ rhs.buffer_ + rhs.length_,
+ ACE_make_checked_array_iterator (tmp.buffer_, tmp.length_));
+ swap(tmp);
}
/// Assignment operator
generic_sequence & operator=(generic_sequence const & rhs)
{
- copy_internal(rhs);
-
+ generic_sequence tmp(rhs);
+ swap(tmp);
return * this;
}
@@ -186,15 +199,6 @@ public:
/// Set a new length for the sequence
void length(CORBA::ULong length)
{
- // When sequence doesn't own a buffer it's not allowed
- // to change it in any way.
- if (buffer_ && !release_)
- {
-// ACE_ERROR ((LM_ERROR,
-// ACE_TEXT ("Tried to change length of sequence when doesn't have ownership\n")));
- return;
- }
-
if (length <= maximum_)
{
if (buffer_ == 0)
@@ -209,7 +213,7 @@ public:
// When sequence doesn't own a buffer it's not allowed
// to change it in any way.
- if (length < length_ )
+ if (length < length_ && release_)
{
// TODO This code does not provide the strong-exception
// guarantee, but it does provide the weak-exception
@@ -234,15 +238,10 @@ public:
// destructed but *this will remain unchanged.
element_traits::initialize_range(
tmp.buffer_ + length_, tmp.buffer_ + length);
- if (element_traits::copy_swap_range(
- buffer_,
- buffer_ + length_,
- ACE_make_checked_array_iterator (tmp.buffer_, tmp.length_))) {
-
- // Made a shallow copy so release buffer_ because tmp.buffer_
- // now has the contents.
- element_traits::zero_range(buffer_, buffer_ + length_);
- }
+ element_traits::copy_swap_range(
+ buffer_,
+ buffer_ + length_,
+ ACE_make_checked_array_iterator (tmp.buffer_, tmp.length_));
swap(tmp);
}
@@ -448,47 +447,6 @@ private:
/// If true then the sequence should release the buffer when it is
/// destroyed.
mutable CORBA::Boolean release_;
-
- /// helper method for assignment operator and copy constructor
- /// to minimize creation of tmp sequences.
- void copy_internal(generic_sequence const & rhs)
- {
- if (buffer_ == 0)
- {
- if (rhs.maximum_ == 0 || rhs.buffer_ == 0)
- {
- maximum_ = rhs.maximum_;
- length_ = rhs.length_;
- }
- else
- {
- maximum_ = rhs.maximum_;
- length_ = rhs.length_;
- buffer_ = allocation_traits::allocbuf_noinit(maximum_);
- release_ = true;
-
- element_traits::initialize_range(
- buffer_ + length_, buffer_ + maximum_);
- element_traits::copy_range(
- rhs.buffer_,
- rhs.buffer_ + rhs.length_,
- ACE_make_checked_array_iterator (buffer_, length_));
- }
- }
- else
- {
- generic_sequence tmp(rhs.maximum_, rhs.length_,
- allocation_traits::allocbuf_noinit(rhs.maximum_),
- true);
- element_traits::initialize_range(
- tmp.buffer_ + tmp.length_, tmp.buffer_ + tmp.maximum_);
- element_traits::copy_range(
- rhs.buffer_,
- rhs.buffer_ + rhs.length_,
- ACE_make_checked_array_iterator (tmp.buffer_, tmp.length_));
- swap(tmp);
- }
- }
};
#if defined TAO_HAS_SEQUENCE_ITERATORS && TAO_HAS_SEQUENCE_ITERATORS == 1
diff --git a/TAO/tao/Object_Reference_Traits_T.h b/TAO/tao/Object_Reference_Traits_T.h
index 826c084dc7f..08532daa8cd 100644
--- a/TAO/tao/Object_Reference_Traits_T.h
+++ b/TAO/tao/Object_Reference_Traits_T.h
@@ -53,11 +53,10 @@ struct object_reference_traits_decorator
// Allow MSVC++ >= 8 checked iterators to be used.
template <typename iter>
- inline static bool copy_swap_range(
+ inline static void copy_swap_range(
object_type ** begin, object_type ** end, iter dst)
{
- std::copy(begin, end, dst);
- return true;
+ std::swap_ranges(begin, end, dst);
}
inline static void release_range(
diff --git a/TAO/tao/String_Traits_T.h b/TAO/tao/String_Traits_T.h
index f4cb728cf1d..ca1b05d990f 100644
--- a/TAO/tao/String_Traits_T.h
+++ b/TAO/tao/String_Traits_T.h
@@ -51,11 +51,10 @@ struct string_traits_decorator
// Allow MSVC++ >= 8 checked iterators to be used.
template <typename iter>
- inline static bool copy_swap_range(
+ inline static void copy_swap_range(
char_type ** begin, char_type ** end, iter dst)
{
std::swap_ranges(begin, end, dst);
- return true;
}
inline static void release_range(
diff --git a/TAO/tao/Value_Traits_T.h b/TAO/tao/Value_Traits_T.h
index c991a6dfc6e..a36338f2b41 100644
--- a/TAO/tao/Value_Traits_T.h
+++ b/TAO/tao/Value_Traits_T.h
@@ -56,11 +56,10 @@ struct value_traits
// Allow MSVC++ >= 8 checked iterators to be used.
template <typename iter>
- inline static bool copy_swap_range(
+ inline static void copy_swap_range(
value_type * begin, value_type * end, iter dst)
{
copy_range(begin, end, dst);
- return false;
}
};
diff --git a/TAO/tao/Valuetype/Valuetype_Traits_T.h b/TAO/tao/Valuetype/Valuetype_Traits_T.h
index c096eea835a..460ccc946ff 100644
--- a/TAO/tao/Valuetype/Valuetype_Traits_T.h
+++ b/TAO/tao/Valuetype/Valuetype_Traits_T.h
@@ -52,11 +52,10 @@ struct valuetype_traits_decorator
// Allow MSVC++ >= 8 checked iterators to be used.
template <typename iter>
- inline static bool copy_swap_range(
+ inline static void copy_swap_range(
object_type ** begin, object_type ** end, iter dst)
{
std::swap_ranges(begin, end, dst);
- return true;
}
inline static void release_range(
diff --git a/TAO/tests/Sequence_Unit_Tests/bounded_object_reference_sequence_ut.cpp b/TAO/tests/Sequence_Unit_Tests/bounded_object_reference_sequence_ut.cpp
index b5f94e10d26..c5fd630ab97 100644
--- a/TAO/tests/Sequence_Unit_Tests/bounded_object_reference_sequence_ut.cpp
+++ b/TAO/tests/Sequence_Unit_Tests/bounded_object_reference_sequence_ut.cpp
@@ -200,9 +200,9 @@ struct Tester
CHECK_THROW(tested_sequence y(x), testing_exception);
FAIL_RETURN_IF_NOT(a.expect(1), a);
FAIL_RETURN_IF_NOT(da.expect(0), da);
- FAIL_RETURN_IF_NOT(f.expect(0), f);
+ FAIL_RETURN_IF_NOT(f.expect(1), f);
FAIL_RETURN_IF_NOT(d.expect(8), d);
- FAIL_RETURN_IF_NOT(r.expect(0), r);
+ FAIL_RETURN_IF_NOT(r.expect(TMAX), r);
}
FAIL_RETURN_IF_NOT(d.expect(0), d);
FAIL_RETURN_IF_NOT(r.expect(TMAX), r);
diff --git a/TAO/tests/Sequence_Unit_Tests/string_sequence_tester.hpp b/TAO/tests/Sequence_Unit_Tests/string_sequence_tester.hpp
index b8665598d92..339c59ada80 100644
--- a/TAO/tests/Sequence_Unit_Tests/string_sequence_tester.hpp
+++ b/TAO/tests/Sequence_Unit_Tests/string_sequence_tester.hpp
@@ -377,9 +377,9 @@ struct string_sequence_tester
CHECK_THROW(tested_sequence y(x), testing_exception);
FAIL_RETURN_IF_NOT(a.expect(1), a);
- FAIL_RETURN_IF_NOT(f.expect(0), f);
+ FAIL_RETURN_IF_NOT(f.expect(1), f);
FAIL_RETURN_IF_NOT(d.expect(4), d);
- FAIL_RETURN_IF_NOT(r.expect(0), r);
+ FAIL_RETURN_IF_NOT(r.expect(x.maximum()), r);
}
FAIL_RETURN_IF_NOT(f.expect(1), f);
return 0;
@@ -420,13 +420,13 @@ struct string_sequence_tester
FAIL_RETURN_IF_NOT(d.expect(4), d);
FAIL_RETURN_IF_NOT(r.expect(y.maximum()), r);
- CHECK_EQUAL(CORBA::ULong(4), x.length());
- for(CORBA::ULong i = 0; i != 4; ++i)
+ CHECK_EQUAL(CORBA::ULong(8), y.length());
+ for(CORBA::ULong i = 0; i != 8; ++i)
{
FAIL_RETURN_IF_NOT(
- helper::compare_test_string(x[i]),
+ helper::compare_test_string(y[i]),
"Mismatch in element " << i
- << ", got=" << x[i]);
+ << ", got=" << y[i]);
}
}
FAIL_RETURN_IF_NOT(f.expect(1), f);
diff --git a/TAO/tests/Sequence_Unit_Tests/unbounded_object_reference_sequence_ut.cpp b/TAO/tests/Sequence_Unit_Tests/unbounded_object_reference_sequence_ut.cpp
index a3bf9bbd279..eee6e01f5e3 100644
--- a/TAO/tests/Sequence_Unit_Tests/unbounded_object_reference_sequence_ut.cpp
+++ b/TAO/tests/Sequence_Unit_Tests/unbounded_object_reference_sequence_ut.cpp
@@ -221,9 +221,9 @@ struct Tester
mock_reference::duplicate_calls.failure_countdown(8);
CHECK_THROW(tested_sequence y(x), testing_exception);
FAIL_RETURN_IF_NOT(a.expect(1), a);
- FAIL_RETURN_IF_NOT(f.expect(0), f);
+ FAIL_RETURN_IF_NOT(f.expect(1), f);
FAIL_RETURN_IF_NOT(d.expect(8), d);
- FAIL_RETURN_IF_NOT(r.expect(0), r);
+ FAIL_RETURN_IF_NOT(r.expect(l), r);
}
FAIL_RETURN_IF_NOT(d.expect(0), d);
FAIL_RETURN_IF_NOT(r.expect(l), r);