Skip to content

Commit d88365e

Browse files
author
Ivan Dlugos
committed
fix C generated code - split aux function declaration & implementation
1 parent 825129b commit d88365e

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

internal/generator/c/templates/binding-c.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,15 @@ var CBindingTemplate = template.Must(template.New("binding-c").Funcs(funcMap).Pa
3737
#include "flatcc/flatcc_builder.h"
3838
#include "objectbox.h"
3939
40-
/// Internal function used in other generated functions to put (write) explicitly typed objects
40+
/// Internal function used in other generated functions to put (write) explicitly typed objects.
4141
static obx_id {{.FileIdentifier}}_put_object(OBX_box* box, void* object,
4242
bool (*to_flatbuffer)(flatcc_builder_t*, const void*, void**, size_t*), OBXPutMode mode);
4343
44-
/// Internal function used in other generated functions to get (read) explicitly typed objects
44+
/// Internal function used in other generated functions to get (read) explicitly typed objects.
4545
static void* {{.FileIdentifier}}_get_object(OBX_box* box, obx_id id, void* (*from_flatbuffer)(const void*, size_t));
4646
47-
flatbuffers_voffset_t {{.FileIdentifier}}_fb_field_offset(flatbuffers_voffset_t vs, const flatbuffers_voffset_t* vt,
48-
size_t field) {
49-
return (vs < sizeof(vt[0]) * (field + 3)) ? 0 : __flatbuffers_voffset_read_from_pe(vt + field + 2);
50-
}
47+
/// Internal function used in other generated functions to get a vTable offset for a given field.
48+
static flatbuffers_voffset_t {{.FileIdentifier}}_fb_field_offset(flatbuffers_voffset_t vs, const flatbuffers_voffset_t* vt, size_t field);
5149
5250
{{range $entity := .Model.EntitiesWithMeta}}
5351
{{PrintComments 0 $entity.Comments}}typedef struct {{$entity.Meta.CName}} {
@@ -303,4 +301,8 @@ static void* {{.FileIdentifier}}_get_object(OBX_box* box, obx_id id, void* (*fro
303301
obx_txn_close(tx);
304302
return result;
305303
}
304+
305+
static flatbuffers_voffset_t {{.FileIdentifier}}_fb_field_offset(flatbuffers_voffset_t vs, const flatbuffers_voffset_t* vt, size_t field) {
306+
return (vs < sizeof(vt[0]) * (field + 3)) ? 0 : __flatbuffers_voffset_read_from_pe(vt + field + 2);
307+
}
306308
`))

test/comparison/testdata/fbs/typeful/c/schema.obx.h.expected

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@
1010
#include "flatcc/flatcc_builder.h"
1111
#include "objectbox.h"
1212

13-
/// Internal function used in other generated functions to put (write) explicitly typed objects
13+
/// Internal function used in other generated functions to put (write) explicitly typed objects.
1414
static obx_id schema_obx_h_put_object(OBX_box* box, void* object,
1515
bool (*to_flatbuffer)(flatcc_builder_t*, const void*, void**, size_t*), OBXPutMode mode);
1616

17-
/// Internal function used in other generated functions to get (read) explicitly typed objects
17+
/// Internal function used in other generated functions to get (read) explicitly typed objects.
1818
static void* schema_obx_h_get_object(OBX_box* box, obx_id id, void* (*from_flatbuffer)(const void*, size_t));
1919

20-
flatbuffers_voffset_t schema_obx_h_fb_field_offset(flatbuffers_voffset_t vs, const flatbuffers_voffset_t* vt,
21-
size_t field) {
22-
return (vs < sizeof(vt[0]) * (field + 3)) ? 0 : __flatbuffers_voffset_read_from_pe(vt + field + 2);
23-
}
20+
/// Internal function used in other generated functions to get a vTable offset for a given field.
21+
static flatbuffers_voffset_t schema_obx_h_fb_field_offset(flatbuffers_voffset_t vs, const flatbuffers_voffset_t* vt,
22+
size_t field);
2423

2524

2625
/// Entity documentation is copied
@@ -1062,3 +1061,8 @@ static void* schema_obx_h_get_object(OBX_box* box, obx_id id, void* (*from_flatb
10621061
obx_txn_close(tx);
10631062
return result;
10641063
}
1064+
1065+
static flatbuffers_voffset_t schema_obx_h_fb_field_offset(flatbuffers_voffset_t vs,
1066+
const flatbuffers_voffset_t* vt, size_t field) {
1067+
return (vs < sizeof(vt[0]) * (field + 3)) ? 0 : __flatbuffers_voffset_read_from_pe(vt + field + 2);
1068+
}

0 commit comments

Comments
 (0)