Skip to content

Commit b0cab1d

Browse files
authored
Fix move ownership in C++ API (#59)
1 parent ef9675b commit b0cab1d

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

Diff for: src/rt/cpp/when.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ namespace verona::cpp
140140
template<typename T>
141141
auto convert_access(cown_ptr<T>&& c)
142142
{
143-
return Access<T>(c);
143+
return Access<T>(std::move(c));
144144
}
145145

146146
template<typename T>

Diff for: src/rt/sched/behaviourcore.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -824,12 +824,13 @@ namespace verona::rt
824824
// If the body is the same, then we have an overlap within a single
825825
// behaviour.
826826
auto body_next = bodies[std::get<0>(cown_to_behaviour_slot_map[i])];
827+
828+
// Check if the caller passed an RC and add to the total.
829+
transfer_count +=
830+
std::get<1>(cown_to_behaviour_slot_map[i])->is_move();
831+
827832
if (body_next == body)
828833
{
829-
// Check if the caller passed an RC and add to the total.
830-
transfer_count +=
831-
std::get<1>(cown_to_behaviour_slot_map[i])->is_move();
832-
833834
Logging::cout() << "Duplicate " << cown << " for " << body
834835
<< " Index " << i << Logging::endl;
835836
// We need to reduce the execution count by one, as we can't wait

Diff for: test/func/when-transfer/transfer.cc

+18-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void test_sched_many_move()
6464
Logging::cout() << "test_body()" << Logging::endl;
6565

6666
auto log1 = make_cown<Body>();
67-
auto log2 = cown_ptr<Body>(log1);
67+
auto log2 = make_cown<Body>();
6868

6969
(when(std::move(log1)) <<
7070
[=](auto) { Logging::cout() << "log" << Logging::endl; }) +
@@ -77,7 +77,7 @@ void test_sched_many_move_busy()
7777
Logging::cout() << "test_body()" << Logging::endl;
7878

7979
auto log1 = make_cown<Body>();
80-
auto log2 = cown_ptr<Body>(log1);
80+
auto log2 = make_cown<Body>();
8181

8282
when(log1) << [=](auto) { Logging::cout() << "log" << Logging::endl; };
8383
(when(std::move(log1)) <<
@@ -91,7 +91,7 @@ void test_sched_many_mixed()
9191
Logging::cout() << "test_body()" << Logging::endl;
9292

9393
auto log1 = make_cown<Body>();
94-
auto log2 = cown_ptr<Body>(log1);
94+
auto log2 = make_cown<Body>();
9595

9696
(when(log1) << [=](auto) { Logging::cout() << "log" << Logging::endl; }) +
9797
(when(std::move(log2)) <<
@@ -103,14 +103,27 @@ void test_sched_many_mixed_busy()
103103
Logging::cout() << "test_body()" << Logging::endl;
104104

105105
auto log1 = make_cown<Body>();
106-
auto log2 = cown_ptr<Body>(log1);
106+
auto log2 = make_cown<Body>();
107107

108108
when(log1) << [=](auto) { Logging::cout() << "log" << Logging::endl; };
109109
(when(log1) << [=](auto) { Logging::cout() << "log" << Logging::endl; }) +
110110
(when(std::move(log2)) <<
111111
[=](auto) { Logging::cout() << "log" << Logging::endl; });
112112
}
113113

114+
void test_sched_many_move_same()
115+
{
116+
Logging::cout() << "test_body()" << Logging::endl;
117+
118+
auto log1 = make_cown<Body>();
119+
auto log2 = cown_ptr<Body>(log1);
120+
121+
(when(std::move(log1)) <<
122+
[=](auto) { Logging::cout() << "log" << Logging::endl; }) +
123+
(when(std::move(log2)) <<
124+
[=](auto) { Logging::cout() << "log" << Logging::endl; });
125+
}
126+
114127
int main(int argc, char** argv)
115128
{
116129
SystematicTestHarness harness(argc, argv);
@@ -123,6 +136,7 @@ int main(int argc, char** argv)
123136
harness.run(test_sched_many_move_busy);
124137
harness.run(test_sched_many_mixed);
125138
harness.run(test_sched_many_mixed_busy);
139+
harness.run(test_sched_many_move_same);
126140

127141
return 0;
128142
}

0 commit comments

Comments
 (0)