Merge branch 'kylemanna' into merge
Conflicts: (manually resolved) capn-malloc.c capn-stream.c capn-test.cpp capn.c capn.h compiler/capnpc-c.c
This commit is contained in:
commit
02268ff818
5 changed files with 23 additions and 19 deletions
|
|
@ -80,7 +80,7 @@ int capn_deflate(struct capn_stream* s) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (s->avail_out < 1 + sz)
|
if (s->avail_out < 1U + sz)
|
||||||
return CAPN_NEED_MORE;
|
return CAPN_NEED_MORE;
|
||||||
|
|
||||||
*(s->next_out++) = hdr;
|
*(s->next_out++) = hdr;
|
||||||
|
|
@ -167,7 +167,7 @@ int capn_inflate(struct capn_stream* s) {
|
||||||
if (hdr & (1 << i))
|
if (hdr & (1 << i))
|
||||||
sz++;
|
sz++;
|
||||||
}
|
}
|
||||||
if (s->avail_in < 1 + sz)
|
if (s->avail_in < 1U + sz)
|
||||||
return CAPN_NEED_MORE;
|
return CAPN_NEED_MORE;
|
||||||
|
|
||||||
s->next_in += 1;
|
s->next_in += 1;
|
||||||
|
|
|
||||||
|
|
@ -274,11 +274,11 @@ static void getSegments(struct capn *c, struct capn_segment **s, size_t num) {
|
||||||
ASSERT_EQ(num, c->segnum);
|
ASSERT_EQ(num, c->segnum);
|
||||||
|
|
||||||
s[0] = c->seglist;
|
s[0] = c->seglist;
|
||||||
for (unsigned i = 1; i < num; i++) {
|
for (size_t i = 1; i < num; i++) {
|
||||||
s[i] = s[i-1]->next;
|
s[i] = s[i-1]->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned i = 0; i < num; i++) {
|
for (size_t i = 0; i < num; i++) {
|
||||||
EXPECT_EQ(s[i]->id, i);
|
EXPECT_EQ(s[i]->id, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -315,7 +315,7 @@ TEST(WireFormat, StructRoundTrip_OneSegmentPerAllocation) {
|
||||||
|
|
||||||
struct capn ctx2;
|
struct capn ctx2;
|
||||||
memset(&ctx2, 0, sizeof(ctx2));
|
memset(&ctx2, 0, sizeof(ctx2));
|
||||||
for (unsigned i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) {
|
for (size_t i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) {
|
||||||
capn_append_segment(&ctx2, segments[i]);
|
capn_append_segment(&ctx2, segments[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -371,7 +371,7 @@ TEST(WireFormat, StructRoundTrip_OneSegmentPerAllocation_NoTag) {
|
||||||
|
|
||||||
struct capn ctx2;
|
struct capn ctx2;
|
||||||
memset(&ctx2, 0, sizeof(ctx2));
|
memset(&ctx2, 0, sizeof(ctx2));
|
||||||
for (unsigned i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) {
|
for (size_t i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) {
|
||||||
capn_append_segment(&ctx2, segments[i]);
|
capn_append_segment(&ctx2, segments[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -421,7 +421,7 @@ TEST(WireFormat, StructRoundTrip_MultipleSegmentsWithMultipleAllocations) {
|
||||||
|
|
||||||
struct capn ctx2;
|
struct capn ctx2;
|
||||||
memset(&ctx2, 0, sizeof(ctx2));
|
memset(&ctx2, 0, sizeof(ctx2));
|
||||||
for (unsigned i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) {
|
for (size_t i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) {
|
||||||
capn_append_segment(&ctx2, segments[i]);
|
capn_append_segment(&ctx2, segments[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
16
capn.c
16
capn.c
|
|
@ -186,7 +186,7 @@ end:
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct capn_segment *lookup_segment(struct capn* c, struct capn_segment *s, uint32_t id) {
|
static struct capn_segment *lookup_segment(struct capn* c, struct capn_segment *s, uint32_t id) {
|
||||||
struct capn_tree **x = &c->segtree;
|
struct capn_tree **x;
|
||||||
struct capn_segment *y = NULL;
|
struct capn_segment *y = NULL;
|
||||||
|
|
||||||
if (s && s->id == id)
|
if (s && s->id == id)
|
||||||
|
|
@ -195,6 +195,7 @@ static struct capn_segment *lookup_segment(struct capn* c, struct capn_segment *
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (id < c->segnum) {
|
if (id < c->segnum) {
|
||||||
|
x = &c->segtree;
|
||||||
while (*x) {
|
while (*x) {
|
||||||
y = (struct capn_segment*) *x;
|
y = (struct capn_segment*) *x;
|
||||||
if (id == y->id) {
|
if (id == y->id) {
|
||||||
|
|
@ -205,6 +206,9 @@ static struct capn_segment *lookup_segment(struct capn* c, struct capn_segment *
|
||||||
x = &y->hdr.link[1];
|
x = &y->hdr.link[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
/* Otherwise `x` may be uninitialized */
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = c->lookup ? c->lookup(c->user, id) : NULL;
|
s = c->lookup ? c->lookup(c->user, id) : NULL;
|
||||||
|
|
@ -229,7 +233,7 @@ static struct capn_segment *lookup_segment(struct capn* c, struct capn_segment *
|
||||||
|
|
||||||
static uint64_t lookup_double(struct capn_segment **s, char **d, uint64_t val) {
|
static uint64_t lookup_double(struct capn_segment **s, char **d, uint64_t val) {
|
||||||
uint64_t far, tag;
|
uint64_t far, tag;
|
||||||
uint32_t off = (U32(val) >> 3) * 8;
|
size_t off = (U32(val) >> 3) * 8;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if ((*s = lookup_segment((*s)->capn, *s, U32(val >> 32))) == NULL) {
|
if ((*s = lookup_segment((*s)->capn, *s, U32(val >> 32))) == NULL) {
|
||||||
|
|
@ -264,7 +268,7 @@ static uint64_t lookup_double(struct capn_segment **s, char **d, uint64_t val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t lookup_far(struct capn_segment **s, char **d, uint64_t val) {
|
static uint64_t lookup_far(struct capn_segment **s, char **d, uint64_t val) {
|
||||||
uint32_t off = (U32(val) >> 3) * 8;
|
size_t off = (U32(val) >> 3) * 8;
|
||||||
|
|
||||||
if ((*s = lookup_segment((*s)->capn, *s, U32(val >> 32))) == NULL) {
|
if ((*s = lookup_segment((*s)->capn, *s, U32(val >> 32))) == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -369,7 +373,7 @@ static capn_ptr read_ptr(struct capn_segment *s, char *d) {
|
||||||
e = d + ret.len * 8;
|
e = d + ret.len * 8;
|
||||||
break;
|
break;
|
||||||
case COMPOSITE_LIST:
|
case COMPOSITE_LIST:
|
||||||
if (d+8-s->data > s->len) {
|
if ((size_t)((d+8) - s->data) > s->len) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -394,7 +398,7 @@ static capn_ptr read_ptr(struct capn_segment *s, char *d) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e - s->data > s->len)
|
if ((size_t)(e - s->data) > s->len)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
ret.data = d;
|
ret.data = d;
|
||||||
|
|
@ -664,7 +668,7 @@ static int copy_ptr(struct capn_segment *seg, char *data, struct capn_ptr *t, st
|
||||||
struct capn_segment *cs = c->copylist;
|
struct capn_segment *cs = c->copylist;
|
||||||
|
|
||||||
/* need to allocate a struct copy */
|
/* need to allocate a struct copy */
|
||||||
if (!cs || cs->len + sizeof(*n) > cs->cap) {
|
if (!cs || cs->len + (int)sizeof(*n) > cs->cap) {
|
||||||
cs = c->create_local ? c->create_local(c->user, sizeof(*n)) : NULL;
|
cs = c->create_local ? c->create_local(c->user, sizeof(*n)) : NULL;
|
||||||
if (!cs) {
|
if (!cs) {
|
||||||
/* can't allocate a copy structure */
|
/* can't allocate a copy structure */
|
||||||
|
|
|
||||||
6
capn.h
6
capn.h
|
|
@ -94,7 +94,7 @@ struct capn_segment {
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
/* user settable */
|
/* user settable */
|
||||||
char *data;
|
char *data;
|
||||||
unsigned len, cap;
|
size_t len, cap;
|
||||||
void *user;
|
void *user;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -262,9 +262,9 @@ void capn_reset_copy(struct capn *c);
|
||||||
*/
|
*/
|
||||||
struct capn_stream {
|
struct capn_stream {
|
||||||
const uint8_t *next_in;
|
const uint8_t *next_in;
|
||||||
unsigned avail_in;
|
size_t avail_in;
|
||||||
uint8_t *next_out;
|
uint8_t *next_out;
|
||||||
unsigned avail_out;
|
size_t avail_out;
|
||||||
unsigned zeros, raw;
|
unsigned zeros, raw;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -930,7 +930,7 @@ static void define_struct(struct node *n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
Commenting out interfaces until the RPC protocol has been specified
|
/* Commenting out interfaces until the RPC protocol has been spec'd */
|
||||||
static int find_offset(struct str *v, int inc, uint64_t mask) {
|
static int find_offset(struct str *v, int inc, uint64_t mask) {
|
||||||
int i, j;
|
int i, j;
|
||||||
union {uint64_t u; char c[8];} umask;
|
union {uint64_t u; char c[8];} umask;
|
||||||
|
|
@ -1248,7 +1248,7 @@ int main() {
|
||||||
fprintf(srcf, "static const capn_ptr capn_null = {CAPN_NULL};\n");
|
fprintf(srcf, "static const capn_ptr capn_null = {CAPN_NULL};\n");
|
||||||
|
|
||||||
if (g_valseg.len > 8) {
|
if (g_valseg.len > 8) {
|
||||||
fprintf(srcf, "static const uint8_t capn_buf[%d] = {", g_valseg.len-8);
|
fprintf(srcf, "static const uint8_t capn_buf[%lu] = {", g_valseg.len-8);
|
||||||
for (j = 8; j < g_valseg.len; j++) {
|
for (j = 8; j < g_valseg.len; j++) {
|
||||||
if (j > 8)
|
if (j > 8)
|
||||||
fprintf(srcf, ",");
|
fprintf(srcf, ",");
|
||||||
|
|
@ -1258,7 +1258,7 @@ int main() {
|
||||||
}
|
}
|
||||||
fprintf(srcf, "\n};\n");
|
fprintf(srcf, "\n};\n");
|
||||||
|
|
||||||
fprintf(srcf, "static const struct capn_segment capn_seg = {{0},0,0,0,(char*)&capn_buf[0],%d,%d};\n",
|
fprintf(srcf, "static const struct capn_segment capn_seg = {{0},0,0,0,(char*)&capn_buf[0],%lu,%lu};\n",
|
||||||
g_valseg.len-8, g_valseg.len-8);
|
g_valseg.len-8, g_valseg.len-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue