diff --git a/ccan/README b/ccan/README index 82d4f2af3..fbec62415 100644 --- a/ccan/README +++ b/ccan/README @@ -1,3 +1,3 @@ CCAN imported from http://ccodearchive.net. -CCAN version: init-2500-gcbc7cbf1 +CCAN version: init-2502-gb45a3266 diff --git a/ccan/ccan/json_out/json_out.c b/ccan/ccan/json_out/json_out.c index 87deaca85..53837e67c 100644 --- a/ccan/ccan/json_out/json_out.c +++ b/ccan/ccan/json_out/json_out.c @@ -337,11 +337,12 @@ char *json_out_direct(struct json_out *jout, size_t len) return p; } -void json_out_finished(const struct json_out *jout) +void json_out_finished(struct json_out *jout) { #ifdef CCAN_JSON_OUT_DEBUG assert(tal_count(jout->wrapping) == 0); #endif + jout->empty = true; } const char *json_out_contents(const struct json_out *jout, size_t *len) diff --git a/ccan/ccan/json_out/json_out.h b/ccan/ccan/json_out/json_out.h index 2911ff247..da8b4ffa7 100644 --- a/ccan/ccan/json_out/json_out.h +++ b/ccan/ccan/json_out/json_out.h @@ -177,9 +177,12 @@ bool json_out_add_splice(struct json_out *jout, * @jout: the json_out object written to. * * This simply causes internal assertions that all arrays and objects are - * finished. It needs CCAN_JSON_OUT_DEBUG defined to have any effect. + * finished. If CCAN_JSON_OUT_DEBUG is defined, it does sanity checks. + * + * This also resets the empty flag, so there will be no comma added if + * another JSON object is written. */ -void json_out_finished(const struct json_out *jout); +void json_out_finished(struct json_out *jout); /** * json_out_contents - read contents from json_out stream. diff --git a/ccan/ccan/opt/test/run-unregister.c b/ccan/ccan/opt/test/run-unregister.c new file mode 100644 index 000000000..d2dc469bd --- /dev/null +++ b/ccan/ccan/opt/test/run-unregister.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include +#include +#include "utils.h" + +int main(int argc, char *argv[]) +{ + const char *myname = argv[0]; + + plan_tests(15); + + opt_register_noarg("--aaa|-a", test_noarg, NULL, "AAAAAAll"); + opt_register_arg("-b", test_arg, NULL, "bbb", "b"); + + /* We can't unregister wrong ones, but can unregister correct one */ + ok1(!opt_unregister("--aaa")); + ok1(!opt_unregister("-a")); + ok1(opt_unregister("--aaa|-a")); + + /* Arg parsing works as if we'd never registered it */ + ok1(parse_args(&argc, &argv, "-bbbb", NULL)); + ok1(argc == 1); + ok1(argv[0] == myname); + ok1(argv[1] == NULL); + ok1(test_cb_called == 1); + + ok1(!parse_args(&argc, &argv, "--aaa", NULL)); + + /* We can still add another one OK. */ + opt_register_noarg("-c", test_noarg, NULL, "AAAAAAll"); + ok1(parse_args(&argc, &argv, "-c", NULL)); + ok1(argc == 1); + ok1(argv[0] == myname); + ok1(argv[1] == NULL); + ok1(test_cb_called == 2); + + /* parse_args allocates argv */ + free(argv); + return exit_status(); +}