common/json_stream: remove useless attempt at oom handling.

We tell membuf to use tal, and tal never returns NULL, so this
code can never be triggered.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-07-03 20:37:20 +09:30
committed by neil saitug
parent 9685c1adaf
commit 0236d4e4da
5 changed files with 24 additions and 73 deletions

View File

@@ -37,8 +37,7 @@ struct json_stream *json_stream_dup(const tal_t *ctx,
{
struct json_stream *js = tal_dup(ctx, struct json_stream, original);
if (original->jout)
js->jout = json_out_dup(js, original->jout);
js->jout = json_out_dup(js, original->jout);
js->log = log;
return js;
}
@@ -61,24 +60,12 @@ void json_stream_log_suppress(struct json_stream *js, const char *cmd_name)
js->log = NULL;
}
/* If we have an allocation failure. */
static void COLD js_oom(struct json_stream *js)
{
js->jout = tal_free(js->jout);
}
void json_stream_append(struct json_stream *js,
const char *str, size_t len)
{
char *dest;
if (!js->jout)
return;
dest = json_out_direct(js->jout, len);
if (!dest) {
js_oom(js);
return;
}
memcpy(dest, str, len);
}
@@ -88,9 +75,6 @@ void json_stream_double_cr(struct json_stream *js)
const char *contents;
size_t len, cr_needed;
if (!js->jout)
return;
/* Must be well-formed at this point! */
json_out_finished(js->jout);
@@ -131,46 +115,28 @@ char *json_member_direct(struct json_stream *js,
{
char *dest;
if (!js->jout)
return NULL;
dest = json_out_member_direct(js->jout, fieldname, extra);
if (!dest)
js_oom(js);
return dest;
}
void json_array_start(struct json_stream *js, const char *fieldname)
{
if (js->jout && !json_out_start(js->jout, fieldname, '['))
js_oom(js);
json_out_start(js->jout, fieldname, '[');
}
void json_array_end(struct json_stream *js)
{
if (js->jout && !json_out_end(js->jout, ']'))
js_oom(js);
json_out_end(js->jout, ']');
}
void json_object_start(struct json_stream *js, const char *fieldname)
{
if (js->jout && !json_out_start(js->jout, fieldname, '{'))
js_oom(js);
json_out_start(js->jout, fieldname, '{');
}
void json_object_end(struct json_stream *js)
{
if (js->jout && !json_out_end(js->jout, '}'))
js_oom(js);
}
void json_object_compat_end(struct json_stream *js)
{
/* In 0.7.1 we upgraded pylightning to no longer need this. */
#ifdef COMPAT_V070
json_stream_append(js, " ", 1);
#endif
json_object_end(js);
json_out_end(js->jout, '}');
}
void json_add_member(struct json_stream *js,
@@ -181,8 +147,7 @@ void json_add_member(struct json_stream *js,
va_list ap;
va_start(ap, fmt);
if (js->jout && !json_out_addv(js->jout, fieldname, quote, fmt, ap))
js_oom(js);
json_out_addv(js->jout, fieldname, quote, fmt, ap);
va_end(ap);
}
@@ -194,9 +159,7 @@ void json_add_jsonstr(struct json_stream *js,
size_t len = strlen(jsonstr);
p = json_member_direct(js, fieldname, len);
/* Could be OOM! */
if (p)
memcpy(p, jsonstr, len);
memcpy(p, jsonstr, len);
}
/* This is where we read the json_stream and write it to conn */
@@ -205,10 +168,6 @@ static struct io_plan *json_stream_output_write(struct io_conn *conn,
{
const char *p;
/* Out of memory? Nothing we can do but close conn */
if (!js->jout)
return io_close(conn);
/* For when we've just done some output */
json_out_consume(js->jout, js->len_read);