diff --git a/src/detail/coroutine_context.cpp b/src/detail/coroutine_context.cpp index d0807a2..f6a2d87 100644 --- a/src/detail/coroutine_context.cpp +++ b/src/detail/coroutine_context.cpp @@ -50,9 +50,14 @@ coroutine_context::coroutine_context( ctx_fn fn, stack_context * stack_ctx) : coroutine_context::coroutine_context( coroutine_context const& other) : stack_context( other), context::fcontext_t( other), - stack_ctx_( other.stack_ctx_), - ctx_( other.ctx_) -{} + stack_ctx_( this), ctx_( this) +{ + if ( & other != other.stack_ctx_) + { + stack_ctx_ = other.stack_ctx_; + ctx_ = other.ctx_; + } +} coroutine_context & coroutine_context::operator=( coroutine_context const& other) @@ -61,8 +66,11 @@ coroutine_context::operator=( coroutine_context const& other) stack_context::operator=( other); context::fcontext_t::operator=( other); - stack_ctx_ = other.stack_ctx_; - ctx_ = other.ctx_; + if ( & other != other.stack_ctx_) + { + stack_ctx_ = other.stack_ctx_; + ctx_ = other.ctx_; + } return * this; } diff --git a/test/test_coroutine.cpp b/test/test_coroutine.cpp index 270bcf1..414c653 100644 --- a/test/test_coroutine.cpp +++ b/test/test_coroutine.cpp @@ -95,7 +95,10 @@ public: struct my_exception {}; void f1( coro::coroutine< void >::push_type & c) -{ c(); } +{ + while ( c) + c(); +} void f2( coro::coroutine< void >::push_type &) { ++value1; } @@ -198,7 +201,7 @@ void f19( coro::coroutine< int* >::push_type & c, std::vector< int * > & vec) void f20( coro::coroutine< int >::push_type &) {} -#if 0 + void test_move() { { @@ -208,9 +211,11 @@ void test_move() BOOST_CHECK( coro1.empty() ); BOOST_CHECK( coro2); BOOST_CHECK( ! coro2.empty() ); + coro2(); coro1 = boost::move( coro2); BOOST_CHECK( coro1); BOOST_CHECK( ! coro1.empty() ); + coro1(); BOOST_CHECK( ! coro2); BOOST_CHECK( coro2.empty() ); } @@ -235,7 +240,7 @@ void test_move() BOOST_CHECK( value3); } } -#endif + void test_complete() { value1 = 0; @@ -538,7 +543,7 @@ boost::unit_test::test_suite * init_unit_test_suite( int, char* []) boost::unit_test::test_suite * test = BOOST_TEST_SUITE("Boost.coroutine: coroutine test suite"); -// test->add( BOOST_TEST_CASE( & test_move) ); + test->add( BOOST_TEST_CASE( & test_move) ); test->add( BOOST_TEST_CASE( & test_complete) ); test->add( BOOST_TEST_CASE( & test_jump) ); test->add( BOOST_TEST_CASE( & test_result_int) );