Skip to content

Commit 9ce7281

Browse files
committed
Use json unpack format style consistently
Problem: While both the formats "s?:" and "s?" can be used to deal with optional keys while unpacking json, it has often used inconsistently. Sometimes both styles were used within the same line of code! Solution: Use "s?" over "s?:" as it is more widely used in flux-core.
1 parent 628a308 commit 9ce7281

File tree

27 files changed

+50
-50
lines changed

27 files changed

+50
-50
lines changed

src/broker/boot_config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ static int gethostentry (json_t *hosts,
409409
/* N.B. entry already validated by boot_config_parse().
410410
*/
411411
(void)json_unpack (entry,
412-
"{s:s s?:s s?:s}",
412+
"{s:s s?s s?s}",
413413
"host", host,
414414
"bind", bind,
415415
"connect", uri);

src/broker/publisher.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static void publish_cb (flux_t *h,
102102
flux_msg_t *event = NULL;
103103
const char *errmsg = NULL;
104104

105-
if (flux_request_unpack (msg, NULL, "{s:s s:i s?:s}",
105+
if (flux_request_unpack (msg, NULL, "{s:s s:i s?s}",
106106
"topic", &topic,
107107
"flags", &flags,
108108
"payload", &payload) < 0)

src/cmd/flux-job.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ static void handle_output_redirect (struct attach_ctx *ctx, json_t *context)
16661666
const char *path = NULL;
16671667
if (!ctx->output_header_parsed)
16681668
log_msg_exit ("stream redirect read before header");
1669-
if (json_unpack (context, "{ s:s s:s s?:s }",
1669+
if (json_unpack (context, "{ s:s s:s s?s }",
16701670
"stream", &stream,
16711671
"rank", &rank,
16721672
"path", &path) < 0)
@@ -1700,7 +1700,7 @@ static void handle_output_log (struct attach_ctx *ctx,
17001700
json_error_t err;
17011701

17021702
if (json_unpack_ex (context, &err, 0,
1703-
"{ s?i s:i s:s s?:s s?:s s?:i }",
1703+
"{ s?i s:i s:s s?s s?s s?i }",
17041704
"rank", &rank,
17051705
"level", &level,
17061706
"message", &msg,
@@ -2008,7 +2008,7 @@ static void setup_mpir_interface (struct attach_ctx *ctx, json_t *context)
20082008
flux_future_t *f = NULL;
20092009
int stop_tasks_in_exec = 0;
20102010

2011-
if (json_unpack (context, "{s?:b}", "sync", &stop_tasks_in_exec) < 0)
2011+
if (json_unpack (context, "{s?b}", "sync", &stop_tasks_in_exec) < 0)
20122012
log_err_exit ("error decoding shell.init context");
20132013

20142014
snprintf (topic, sizeof (topic), "%s.proctable", ctx->service);
@@ -2513,7 +2513,7 @@ void attach_event_continuation (flux_future_t *f, void *arg)
25132513
int severity;
25142514
const char *note = NULL;
25152515

2516-
if (json_unpack (context, "{s:s s:i s?:s}",
2516+
if (json_unpack (context, "{s:s s:i s?s}",
25172517
"type", &type,
25182518
"severity", &severity,
25192519
"note", &note) < 0)

src/common/libflux/test/rpc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void rpctest_echo_error_cb (flux_t *h, flux_msg_handler_t *mh,
8585
int errnum;
8686
const char *errstr = NULL;
8787

88-
if (flux_request_unpack (msg, NULL, "{s:i s?:s}",
88+
if (flux_request_unpack (msg, NULL, "{s:i s?s}",
8989
"errnum", &errnum, "errstr", &errstr) < 0)
9090
goto error;
9191
if (errstr) {

src/common/libjob/result.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static int job_result_handle_exception (json_t *res,
118118
return -1;
119119

120120
if (json_unpack (context,
121-
"{s:o s:o s?:o}",
121+
"{s:o s:o s?o}",
122122
"type", &type,
123123
"severity", &severity,
124124
"note", &note) < 0)

src/modules/connector-local/local.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ int parse_config (struct connector_local *ctx,
218218

219219
if (flux_conf_unpack (conf,
220220
&error,
221-
"{s?:{s?:b s?:b !}}",
221+
"{s?{s?b s?b !}}",
222222
"access",
223223
"allow-guest-user",
224224
&allow_guest_user,

src/modules/content-s3/content-s3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static struct s3_config *parse_config (const flux_conf_t *conf,
155155

156156
if (flux_conf_unpack (conf,
157157
&error,
158-
"{s:{s:s, s:s, s:s, s?:b !} }",
158+
"{s:{s:s, s:s, s:s, s?b !} }",
159159
"content-s3",
160160
"credential-file",
161161
&cred_file,

src/modules/job-archive/job-archive.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ void job_info_lookup_continuation (flux_future_t *f, void *arg)
272272

273273
monotime (&t0);
274274

275-
if (flux_rpc_get_unpack (f, "{s:s s:s s?:s}",
275+
if (flux_rpc_get_unpack (f, "{s:s s:s s?s}",
276276
"eventlog", &eventlog,
277277
"jobspec", &jobspec,
278278
"R", &R) < 0) {
@@ -292,7 +292,7 @@ void job_info_lookup_continuation (flux_future_t *f, void *arg)
292292
}
293293

294294
if (json_unpack_ex (job, &error, 0,
295-
"{s:i s?:s s:f s?:f s?:f s:f}",
295+
"{s:i s?s s:f s?f s?f s:f}",
296296
"userid", &userid,
297297
"ranks", &ranks,
298298
"t_submit", &t_submit,
@@ -420,7 +420,7 @@ int job_info_lookup (struct job_archive_ctx *ctx, json_t *job)
420420
json_t *keys = NULL;
421421
double t_run = 0.0;
422422

423-
if (json_unpack (job, "{s:I s?:f}", "id", &id, "t_run", &t_run) < 0) {
423+
if (json_unpack (job, "{s:I s?f}", "id", &id, "t_run", &t_run) < 0) {
424424
flux_log (ctx->h, LOG_ERR, "%s: parse t_run", __FUNCTION__);
425425
goto error;
426426
}

src/modules/job-exec/exec_config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int config_init (flux_t *h, int argc, char **argv)
8787
/* Check configuration for exec.job-shell */
8888
if (flux_conf_unpack (flux_get_conf (h),
8989
&err,
90-
"{s?:{s?s}}",
90+
"{s?{s?s}}",
9191
"exec",
9292
"job-shell", &default_job_shell) < 0) {
9393
flux_log (h, LOG_ERR,
@@ -99,7 +99,7 @@ int config_init (flux_t *h, int argc, char **argv)
9999
/* Check configuration for exec.imp */
100100
if (flux_conf_unpack (flux_get_conf (h),
101101
&err,
102-
"{s?:{s?s}}",
102+
"{s?{s?s}}",
103103
"exec",
104104
"imp", &flux_imp_path) < 0) {
105105
flux_log (h, LOG_ERR,

src/modules/job-exec/sdexec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ static int sdexec_init (struct jobinfo *job)
301301
const char *method = NULL;
302302
if (flux_conf_unpack (flux_get_conf (h),
303303
&err,
304-
"{s?:{s?s}}",
304+
"{s?{s?s}}",
305305
"exec",
306306
"method", &method) < 0) {
307307
flux_log (h, LOG_ERR,

0 commit comments

Comments
 (0)