summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ACE/ChangeLog14
-rw-r--r--ACE/THANKS3
-rw-r--r--ACE/ace/Vector_T.cpp55
-rw-r--r--ACE/ace/Vector_T.inl19
-rw-r--r--ACE/tests/Vector_Test.cpp42
5 files changed, 87 insertions, 46 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog
index 8bb6d5df6cd..1c72859ec00 100644
--- a/ACE/ChangeLog
+++ b/ACE/ChangeLog
@@ -1,3 +1,17 @@
+Wed Nov 21 21:43:54 UTC 2007 Douglas C. Schmidt <schmidt@dre.vanderbilt.edu>
+
+ * ace/Vector_T.inl (advance):
+ * ace/Vector_T.cpp: Fixed the push_back() and pop_back() methods
+ so they work properly after resizing. Thanks to Karl-Heinz Wind
+ <wind at itq dot de> for these fixes.
+
+Wed Nov 21 21:36:27 UTC 2007 Douglas C. Schmidt <schmidt@dre.vanderbilt.edu>
+
+ * tests/Vector_Test.cpp (run_main): Updated the test so that it
+ checks for the buggy push_back() and pop_back(). Thanks to
+ Karl-Heinz Wind <wind at itq dot de> for providing these
+ enhancements.
+
Wed Nov 21 19:37:29 UTC 2007 Douglas C. Schmidt <schmidt@dre.vanderbilt.edu>
* examples/Reactor/Ntalker/ntalker.cpp (ACE_TMAIN):
diff --git a/ACE/THANKS b/ACE/THANKS
index 5d19ebf5fb0..9a06eb2ac67 100644
--- a/ACE/THANKS
+++ b/ACE/THANKS
@@ -70,6 +70,7 @@ Emre Turkay <turkaye at dre dot vanderbilt dot edu>
Nanbor Wang <nanbor at cs dot wustl dot edu>
Seth Widoff <sbw1 at cs dot wustl dot edu>
Jules White <jules at dre dot vanderbilt dot edu>
+Friedhelm Wolf <fwolf at dre dot vanderbilt dot edu>
Torben Worm <tworm at cs dot wustl dot edu>
Ming Xiong <xiongm at isis dot vanderbilt dot edu>
@@ -2007,7 +2008,6 @@ Steven T. Hatton <hattons at globalsymmetry dot com>
Yevgen Galchenko <yevgeng at softcomputer dot com>
Timothy Wayne Gomez <gomezt at saic dot com>
Ventimiglia Chere <Ventimiglia_Chere at emc dot com>
-Friedhelm Wolf <fwolf at dre dot vanderbilt dot edu>
Frederick Heckel <fwph at cse dot wustl dot edu>
Ian Zagorskih <ianzag at megasignal dot com>
Olivier Guérin <guerin35 at hotmail dot com>
@@ -2228,6 +2228,7 @@ Alex Solan <alex dot solan at gmail dot com>
Venkat Sidhabathuni <venkats at idengines dot com>
Nathan Ernst <Nathan dot Ernst at citadelgroup dot com>
Kun Niu <haoniukun at gmail dot com>
+Karl-Heinz Wind <wind at itq dot de>
I would particularly like to thank Paul Stephenson, who worked with me
at Ericsson in the early 1990's. Paul devised the recursive Makefile
diff --git a/ACE/ace/Vector_T.cpp b/ACE/ace/Vector_T.cpp
index adf9727c6ff..d66abd411ac 100644
--- a/ACE/ace/Vector_T.cpp
+++ b/ACE/ace/Vector_T.cpp
@@ -38,6 +38,9 @@ void ACE_Vector<T, DEFAULT_SIZE>::push_back (const T& elem)
ACE_Array<T>::size (curr_max_size_ * 2);
curr_max_size_ = this->max_size ();
}
+ else
+ ACE_Array<T>::size (length_ + 1);
+
++length_;
(*this)[length_-1] = elem;
}
@@ -82,29 +85,20 @@ int compare(const ACE_Vector<T>& v1,
size_t last1 = v1.size () - 1;
size_t last2 = v2.size () - 1;
if (last1 < from_ndx || last1 < to_ndx)
- {
- return false;
- }
+ return false;
if (last2 < from_ndx || last2 < to_ndx)
- {
- return false;
- }
+ return false;
if (last1 != last2)
- {
- return false;
- }
+ return false;
// cout<<"compare() <================="<<endl;
for (size_t i = from_ndx; i <= to_ndx; ++i)
- {
- // cout<<"V1["<<i<<"]="<<v1[i];
- // cout<<", V2["<<i<<"]="<<v2[i];
- // cout<<": NOT EQUAL == "<<(v1[i]!=v2[i])<<endl;
- if (v1[i] != v2[i])
- {
- return false;
- }
- }
+ // cout<<"V1["<<i<<"]="<<v1[i];
+ // cout<<", V2["<<i<<"]="<<v2[i];
+ // cout<<": NOT EQUAL == "<<(v1[i]!=v2[i])<<endl;
+ if (v1[i] != v2[i])
+ return false;
+
// cout<<"compare() ====================>"<<endl;
return true;
}
@@ -117,25 +111,20 @@ int partial_compare(const ACE_Vector<T>& v1,
{
size_t last1 = v1.size () - 1;
size_t last2 = v2.size () - 1;
+
if (last1 < from_ndx || last1 < to_ndx)
- {
- return false;
- }
+ return false;
if (last2 < from_ndx || last2 < to_ndx)
- {
- return false;
- }
+ return false;
+
// cout<<"partial_compare() <================="<<endl;
for (size_t i = from_ndx; i <= to_ndx; ++i)
- {
- // cout<<"V1["<<i<<"]="<<v1[i];
- // cout<<", V2["<<i<<"]="<<v2[i];
- // cout<<": NOT EQUAL == "<<(v1[i]!=v2[i])<<endl;
- if (v1[i] != v2[i])
- {
- return false;
- }
- }
+ // cout<<"V1["<<i<<"]="<<v1[i];
+ // cout<<", V2["<<i<<"]="<<v2[i];
+ // cout<<": NOT EQUAL == "<<(v1[i]!=v2[i])<<endl;
+ if (v1[i] != v2[i])
+ return false;
+
// cout<<"partial_compare() ====================>"<<endl;
return true;
}
diff --git a/ACE/ace/Vector_T.inl b/ACE/ace/Vector_T.inl
index f9388daf619..4a791e46065 100644
--- a/ACE/ace/Vector_T.inl
+++ b/ACE/ace/Vector_T.inl
@@ -9,10 +9,10 @@ ACE_BEGIN_VERSIONED_NAMESPACE_DECL
template <class T, size_t DEFAULT_SIZE> ACE_INLINE
ACE_Vector<T, DEFAULT_SIZE>::ACE_Vector (const size_t init_size,
ACE_Allocator* alloc)
- : ACE_Array<T> (init_size == 0 ? DEFAULT_SIZE : init_size, alloc)
+ : ACE_Array<T> (init_size == 0 ? DEFAULT_SIZE : init_size, alloc),
+ length_ (0),
+ curr_max_size_ (max_size ());
{
- length_ = 0;
- curr_max_size_ = this->max_size ();
}
template <class T, size_t DEFAULT_SIZE> ACE_INLINE
@@ -42,7 +42,10 @@ template <class T, size_t DEFAULT_SIZE> ACE_INLINE
void ACE_Vector<T, DEFAULT_SIZE>::pop_back (void)
{
if (length_ > 0)
- --length_;
+ {
+ --length_;
+ ACE_Array<T>::size (length_);
+ }
}
// Compare this vector with <s> for inequality.
@@ -61,7 +64,6 @@ ACE_Vector<T, DEFAULT_SIZE>::swap (ACE_Vector &rhs)
std::swap (this->curr_max_size_, rhs.curr_max_size_);
}
-
// ****************************************************************
template <class T, size_t DEFAULT_SIZE> ACE_INLINE void
@@ -89,10 +91,8 @@ ACE_Vector_Iterator<T, DEFAULT_SIZE>::advance (void)
return 1;
}
else
- {
- // Already finished iterating.
- return 0;
- }
+ // Already finished iterating.
+ return 0;
}
template <class T, size_t DEFAULT_SIZE> ACE_INLINE int
@@ -104,3 +104,4 @@ ACE_Vector_Iterator<T, DEFAULT_SIZE>::done (void) const
}
ACE_END_VERSIONED_NAMESPACE_DECL
+
diff --git a/ACE/tests/Vector_Test.cpp b/ACE/tests/Vector_Test.cpp
index 1d0933d73eb..3866094c62b 100644
--- a/ACE/tests/Vector_Test.cpp
+++ b/ACE/tests/Vector_Test.cpp
@@ -12,7 +12,8 @@
// This is a simple test of the ACE_Vector class and its iterators.
//
// = AUTHOR
-// Gonzalo A. Diethelm <gonzalo.diethelm@aditiva.com>
+// Gonzalo A. Diethelm <gonzalo.diethelm@aditiva.com> and
+// Karl-Heinz Wind <wind@itq.de>
//
// ============================================================================
@@ -37,6 +38,9 @@ const size_t TOP = 100;
const size_t LEFT = 10;
const size_t RESIZE = 20;
+const size_t FILLER1 = 1;
+const size_t FILLER2 = 2;
+
int run_main (int, ACE_TCHAR *[])
{
ACE_START_TEST (ACE_TEXT ("Vector_Test"));
@@ -107,8 +111,8 @@ int run_main (int, ACE_TCHAR *[])
ACE_ASSERT (vector[i] == 0);
}
ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("vector[%d]:%d\n"),
- i, vector[i]));
+ ACE_TEXT ("vector[%d]:%d\n"),
+ i, vector[i]));
}
vector.clear ();
@@ -117,6 +121,37 @@ int run_main (int, ACE_TCHAR *[])
ACE_TEXT ("Size: %d\n"),
vector.size ()));
+ // test resize (shrink and enlarge with buffer realloc)
+ VECTOR vector2;
+
+ // should be around 32
+ size_t boundary = vector2.capacity ();
+
+ // we fill everything up with 1
+ // 1, 1, 1, 1, 1, 1, 1, 1,
+ // 1, 1, 1, 1, 1, 1, 1, 1,
+ // 1, 1, 1, 1, 1, 1, 1, 1,
+ // 1, 1, 1, 1, 1, 1, 1, 1,
+ for (i = 0; i < boundary; ++i)
+ vector2.push_back (FILLER1);
+
+ // we throw almost everything away.
+ vector2.resize (1, 0);
+
+ // we fill up with another pattern
+ // 1, 2, 2, 2, 2, 2, 2, 2,
+ // 2, 2, 2, 2, 2, 2, 2, 2,
+ // 2, 2, 2, 2, 2, 2, 2, 2,
+ // 2, 2, 2, 2, 2, 2, 2, 2,
+ // 2,
+ for (i = 0; i < boundary; ++i)
+ vector2.push_back (FILLER2);
+
+ // now we check the result
+ ACE_ASSERT (vector2[0] == FILLER1);
+ for (i = 0; i < boundary; ++i)
+ ACE_ASSERT (vector2[i+1] == FILLER2);
+
VECTOR v1;
VECTOR v2;
v1.push_back (1);
@@ -141,3 +176,4 @@ int run_main (int, ACE_TCHAR *[])
return 0;
}
+