Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/runtime/builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,10 @@ static int enter_frame(flatcc_builder_t *B, uint16_t align)

static inline void exit_frame(flatcc_builder_t *B)
{
memset(B->ds, 0, B->ds_offset);
/* Clear the ds stack (if any struct frames have been allocated). */
if (B->ds) {
memset(B->ds, 0, B->ds_offset);
}
B->ds_offset = frame(ds_offset);
B->ds_first = frame(ds_first);
refresh_ds(B, frame(type_limit));
Expand Down
9 changes: 8 additions & 1 deletion test/optional_scalars_test/optional_scalars_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ int create_scalar_stuff(flatcc_builder_t *builder)
{
ns(ScalarStuff_start_as_root(builder));

/* Test of creating a table before any fields are added. */
ns(NestedTable_ref_t) nested_table;
ns(NestedTable_start(builder));
nested_table = ns(NestedTable_end(builder));

ns(ScalarStuff_just_i8_add(builder, 10));
ns(ScalarStuff_maybe_i8_add(builder, 11));
ns(ScalarStuff_default_i8_add(builder, 12));
Expand Down Expand Up @@ -49,6 +54,8 @@ int create_scalar_stuff(flatcc_builder_t *builder)
ns(ScalarStuff_maybe_xfactor_add)(builder, ns(OptionalFactor_Twice));
ns(ScalarStuff_default_xfactor_add)(builder, ns(OptionalFactor_Twice));

ns(ScalarStuff_nested_table_add)(builder,nested_table);

ns(ScalarStuff_end_as_root(builder));

return 0;
Expand Down Expand Up @@ -176,7 +183,7 @@ int test(void)
}

const char *expected_json =
"{\"just_i8\":10,\"maybe_i8\":11,\"default_i8\":12,\"just_i16\":42,\"maybe_i16\":42,\"maybe_u32\":0,\"default_u32\":0,\"just_f32\":42,\"maybe_f32\":42,\"just_bool\":true,\"maybe_bool\":true,\"just_enum\":\"One\",\"maybe_enum\":\"One\",\"just_xfactor\":\"Twice\",\"maybe_xfactor\":\"Twice\"}";
"{\"just_i8\":10,\"maybe_i8\":11,\"default_i8\":12,\"just_i16\":42,\"maybe_i16\":42,\"maybe_u32\":0,\"default_u32\":0,\"just_f32\":42,\"maybe_f32\":42,\"just_bool\":true,\"maybe_bool\":true,\"just_enum\":\"One\",\"maybe_enum\":\"One\",\"just_xfactor\":\"Twice\",\"maybe_xfactor\":\"Twice\",\"nested_table\":{}}";

#if 0
int print_buffer(const void *buf, size_t size)
Expand Down
6 changes: 6 additions & 0 deletions test/optional_scalars_test/optional_scalars_test.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ table ScalarStuff {
maybe_yfactor: OptionalFactor = null;
default_yfactor: OptionalFactor = Twice;

nested_table: NestedTable;
}

table NestedTable {
u64_0: uint64 = null;
u64_1: uint64 = null;
}
Loading