handle NULL text
This commit is contained in:
parent
07e2126e25
commit
3a7ae150b8
4 changed files with 20 additions and 6 deletions
|
|
@ -1070,9 +1070,21 @@ static void encode_member(capnp_ctx_t *ctx, struct str *func, struct field *f,
|
||||||
break;
|
break;
|
||||||
case Type_text:
|
case Type_text:
|
||||||
str_add(func, tab, -1);
|
str_add(func, tab, -1);
|
||||||
str_addf(func, "d->%s.str = s->%s;\n", var, var2);
|
str_addf(func, "if (s->%s != NULL) {\n", var2);
|
||||||
str_add(func, tab, -1);
|
str_add(func, tab, -1);
|
||||||
str_addf(func, "d->%s.len = strlen(s->%s);\n", var, var2);
|
str_addf(func, "\td->%s.str = s->%s;\n", var, var2);
|
||||||
|
str_add(func, tab, -1);
|
||||||
|
str_addf(func, "\td->%s.len = strlen(s->%s);\n", var, var2);
|
||||||
|
str_add(func, tab, -1);
|
||||||
|
str_addf(func, "}\n");
|
||||||
|
str_add(func, tab, -1);
|
||||||
|
str_addf(func, "else{\n");
|
||||||
|
str_add(func, tab, -1);
|
||||||
|
str_addf(func, "\td->%s.str = \"\";\n", var);
|
||||||
|
str_add(func, tab, -1);
|
||||||
|
str_addf(func, "\td->%s.len = 0;\n", var);
|
||||||
|
str_add(func, tab, -1);
|
||||||
|
str_addf(func, "}\n");
|
||||||
str_add(func, tab, -1);
|
str_add(func, tab, -1);
|
||||||
str_addf(func, "d->%s.seg = NULL;\n", var);
|
str_addf(func, "d->%s.seg = NULL;\n", var);
|
||||||
break;
|
break;
|
||||||
|
|
@ -1081,8 +1093,8 @@ static void encode_member(capnp_ctx_t *ctx, struct str *func, struct field *f,
|
||||||
|
|
||||||
if (n != NULL) {
|
if (n != NULL) {
|
||||||
str_add(func, tab, -1);
|
str_add(func, tab, -1);
|
||||||
str_addf(func, "encode_%s_ptr(cs, &(d->%s), s->%s);\n", n->name.str,
|
str_addf(func, "encode_%s_ptr(cs, &(d->%s), s->%s);\n", n->name.str, var,
|
||||||
var, var2);
|
var2);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Type__list:
|
case Type__list:
|
||||||
|
|
@ -1323,8 +1335,7 @@ void mk_struct_ptr_decoder(capnp_ctx_t *ctx, struct node *n) {
|
||||||
"%s_ptr p) {\n",
|
"%s_ptr p) {\n",
|
||||||
n->name.str, buf, n->name.str);
|
n->name.str, buf, n->name.str);
|
||||||
str_addf(&(ctx->SRC), "\tstruct %s s;\n", n->name.str);
|
str_addf(&(ctx->SRC), "\tstruct %s s;\n", n->name.str);
|
||||||
str_addf(&(ctx->SRC), "\t*d = (%s *)calloc(1, sizeof(%s));\n",
|
str_addf(&(ctx->SRC), "\t*d = (%s *)calloc(1, sizeof(%s));\n", buf, buf);
|
||||||
buf, buf);
|
|
||||||
str_addf(&(ctx->SRC), "\tread_%s(&s, p);\n", n->name.str);
|
str_addf(&(ctx->SRC), "\tread_%s(&s, p);\n", n->name.str);
|
||||||
str_addf(&(ctx->SRC), "\tdecode_%s(*d, &s);\n", n->name.str);
|
str_addf(&(ctx->SRC), "\tdecode_%s(*d, &s);\n", n->name.str);
|
||||||
str_addf(&(ctx->SRC), "}\n");
|
str_addf(&(ctx->SRC), "}\n");
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ struct Book $C.mapname("book_t") {
|
||||||
publish @6: Publish;
|
publish @6: Publish;
|
||||||
nulldata @7: Nulldata;
|
nulldata @7: Nulldata;
|
||||||
magic1 @2: List(UInt32) $C.mapname("magic_1") $C.maplistcount("n_magic1");
|
magic1 @2: List(UInt32) $C.mapname("magic_1") $C.maplistcount("n_magic1");
|
||||||
|
description @8: Text;
|
||||||
acquire :union $C.mapuniontag("acquire_method") {
|
acquire :union $C.mapuniontag("acquire_method") {
|
||||||
buy @3: Text;
|
buy @3: Text;
|
||||||
donation @4: Text;
|
donation @4: Text;
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ typedef struct {
|
||||||
nulldata_t *nulldata;
|
nulldata_t *nulldata;
|
||||||
int n_magic1;
|
int n_magic1;
|
||||||
uint32_t *magic_1;
|
uint32_t *magic_1;
|
||||||
|
char *description;
|
||||||
int acquire_method;
|
int acquire_method;
|
||||||
union {
|
union {
|
||||||
char *buy;
|
char *buy;
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ int encode() {
|
||||||
book.nulldata = NULL;
|
book.nulldata = NULL;
|
||||||
book.n_magic1 = 2;
|
book.n_magic1 = 2;
|
||||||
book.magic_1 = &magic1[0];
|
book.magic_1 = &magic1[0];
|
||||||
|
book.description = NULL;
|
||||||
book.acquire_method = Book_acquire_buy;
|
book.acquire_method = Book_acquire_buy;
|
||||||
book.acquire.buy = "bought from Xinhua book store";
|
book.acquire.buy = "bought from Xinhua book store";
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue