Skip to content

Commit

Permalink
libflux/future: convert void * to const void **
Browse files Browse the repository at this point in the history
In flux_future_get, convert void * parameter to void ** parameter,
consistent to fixes done in flux-framework#1144 and flux-framework#1212.

Fixes flux-framework#1602
  • Loading branch information
chu11 committed Jul 27, 2018
1 parent 677910a commit 5ed0446
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 39 deletions.
2 changes: 1 addition & 1 deletion doc/man3/flux_future_get.adoc
Expand Up @@ -14,7 +14,7 @@ SYNOPSIS

typedef void (*flux_continuation_f)(flux_future_t *f, void *arg);

int flux_future_get (flux_future_t *f, void *result);
int flux_future_get (flux_future_t *f, const void **result);

int flux_future_then (flux_future_t *f, double timeout,
flux_continuation_f cb, void *arg);
Expand Down
2 changes: 1 addition & 1 deletion src/common/libflux/composite_future.c
Expand Up @@ -237,7 +237,7 @@ static void fulfill_next (flux_future_t *f, flux_future_t *next)
*/
flux_future_aux_set (next, NULL, f, (flux_free_f) flux_future_destroy);

if (flux_future_get (f, &result) < 0)
if (flux_future_get (f, (const void **)&result) < 0)
flux_future_fulfill_error (next, errno, NULL);
else
flux_future_fulfill (next, result, NULL);
Expand Down
4 changes: 2 additions & 2 deletions src/common/libflux/future.c
Expand Up @@ -500,7 +500,7 @@ bool flux_future_is_ready (flux_future_t *f)
/* Block until future is fulfilled if not already.
* Then return either result or error depending on how it was fulfilled.
*/
int flux_future_get (flux_future_t *f, void *result)
int flux_future_get (flux_future_t *f, const void **result)
{
if (flux_future_wait_for (f, -1.0) < 0) // no timeout
return -1;
Expand All @@ -515,7 +515,7 @@ int flux_future_get (flux_future_t *f, void *result)
}
else {
if (result)
*(void **)result = f->result.value;
(*result) = f->result.value;
}
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/common/libflux/future.h
Expand Up @@ -41,7 +41,7 @@ typedef void (*flux_future_init_f)(flux_future_t *f, void *arg);

flux_future_t *flux_future_create (flux_future_init_f cb, void *arg);

int flux_future_get (flux_future_t *f, void *result);
int flux_future_get (flux_future_t *f, const void **result);

void flux_future_fulfill (flux_future_t *f, void *result, flux_free_f free_fn);
void flux_future_fulfill_error (flux_future_t *f, int errnum, const char *errstr);
Expand Down
6 changes: 3 additions & 3 deletions src/common/libflux/rpc.c
Expand Up @@ -95,7 +95,7 @@ int flux_rpc_get (flux_future_t *f, const char **s)
const flux_msg_t *msg;
int rc = -1;

if (flux_future_get (f, &msg) < 0)
if (flux_future_get (f, (const void **)&msg) < 0)
goto done;
if (flux_response_decode (msg, NULL, s) < 0)
goto done;
Expand All @@ -109,7 +109,7 @@ int flux_rpc_get_raw (flux_future_t *f, const void **data, int *len)
const flux_msg_t *msg;
int rc = -1;

if (flux_future_get (f, &msg) < 0)
if (flux_future_get (f, (const void **)&msg) < 0)
goto done;
if (flux_response_decode_raw (msg, NULL, data, len) < 0)
goto done;
Expand All @@ -123,7 +123,7 @@ static int flux_rpc_get_vunpack (flux_future_t *f, const char *fmt, va_list ap)
const flux_msg_t *msg;
int rc = -1;

if (flux_future_get (f, &msg) < 0)
if (flux_future_get (f, (const void **)&msg) < 0)
goto done;
if (flux_msg_vunpack (msg, fmt, ap) < 0)
goto done;
Expand Down
24 changes: 12 additions & 12 deletions src/common/libflux/test/composite_future.c
Expand Up @@ -146,10 +146,10 @@ static void test_composite_basic_all (flux_reactor_t *r)

static void step1_or (flux_future_t *f, void *arg)
{
void * result;
const void *result;
char *str = arg;
/* or_then handler -- future `f` must have been fulfilled with error */
ok (flux_future_get (f, &result) < 0,
ok (flux_future_get (f, (const void **)&result) < 0,
"chained: step1 or_then: flux_future_get returns failure");
strcat (str, "-step1_or");

Expand All @@ -162,9 +162,9 @@ static void step1_or (flux_future_t *f, void *arg)

static void step2 (flux_future_t *f, void *arg)
{
void * result;
const void *result;
char *str = arg;
ok (flux_future_get (f, &result) == 0,
ok (flux_future_get (f, (const void **)&result) == 0,
"chained: step2: flux_future_get returns success");
strcat (str, "-step2");
flux_future_t *next = flux_future_create (NULL, NULL);
Expand All @@ -175,9 +175,9 @@ static void step2 (flux_future_t *f, void *arg)

static void step2_err (flux_future_t *f, void *arg)
{
void * result;
const void *result;
char *str = arg;
ok (flux_future_get (f, &result) == 0,
ok (flux_future_get (f, (const void **)&result) == 0,
"chained: step2: flux_future_get returns success");
strcat (str, "-step2_err");
flux_future_continue_error (f, 123);
Expand All @@ -186,9 +186,9 @@ static void step2_err (flux_future_t *f, void *arg)

static void step3 (flux_future_t *f2, void *arg)
{
void * result;
const void *result;
char *str = arg;
ok (flux_future_get (f2, &result) == 0,
ok (flux_future_get (f2, (const void **)&result) == 0,
"chained: step3: flux_future_get returns success");
strcat (str, "-step3");
flux_future_t *next = flux_future_create (NULL, NULL);
Expand Down Expand Up @@ -472,12 +472,12 @@ void f_strdup_init (flux_future_t *f, void *arg)

void f_strcat (flux_future_t *prev, void *arg)
{
char *result = NULL;
const char *result = NULL;
char *next = NULL;
char *append = arg;
flux_future_t *f;

ok (flux_future_get (prev, (void *)&result) == 0,
ok (flux_future_get (prev, (const void **)&result) == 0,
"flux_future_get (prev) worked");
if (asprintf (&next, "%s%s", result, append) < 0)
BAIL_OUT ("f_strcat: asprintf: %s", strerror (errno));
Expand All @@ -491,11 +491,11 @@ void f_strcat (flux_future_t *prev, void *arg)

void chained_async_cb (flux_future_t *f, void *arg)
{
char *result;
const char *result;
const char *expected = arg;
ok (flux_future_is_ready (f),
"chained_async_cb: future is ready");
ok (flux_future_get (f, (void *) &result) == 0,
ok (flux_future_get (f, (const void **) &result) == 0,
"chained_async_cb: flux_future_get worked");
is (result, expected,
"chained_async_cb: got expected result");
Expand Down
35 changes: 18 additions & 17 deletions src/common/libflux/test/future.c
Expand Up @@ -25,7 +25,7 @@ void result_destroy (void *arg)
}

int contin_called;
void *contin_arg;
const void *contin_arg;
int contin_get_rc;
flux_reactor_t *contin_reactor;
flux_t *contin_flux;
Expand All @@ -36,7 +36,7 @@ void contin (flux_future_t *f, void *arg)
contin_arg = arg;
contin_flux = flux_future_get_flux (f);
contin_reactor = flux_future_get_reactor (f);
contin_get_rc = flux_future_get (f, &contin_get_result);
contin_get_rc = flux_future_get (f, (const void **)&contin_get_result);
}

void test_simple (void)
Expand Down Expand Up @@ -105,7 +105,7 @@ void test_simple (void)
ok (!flux_future_is_ready (f),
"flux_future_is_ready returns false");
errno = 0;
void *result = NULL;
const void *result = NULL;
result_destroy_called = 0;
result_destroy_arg = NULL;
flux_future_fulfill (f, "Hello", result_destroy);
Expand Down Expand Up @@ -244,7 +244,7 @@ void simple_init (flux_future_t *f, void *arg)
void test_init_now (void)
{
flux_future_t *f;
char *result;
const char *result;

f = flux_future_create (simple_init, "testarg");
ok (f != NULL,
Expand All @@ -255,7 +255,7 @@ void test_init_now (void)
simple_init_arg = NULL;
simple_init_r = NULL;
result = NULL;
ok (flux_future_get (f, &result) == 0,
ok (flux_future_get (f, (const void **)&result) == 0,
"flux_future_get worked");
ok (result != NULL && !strcmp (result, "Result!"),
"and correct result was returned");
Expand All @@ -270,13 +270,13 @@ void test_init_now (void)
diag ("%s: init works in synchronous context", __FUNCTION__);
}

char *simple_contin_result;
const char *simple_contin_result;
int simple_contin_called;
int simple_contin_rc;
void simple_contin (flux_future_t *f, void *arg)
{
simple_contin_called++;
simple_contin_rc = flux_future_get (f, &simple_contin_result);
simple_contin_rc = flux_future_get (f, (const void **)&simple_contin_result);
}

void test_init_then (void)
Expand Down Expand Up @@ -358,24 +358,25 @@ flux_future_t *mumble_create (void)
int fclass_contin_rc;
void fclass_contin (flux_future_t *f, void *arg)
{
fclass_contin_rc = flux_future_get (f, arg);
const void **result = arg;
fclass_contin_rc = flux_future_get (f, result);
}

void test_fclass_synchronous (char *tag, flux_future_t *f, const char *expected)
{
char *s;
const char *s;

ok (flux_future_wait_for (f, -1.) == 0,
"%s: flux_future_wait_for returned successfully", tag);
ok (flux_future_get (f, &s) == 0 && s != NULL && !strcmp (s, expected),
ok (flux_future_get (f, (const void **)&s) == 0 && s != NULL && !strcmp (s, expected),
"%s: flux_future_get worked", tag);
}

void test_fclass_asynchronous (char *tag,
flux_future_t *f, const char *expected)
{
flux_reactor_t *r;
char *s;
const char *s;

r = flux_reactor_create (0);
if (!r)
Expand Down Expand Up @@ -824,7 +825,7 @@ void test_multiple_fulfill (void)
{
flux_reactor_t *r;
flux_future_t *f;
void *result;
const void *result;

if (!(r = flux_reactor_create (0)))
BAIL_OUT ("flux_reactor_create failed");
Expand All @@ -840,31 +841,31 @@ void test_multiple_fulfill (void)
flux_future_fulfill (f, "baz", NULL);

result = NULL;
ok (flux_future_get (f, &result) == 0
ok (flux_future_get (f, (const void **)&result) == 0
&& result
&& !strcmp (result, "foo"),
"flux_future_get gets fulfillment");
flux_future_reset (f);

ok (flux_future_get (f, &result) < 0
ok (flux_future_get (f, (const void **)&result) < 0
&& errno == ENOENT,
"flux_future_get gets queued ENOENT error");
flux_future_reset (f);

result = NULL;
ok (flux_future_get (f, &result) == 0
ok (flux_future_get (f, (const void **)&result) == 0
&& result
&& !strcmp (result, "bar"),
"flux_future_get gets queued fulfillment");
flux_future_reset (f);

ok (flux_future_get (f, &result) < 0
ok (flux_future_get (f, (const void **)&result) < 0
&& errno == EPERM,
"flux_future_get gets queued EPERM error");
flux_future_reset (f);

result = NULL;
ok (flux_future_get (f, &result) == 0
ok (flux_future_get (f, (const void **)&result) == 0
&& result
&& !strcmp (result, "baz"),
"flux_future_get gets queued fulfillment");
Expand Down
2 changes: 1 addition & 1 deletion src/common/libkvs/kvs_watch.c
Expand Up @@ -323,7 +323,7 @@ static int kvs_watch_rpc_get_matchtag (flux_future_t *f, uint32_t *matchtag)
uint32_t tag;
const flux_msg_t *msg;

if (flux_future_get (f, &msg) < 0)
if (flux_future_get (f, (const void **)&msg) < 0)
return -1;
if (flux_msg_get_matchtag (msg, &tag) < 0)
return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/wreck/job.c
Expand Up @@ -574,7 +574,7 @@ static void cmb_exec_cb (flux_future_t *f, void *arg)
flux_t *h = flux_future_get_flux (f);
struct wreck_job *job = arg;

if (flux_future_get (f, &msg) < 0) {
if (flux_future_get (f, (const void **)&msg) < 0) {
flux_log_error (h, "cmb_exec_cb: flux_future_get");
flux_future_destroy (f);
return;
Expand Down

0 comments on commit 5ed0446

Please sign in to comment.