Skip to content

Commit

Permalink
libflux: convert some params to const
Browse files Browse the repository at this point in the history
Problem: flux_msg_get_payload() accepts a a void **
argument that is set to point to the message payload,
but the payload belongs to the const flux_msg_t passed
in as another argument.

Make the payload pointer 'const'.

The following functions, based on the above, are
similarly updated:

flux_request_decode_raw()
flux_response_decode_raw()
flux_rpc_get_raw()
flux_mrpc_get_raw()
flux_content_load_get()

Finally, all users of the above functions are updated.

And a libutil function writeall() parameter was changed
to const as well, since flux-content was using it on
payload returned from flux_content_load_get(), and
anyway it was appropriate there.

Fixes flux-framework#1211
  • Loading branch information
garlick committed Sep 27, 2017
1 parent 6486563 commit 276a14a
Show file tree
Hide file tree
Showing 24 changed files with 44 additions and 42 deletions.
6 changes: 3 additions & 3 deletions src/broker/content-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ static void cache_load_continuation (flux_future_t *f, void *arg)
{
content_cache_t *cache = arg;
struct cache_entry *e = flux_future_aux_get (f, "entry");
void *data = NULL;
const void *data = NULL;
int len = 0;
int saved_errno;
int rc = -1;
Expand Down Expand Up @@ -359,7 +359,7 @@ void content_load_request (flux_t *h, flux_msg_handler_t *w,
int saved_errno = 0;
int rc = -1;

if (flux_request_decode_raw (msg, NULL, (void **)&blobref,
if (flux_request_decode_raw (msg, NULL, (const void **)&blobref,
&blobref_size) < 0) {
saved_errno = errno;
goto done;
Expand Down Expand Up @@ -518,7 +518,7 @@ static void content_store_request (flux_t *h, flux_msg_handler_t *w,
const flux_msg_t *msg, void *arg)
{
content_cache_t *cache = arg;
void *data;
const void *data;
int len;
struct cache_entry *e = NULL;
char blobref[BLOBREF_MAX_STRING_SIZE];
Expand Down
2 changes: 1 addition & 1 deletion src/broker/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ static void append_request_cb (flux_t *h, flux_msg_handler_t *w,
log_msg ("%s: malformed log request", __FUNCTION__);
return;
}
if (flux_request_decode_raw (msg, NULL, (void **)&buf, &len) < 0)
if (flux_request_decode_raw (msg, NULL, (const void **)&buf, &len) < 0)
goto error;
if (logbuf_append (logbuf, buf, len) < 0)
goto error;
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/builtin/content.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static int internal_content_load (optparse_t *p, int ac, char *av[])
{
int n;
const char *ref;
uint8_t *data;
const uint8_t *data;
int size;
flux_t *h;
flux_future_t *f;
Expand All @@ -50,7 +50,7 @@ static int internal_content_load (optparse_t *p, int ac, char *av[])
flags |= CONTENT_FLAG_CACHE_BYPASS;
if (!(f = flux_content_load (h, ref, flags)))
log_err_exit ("flux_content_load");
if (flux_content_load_get (f, (void **)&data, &size) < 0)
if (flux_content_load_get (f, (const void **)&data, &size) < 0)
log_err_exit ("flux_content_load_get");
if (write_all (STDOUT_FILENO, data, size) < 0)
log_err_exit ("write");
Expand Down
4 changes: 2 additions & 2 deletions src/common/libflux/content.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ flux_future_t *flux_content_load (flux_t *h, const char *blobref, int flags)
return flux_rpc_raw (h, topic, blobref, strlen (blobref) + 1, rank, 0);
}

int flux_content_load_get (flux_future_t *f, void **buf, int *len)
int flux_content_load_get (flux_future_t *f, const void **buf, int *len)
{
return flux_rpc_get_raw (f, buf, len);
}
Expand All @@ -76,7 +76,7 @@ int flux_content_store_get (flux_future_t *f, const char **blobref)
int ref_size;
const char *ref;

if (flux_rpc_get_raw (f, (void **)&ref, &ref_size) < 0)
if (flux_rpc_get_raw (f, (const void **)&ref, &ref_size) < 0)
return -1;
if (!ref || ref[ref_size - 1] != '\0' || blobref_validate (ref) < 0) {
errno = EPROTO;
Expand Down
2 changes: 1 addition & 1 deletion src/common/libflux/content.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ flux_future_t *flux_content_load (flux_t *h,
* Storage for 'buf' belongs to 'f' and is valid until 'f' is destroyed.
* Returns 0 on success, -1 on failure with errno set.
*/
int flux_content_load_get (flux_future_t *f, void **buf, int *len);
int flux_content_load_get (flux_future_t *f, const void **buf, int *len);

/* Send request to store blob.
*/
Expand Down
9 changes: 5 additions & 4 deletions src/common/libflux/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,8 @@ int flux_msg_pack (flux_msg_t *msg, const char *fmt, ...)
return rc;
}

int flux_msg_get_payload (const flux_msg_t *msg, int *flags, void **buf, int *size)
int flux_msg_get_payload (const flux_msg_t *msg, int *flags,
const void **buf, int *size)
{
zframe_t *zf;
uint8_t msgflags;
Expand Down Expand Up @@ -1124,7 +1125,7 @@ int flux_msg_set_json (flux_msg_t *msg, const char *s)

int flux_msg_get_json (const flux_msg_t *msg, const char **s)
{
char *buf;
const char *buf;
int size;
int flags;
int rc = -1;
Expand All @@ -1133,7 +1134,7 @@ int flux_msg_get_json (const flux_msg_t *msg, const char **s)
errno = EINVAL;
goto done;
}
if (flux_msg_get_payload (msg, &flags, (void **)&buf, &size) < 0) {
if (flux_msg_get_payload (msg, &flags, (const void **)&buf, &size) < 0) {
errno = 0;
*s = NULL;
} else {
Expand Down Expand Up @@ -1403,7 +1404,7 @@ void flux_msg_fprint (FILE *f, const flux_msg_t *msg)
*/
if (flux_msg_has_payload (msg)) {
const char *json_str;
void *buf;
const void *buf;
int size, flags;
if (flux_msg_get_json (msg, &json_str) == 0)
fprintf (f, "%s[%3.3zu] %s\n", prefix, strlen (json_str), json_str);
Expand Down
2 changes: 1 addition & 1 deletion src/common/libflux/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ int flux_msg_get_topic (const flux_msg_t *msg, const char **topic);
* Flags can be 0 or FLUX_MSGFLAG_JSON (hint for decoding).
*/
int flux_msg_get_payload (const flux_msg_t *msg, int *flags,
void **buf, int *size);
const void **buf, int *size);
int flux_msg_set_payload (flux_msg_t *msg, int flags,
const void *buf, int size);
bool flux_msg_has_payload (const flux_msg_t *msg);
Expand Down
2 changes: 1 addition & 1 deletion src/common/libflux/mrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ int flux_mrpc_get (flux_mrpc_t *mrpc, const char **json_str)
return rc;
}

int flux_mrpc_get_raw (flux_mrpc_t *mrpc, void **data, int *len)
int flux_mrpc_get_raw (flux_mrpc_t *mrpc, const void **data, int *len)
{
int rc = -1;

Expand Down
2 changes: 1 addition & 1 deletion src/common/libflux/mrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int flux_mrpc_get_nodeid (flux_mrpc_t *mrpc, uint32_t *nodeid);
* or flux_mrpc_next().
* Returns 0 on success, or -1 on failure with errno set.
*/
int flux_mrpc_get_raw (flux_mrpc_t *mrpc, void **data, int *len);
int flux_mrpc_get_raw (flux_mrpc_t *mrpc, const void **data, int *len);

/* Arrange for reactor to handle response and call 'cb' continuation function
* when a response is received. The function should call flux_mrpc_get().
Expand Down
4 changes: 2 additions & 2 deletions src/common/libflux/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ int flux_request_decode (const flux_msg_t *msg, const char **topic,
}

int flux_request_decode_raw (const flux_msg_t *msg, const char **topic,
void **data, int *len)
const void **data, int *len)
{
const char *ts;
void *d = NULL;
const void *d = NULL;
int l = 0;
int rc = -1;

Expand Down
2 changes: 1 addition & 1 deletion src/common/libflux/request.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int flux_request_unpack (const flux_msg_t *msg, const char **topic,
* Returns 0 on success, or -1 on failure with errno set.
*/
int flux_request_decode_raw (const flux_msg_t *msg, const char **topic,
void **data, int *len);
const void **data, int *len);

/* Encode a request message.
* If json_str is non-NULL, assign the json payload.
Expand Down
4 changes: 2 additions & 2 deletions src/common/libflux/response.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ int flux_response_decode (const flux_msg_t *msg, const char **topic,
}

int flux_response_decode_raw (const flux_msg_t *msg, const char **topic,
void **data, int *len)
const void **data, int *len)
{
const char *ts;
void *d = NULL;
const void *d = NULL;
int l = 0;
int flags = 0;
int rc = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/common/libflux/response.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int flux_response_decode (const flux_msg_t *msg, const char **topic,
* Returns 0 on success, or -1 on failure with errno set.
*/
int flux_response_decode_raw (const flux_msg_t *msg, const char **topic,
void **data, int *len);
const void **data, int *len);

flux_msg_t *flux_response_encode (const char *topic, int errnum,
const char *json_str);
Expand Down
2 changes: 1 addition & 1 deletion src/common/libflux/rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int flux_rpc_get (flux_future_t *f, const char **json_str)
return rc;
}

int flux_rpc_get_raw (flux_future_t *f, void **data, int *len)
int flux_rpc_get_raw (flux_future_t *f, const void **data, int *len)
{
const flux_msg_t *msg;
int rc = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/common/libflux/rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int flux_rpc_get (flux_future_t *f, const char **json_str);

int flux_rpc_get_unpack (flux_future_t *f, const char *fmt, ...);

int flux_rpc_get_raw (flux_future_t *f, void **data, int *len);
int flux_rpc_get_raw (flux_future_t *f, const void **data, int *len);


#endif /* !_FLUX_CORE_RPC_H */
Expand Down
7 changes: 4 additions & 3 deletions src/common/libflux/test/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ void check_payload_json_formatted (void)
void check_payload (void)
{
flux_msg_t *msg;
void *pay[1024], *buf;
const void *buf;
void *pay[1024];
int plen = sizeof (pay), len;
int flags;

Expand Down Expand Up @@ -610,8 +611,8 @@ void check_copy (void)
int type;
const char *topic;
int cpylen, flags;
char buf[] = "xxxxxxxxxxxxxxxxxx";
void *cpybuf;
const char buf[] = "xxxxxxxxxxxxxxxxxx";
const void *cpybuf;

ok ((msg = flux_msg_create (FLUX_MSGTYPE_KEEPALIVE)) != NULL,
"created no-payload keepalive");
Expand Down
4 changes: 2 additions & 2 deletions src/common/libflux/test/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ int main (int argc, char *argv[])
flux_msg_t *msg;
const char *topic, *s;
const char *json_str = "{\"a\":42}";
void *d;
char data[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
const void *d;
const char data[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
int i, l, len = strlen (data);

plan (NO_PLAN);
Expand Down
4 changes: 2 additions & 2 deletions src/common/libflux/test/response.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ int main (int argc, char *argv[])
flux_msg_t *msg;
const char *topic, *s;
const char *json_str = "{\"a\":42}";
void *d;
char data[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
const void *d;
const char data[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
int l, len = strlen (data);

plan (NO_PLAN);
Expand Down
2 changes: 1 addition & 1 deletion src/common/libutil/readall.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include "readall.h"

int write_all (int fd, uint8_t *buf, int len)
int write_all (int fd, const uint8_t *buf, int len)
{
int n;
int count = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/common/libutil/readall.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <stdint.h>

int write_all (int fd, uint8_t *buf, int len);
int write_all (int fd, const uint8_t *buf, int len);
int read_all (int fd, uint8_t **bufp);

#endif /* !_UTIL_READ_ALL_H */
8 changes: 4 additions & 4 deletions src/modules/content-sqlite/content-sqlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void load_cb (flux_t *h, flux_msg_handler_t *w,
const flux_msg_t *msg, void *arg)
{
sqlite_ctx_t *ctx = arg;
char *blobref = "-";
const char *blobref = "-";
int blobref_size;
uint8_t hash[BLOBREF_MAX_DIGEST_SIZE];
int hash_len;
Expand All @@ -258,7 +258,7 @@ void load_cb (flux_t *h, flux_msg_handler_t *w,
//delay cancellation to ensure lock-correctness in sqlite
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_state);

if (flux_request_decode_raw (msg, NULL, (void **)&blobref,
if (flux_request_decode_raw (msg, NULL, (const void **)&blobref,
&blobref_size) < 0) {
flux_log_error (h, "load: request decode failed");
goto done;
Expand Down Expand Up @@ -327,7 +327,7 @@ void store_cb (flux_t *h, flux_msg_handler_t *w,
const flux_msg_t *msg, void *arg)
{
sqlite_ctx_t *ctx = arg;
void *data;
const void *data;
int size, hash_len;
uint8_t hash[BLOBREF_MAX_DIGEST_SIZE];
char blobref[BLOBREF_MAX_STRING_SIZE] = "-";
Expand Down Expand Up @@ -492,7 +492,7 @@ void shutdown_cb (flux_t *h, flux_msg_handler_t *w,
flux_log_error (h, "shutdown: store");
continue;
}
if (flux_rpc_get_raw (f, (void **)&blobref, &blobref_size) < 0) {
if (flux_rpc_get_raw (f, (const void **)&blobref, &blobref_size) < 0) {
flux_log_error (h, "shutdown: store");
flux_future_destroy (f);
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/kvs/kvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static void content_load_completion (flux_future_t *f, void *arg)
{
kvs_ctx_t *ctx = arg;
json_t *o;
void *data;
const void *data;
int size;
const char *blobref;
struct cache_entry *hp;
Expand Down
2 changes: 1 addition & 1 deletion t/request/req.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ void null_request_cb (flux_t *h, flux_msg_handler_t *w,
t_req_ctx_t *ctx = arg;
const char *topic;
int type, size;
void *buf;
const void *buf;
uint32_t nodeid;
int flags;

Expand Down
6 changes: 3 additions & 3 deletions t/rpc/rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void rpctest_rawecho_cb (flux_t *h, flux_msg_handler_t *w,
const flux_msg_t *msg, void *arg)
{
int errnum = 0;
void *d = NULL;
const void *d = NULL;
int l = 0;

if (flux_request_decode_raw (msg, NULL, &d, &l) < 0) {
Expand Down Expand Up @@ -260,8 +260,8 @@ void test_encoding (flux_t *h)
flux_future_destroy (r);

/* working with-payload RPC (raw) */
void *d;
char data[] = "aaaaaaaaaaaaaaaaaaaa";
const void *d;
const char data[] = "aaaaaaaaaaaaaaaaaaaa";
int l, len = strlen (data);
ok ((r = flux_rpc_raw (h, "rpctest.rawecho", data, len,
FLUX_NODEID_ANY, 0)) != NULL,
Expand Down

0 comments on commit 276a14a

Please sign in to comment.