[shifted_ptr][3.1] Works fine

Ok, I just uploaded a version that finally works fine. At this point I would doubt there is any bugs left in its functionality. Thanks, -Phil

AMDG Phil Bouchard wrote:
Ok,
I just uploaded a version that finally works fine. At this point I would doubt there is any bugs left in its functionality.
I'm attaching a program that tests everything that I've thought of so far that might go wrong. BTW, any chance that you could use the svn sandbox? It would be easier for me to update rather than having to get the old files out of the way and then download and unzip the new version. In Christ, Steven Watanabe #include <boost/shifted_ptr.hpp> #include <vector> #include <iostream> #include <boost/mpl/range_c.hpp> #include <boost/mpl/for_each.hpp> #include <boost/array.hpp> #define BOOST_TEST_MAIN #include <boost/test/unit_test.hpp> static int count; using boost::shifted_ptr; using boost::new_sh; struct node { node() { ++count; } ~node() { --count; } node(const node&) { ++count; } shifted_ptr<node> prior; shifted_ptr<node> next; }; struct list { public: list() {} void clear() { front.reset(); back.reset(); } void insert() { if(front.get() == 0) { front = back = new_sh<node>(); } else { back->next = new_sh<node>(); back->next->prior = back; back = back->next; } } private: shifted_ptr<node> front; shifted_ptr<node> back; }; struct vector { vector() { ++count; } ~vector() { --count; } vector(const vector& other) : elements(other.elements) { ++count; } std::vector<shifted_ptr<vector> > elements; }; struct create_type { template<class T> void operator()(T) const { new_sh<boost::array<char, T::value> >(); } }; BOOST_AUTO_TEST_CASE(test_shifted_ptr) { { shifted_ptr<vector> v = new_sh<vector>(); v->elements.push_back(v); } BOOST_CHECK_EQUAL(count, 0); count = 0; { list l; for(int j = 0; j < 2; ++j) { for(int i = 0; i < 2; ++i) { l.insert(); } l.clear(); } std::cout << count << std::endl; } BOOST_CHECK_EQUAL(count, 0); count = 0; { shifted_ptr<int> test = new_sh<int>(5); test = test; BOOST_CHECK_NE(test.get(), static_cast<int*>(0)); BOOST_CHECK_EQUAL(*test, 5); } for(int i = 0; i < 500; ++i) { boost::mpl::for_each<boost::mpl::range_c<int, 1, 100> >(create_type()); } { shifted_ptr<vector> v = new_sh<vector>(); v->elements.push_back(v); } BOOST_CHECK_EQUAL(count, 0); count = 0; { vector v; v.elements.push_back(new_sh<vector>()); } BOOST_CHECK_EQUAL(count, 0); count = 0; }

"Steven Watanabe" <watanabesj@gmail.com> wrote in message news:48178864.1040602@providere-consulting.com... [...]
I'm attaching a program that tests everything that I've thought of so far that might go wrong.
BTW, any chance that you could use the svn sandbox? It would be easier for me to update rather than having to get the old files out of the way and then download and unzip the new version.
I'll do that today. The last corrections are on Vault. -Phil

"Steven Watanabe" <watanabesj@gmail.com> wrote in message news:48178864.1040602@providere-consulting.com... [...]
BTW, any chance that you could use the svn sandbox? It would be easier for me to update rather than having to get the old files out of the way and then download and unzip the new version.
Sorry for the delay. I had a file using an unrecognized extension that was creating a lot of trouble and postponed utterly my submission. -Phil

"Steven Watanabe" <watanabesj@gmail.com> wrote in message news:48178864.1040602@providere-consulting.com...
{ shifted_ptr<vector> v = new_sh<vector>(); v->elements.push_back(v); } BOOST_CHECK_EQUAL(count, 0);
[...] I apologize for the late reply, I was having issues with my installation. I switched the environment and finally had a chance to check it out. The text mentionned against shows the undefined behavior of shifted_ptr when used with STL containers. STL containers use global operator new for allocation and shifted_ptr will therefore not be able to distinguish the heap section from the stack section. There are various solutions for this problem and I am currently working on one that should be more reliable and portable. -Phil
participants (2)
-
Phil Bouchard
-
Steven Watanabe