Skip to content

Commit

Permalink
Bug fix #5: parameters not passed by reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfjlaros committed Jul 20, 2019
1 parent 71ea0ab commit d1885f4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/rpcCall.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void _call(void (*)(void), Tuple<C*, void (P::*)(Tail...)> t, Args&... args) {
* @param args Parameter pack for @a f.
*/
template <class T, class... Tail, class F, class... Args>
void _call(void (*f_)(T, Tail...), F f, Args... args) {
void _call(void (*f_)(T, Tail...), F f, Args&... args) {
T data;

_read(&data);
Expand All @@ -70,7 +70,7 @@ void _call(void (*f_)(T, Tail...), F f, Args... args) {

// Parameter of type @a T&.
template <class T, class... Tail, class F, class... Args>
void _call(void (*f_)(T&, Tail...), F f, Args... args) {
void _call(void (*f_)(T&, Tail...), F f, Args&... args) {
T data;

_read(&data);
Expand Down
9 changes: 9 additions & 0 deletions tests/test_rpcCall.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ TEST_CASE("RPC call function with Vector types", "[call][vector]") {
return v;
}
static void f2(Object<Vector<int>, char>&) {}
static int f3(Vector<signed char>&, int i) {
return 1;
}
};

// Void function, parameter is of type Vector.
Expand All @@ -227,6 +230,12 @@ TEST_CASE("RPC call function with Vector types", "[call][vector]") {
rpcCall(S::f2);
REQUIRE(Serial.rx == sizeof(size_t) + 2 * sizeof(int) + sizeof(char));
REQUIRE(Serial.tx == 0);

Serial.reset();
Serial.prepare((size_t)2, (signed char)123, (signed char)234, 10);
rpcCall(S::f3);
REQUIRE(Serial.rx == sizeof(size_t) + 2 * sizeof(signed char) + sizeof(int));
REQUIRE(Serial.tx == sizeof(int));
}

TEST_CASE("RPC call class member functions", "[call][class]") {
Expand Down
2 changes: 2 additions & 0 deletions tests/test_signature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ TEST_CASE("Objects", "[signature][object]") {
TEST_CASE("Vectors", "[signature][vector]") {
void (*f0)(Vector<int>, float);
Vector<int> (*f1)(float);
int (*f2)(Vector<signed char>&, int);

REQUIRE(signature(f0) == ": [i] f");
REQUIRE(signature(f1) == "[i]: f");
REQUIRE(signature(f2) == "i: [b] i");
}

0 comments on commit d1885f4

Please sign in to comment.