switch back to capn_root
capn_root now returns a ptr that can be used with capn_getp/setp. This replaces capn_new_root and capn_get_root.
This commit is contained in:
parent
69b838a092
commit
c85722874d
5 changed files with 20 additions and 31 deletions
|
|
@ -46,7 +46,7 @@ TEST(WireFormat, SimpleRawDataStruct) {
|
||||||
EXPECT_EQ(1, ctx.segnum);
|
EXPECT_EQ(1, ctx.segnum);
|
||||||
EXPECT_EQ(0, seg.id);
|
EXPECT_EQ(0, seg.id);
|
||||||
|
|
||||||
struct capn_ptr ptr = capn_get_root(&ctx);
|
struct capn_ptr ptr = capn_getp(capn_root(&ctx), 0);
|
||||||
EXPECT_EQ(CAPN_STRUCT, ptr.type);
|
EXPECT_EQ(CAPN_STRUCT, ptr.type);
|
||||||
EXPECT_EQ(8, ptr.datasz);
|
EXPECT_EQ(8, ptr.datasz);
|
||||||
EXPECT_EQ(0, ptr.ptrsz);
|
EXPECT_EQ(0, ptr.ptrsz);
|
||||||
|
|
@ -68,7 +68,7 @@ static const AlignedData<2> STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT =
|
||||||
{{0,0,0,0,1,0,0,0, 0,0,0,0,0,0,0,0}};
|
{{0,0,0,0,1,0,0,0, 0,0,0,0,0,0,0,0}};
|
||||||
|
|
||||||
static void setupStruct(struct capn *ctx) {
|
static void setupStruct(struct capn *ctx) {
|
||||||
struct capn_ptr root = capn_new_root(ctx);
|
struct capn_ptr root = capn_root(ctx);
|
||||||
ASSERT_EQ(CAPN_PTR_LIST, root.type);
|
ASSERT_EQ(CAPN_PTR_LIST, root.type);
|
||||||
ASSERT_EQ(1, root.len);
|
ASSERT_EQ(1, root.len);
|
||||||
|
|
||||||
|
|
@ -143,16 +143,16 @@ static void setupStruct(struct capn *ctx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
capn_ptr recurse = capn_new_struct(ptr.seg, 0, 1);
|
capn_ptr recurse = capn_new_struct(ptr.seg, 0, 2);
|
||||||
EXPECT_EQ(CAPN_STRUCT, recurse.type);
|
EXPECT_EQ(CAPN_STRUCT, recurse.type);
|
||||||
EXPECT_EQ(0, recurse.datasz);
|
EXPECT_EQ(0, recurse.datasz);
|
||||||
EXPECT_EQ(8, recurse.ptrsz);
|
EXPECT_EQ(16, recurse.ptrsz);
|
||||||
EXPECT_EQ(0, capn_setp(recurse, 0, recurse));
|
EXPECT_EQ(0, capn_setp(recurse, 0, recurse));
|
||||||
EXPECT_EQ(0, capn_setp(ptr, 4, recurse));
|
EXPECT_EQ(0, capn_setp(ptr, 4, recurse));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkStruct(struct capn *ctx) {
|
static void checkStruct(struct capn *ctx) {
|
||||||
capn_ptr ptr = capn_get_root(ctx);
|
capn_ptr ptr = capn_getp(capn_root(ctx), 0);
|
||||||
EXPECT_EQ(CAPN_STRUCT, ptr.type);
|
EXPECT_EQ(CAPN_STRUCT, ptr.type);
|
||||||
EXPECT_EQ(16, ptr.datasz);
|
EXPECT_EQ(16, ptr.datasz);
|
||||||
EXPECT_EQ(40, ptr.ptrsz);
|
EXPECT_EQ(40, ptr.ptrsz);
|
||||||
|
|
@ -434,8 +434,8 @@ TEST(WireFormat, CopyStruct) {
|
||||||
setupStruct(&ctx1.capn);
|
setupStruct(&ctx1.capn);
|
||||||
checkStruct(&ctx1.capn);
|
checkStruct(&ctx1.capn);
|
||||||
|
|
||||||
capn_ptr root = capn_new_root(&ctx2.capn);
|
capn_ptr root = capn_root(&ctx2.capn);
|
||||||
EXPECT_EQ(0, capn_setp(root, 0, capn_get_root(&ctx1.capn)));
|
EXPECT_EQ(0, capn_setp(root, 0, capn_getp(capn_root(&ctx1.capn), 0)));
|
||||||
|
|
||||||
checkStruct(&ctx2.capn);
|
checkStruct(&ctx2.capn);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
capn.c
32
capn.c
|
|
@ -938,29 +938,19 @@ static void new_object(capn_ptr *p, int bytes) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
capn_ptr capn_get_root(struct capn* c) {
|
capn_ptr capn_root(struct capn *c) {
|
||||||
struct capn_segment* s = lookup_segment(c, NULL, 0);
|
capn_ptr r = {CAPN_PTR_LIST};
|
||||||
if (s->len < 8) {
|
r.seg = lookup_segment(c, NULL, 0);
|
||||||
capn_ptr ret = {CAPN_NULL};
|
r.data = r.seg ? r.seg->data : new_data(c, 8, &r.seg);
|
||||||
return ret;
|
r.len = 1;
|
||||||
} else {
|
|
||||||
return read_ptr(s, s->data);
|
if (!r.seg || r.seg->cap < 8) {
|
||||||
}
|
memset(&r, 0, sizeof(r));
|
||||||
|
} else if (r.seg->len < 8) {
|
||||||
|
r.seg->len = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
capn_ptr capn_new_root(struct capn *c) {
|
return r;
|
||||||
capn_ptr p = {CAPN_NULL};
|
|
||||||
struct capn_segment *s = lookup_segment(c, NULL, 0);
|
|
||||||
|
|
||||||
/* don't use new_object as we don't want the tag */
|
|
||||||
if ((s || new_data(c, 8, &s) != NULL) && s->len >= 8) {
|
|
||||||
p.seg = s;
|
|
||||||
p.data = p.seg->data;
|
|
||||||
p.len = 1;
|
|
||||||
p.type = CAPN_PTR_LIST;
|
|
||||||
}
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
capn_ptr capn_new_struct(struct capn_segment *seg, int datasz, int ptrs) {
|
capn_ptr capn_new_struct(struct capn_segment *seg, int datasz, int ptrs) {
|
||||||
|
|
|
||||||
3
capn.h
3
capn.h
|
|
@ -120,7 +120,7 @@ typedef struct {capn_ptr p;} capn_list64;
|
||||||
/* capn_append_segment appends a segment to a session */
|
/* capn_append_segment appends a segment to a session */
|
||||||
void capn_append_segment(struct capn*, struct capn_segment*);
|
void capn_append_segment(struct capn*, struct capn_segment*);
|
||||||
|
|
||||||
capn_ptr capn_get_root(struct capn*);
|
capn_ptr capn_root(struct capn *c);
|
||||||
|
|
||||||
/* capn_getp|setp functions get/set ptrs in list/structs
|
/* capn_getp|setp functions get/set ptrs in list/structs
|
||||||
* off is the list index or pointer index in a struct
|
* off is the list index or pointer index in a struct
|
||||||
|
|
@ -175,7 +175,6 @@ int capn_setv64(capn_list64 p, int off, const uint64_t *data, int sz);
|
||||||
* datasz is in bytes, ptrs is # of pointers, sz is # of elements in the list
|
* datasz is in bytes, ptrs is # of pointers, sz is # of elements in the list
|
||||||
* On an error a CAPN_NULL pointer is returned
|
* On an error a CAPN_NULL pointer is returned
|
||||||
*/
|
*/
|
||||||
capn_ptr capn_new_root(struct capn*);
|
|
||||||
capn_ptr capn_new_struct(struct capn_segment *seg, int datasz, int ptrs);
|
capn_ptr capn_new_struct(struct capn_segment *seg, int datasz, int ptrs);
|
||||||
capn_ptr capn_new_list(struct capn_segment *seg, int sz, int datasz, int ptrs);
|
capn_ptr capn_new_list(struct capn_segment *seg, int sz, int datasz, int ptrs);
|
||||||
capn_list1 capn_new_list1(struct capn_segment *seg, int sz);
|
capn_list1 capn_new_list1(struct capn_segment *seg, int sz);
|
||||||
|
|
|
||||||
|
|
@ -617,7 +617,7 @@ int main() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
root.p = capn_get_root(&capn);
|
root.p = capn_getp(capn_root(&capn), 0);
|
||||||
read_CodeGeneratorRequest(&req, root);
|
read_CodeGeneratorRequest(&req, root);
|
||||||
|
|
||||||
for (i = 0; i < req.nodes.p.len; i++) {
|
for (i = 0; i < req.nodes.p.len; i++) {
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,7 @@ TEST(Schema, ReadSimple) {
|
||||||
struct capn ctx;
|
struct capn ctx;
|
||||||
ASSERT_EQ(0, capn_init_mem(&ctx, simple_schema, sizeof(simple_schema), 0));
|
ASSERT_EQ(0, capn_init_mem(&ctx, simple_schema, sizeof(simple_schema), 0));
|
||||||
|
|
||||||
CodeGeneratorRequest_ptr root = {capn_get_root(&ctx)};
|
CodeGeneratorRequest_ptr root = {capn_getp(capn_root(&ctx), 0)};
|
||||||
EXPECT_EQ(CAPN_STRUCT, root.p.type);
|
EXPECT_EQ(CAPN_STRUCT, root.p.type);
|
||||||
|
|
||||||
struct CodeGeneratorRequest req;
|
struct CodeGeneratorRequest req;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue