aboutgitcodelistschat:MatrixIRC
diff options
context:
space:
mode:
-rw-r--r--actions.c12
-rw-r--r--gluten.h2
-rw-r--r--tests/unit/test_actions.c22
3 files changed, 11 insertions, 25 deletions
diff --git a/actions.c b/actions.c
index 6a7f55c..bb603af 100644
--- a/actions.c
+++ b/actions.c
@@ -211,14 +211,12 @@ int do_actions(void *data, struct action actions[], unsigned int n_actions, int
resp.id = id;
resp.flags = 0;
resp.error = 0;
- if (actions[i].ret.type == IMMEDIATE) {
+ if (actions[i].ret.type == IMMEDIATE)
resp.val = actions[i].ret.value;
- } else if (actions[i].ret.value_p != NULL) {
- resp.val = *(actions[i].ret.value_p);
- } else {
- fprintf(stderr, "empty reference for the return value");
- return -1;
- }
+ else
+ memcpy(&resp.val, (uint16_t *)data +
+ actions[i].ret.value_off,
+ sizeof(resp.val));
if (send_target(&resp, notifyfd) == -1)
return -1;
diff --git a/gluten.h b/gluten.h
index c004220..760f82b 100644
--- a/gluten.h
+++ b/gluten.h
@@ -77,7 +77,7 @@ struct act_return {
enum value_type type;
union {
int64_t value;
- int64_t *value_p;
+ uint16_t value_off;
};
};
diff --git a/tests/unit/test_actions.c b/tests/unit/test_actions.c
index 2bf92d4..e648063 100644
--- a/tests/unit/test_actions.c
+++ b/tests/unit/test_actions.c
@@ -253,33 +253,22 @@ END_TEST
START_TEST(test_act_return_ref)
{
int64_t v = 2;
+ uint16_t offset = 4;
struct action actions[] = {
{
.type = A_RETURN,
- .ret = { .type = REFERENCE, .value_p = &v },
+ .ret = { .type = REFERENCE, .value_off = offset },
},
};
- int ret = do_actions(NULL, actions, sizeof(actions) / sizeof(actions[0]), -1,
+ memcpy((uint16_t *)&tmp_data + offset, &v, sizeof(v));
+
+ int ret = do_actions(&tmp_data, actions, sizeof(actions) / sizeof(actions[0]), -1,
notifyfd, req.id);
ck_assert_msg(ret == 0, strerror(errno));
check_target_result(v, 0, false);
}
END_TEST
-START_TEST(test_act_return_empty_ref)
-{
- struct action actions[] = {
- {
- .type = A_RETURN,
- .ret = { .type = REFERENCE, .value_p = NULL },
- },
- };
- int ret = do_actions(NULL, actions, sizeof(actions) / sizeof(actions[0]), -1,
- notifyfd, req.id);
- ck_assert_int_eq(ret, -1);
-}
-END_TEST
-
START_TEST(test_act_call)
{
struct action actions[] = {
@@ -365,7 +354,6 @@ Suite *action_call_suite(void)
tcase_set_timeout(ret, timeout);
tcase_add_test(ret, test_act_return);
tcase_add_test(ret, test_act_return_ref);
- tcase_add_test(ret, test_act_return_empty_ref);
suite_add_tcase(s, ret);
block = tcase_create("a_block");