use create_local
This commit is contained in:
parent
ca1d07f657
commit
448021e7e1
3 changed files with 7 additions and 4 deletions
|
|
@ -23,9 +23,14 @@ static struct capn_segment *create(void *u, uint32_t id, int sz) {
|
|||
return s;
|
||||
}
|
||||
|
||||
static struct capn_segment *create_local(void *u, int sz) {
|
||||
return create(u, 0, sz);
|
||||
}
|
||||
|
||||
void capn_init_malloc(struct capn *c) {
|
||||
memset(c, 0, sizeof(*c));
|
||||
c->create = &create;
|
||||
c->create_local = &create_local;
|
||||
}
|
||||
|
||||
void capn_free(struct capn *c) {
|
||||
|
|
|
|||
2
capn.c
2
capn.c
|
|
@ -662,7 +662,7 @@ static int copy_ptr(struct capn_segment *seg, char *data, struct capn_ptr *t, st
|
|||
|
||||
/* need to allocate a struct copy */
|
||||
if (!cs || cs->len + sizeof(*n) > cs->cap) {
|
||||
cs = c->create ? c->create(c->user, CAPN_SEGID_LOCAL, sizeof(*n)) : NULL;
|
||||
cs = c->create_local ? c->create_local(c->user, sizeof(*n)) : NULL;
|
||||
if (!cs) {
|
||||
/* can't allocate a copy structure */
|
||||
return -1;
|
||||
|
|
|
|||
4
capn.h
4
capn.h
|
|
@ -10,8 +10,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CAPN_SEGID_LOCAL 0xFFFFFFFF
|
||||
|
||||
#if defined(__cplusplus) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
|
||||
#define CAPN_INLINE static inline
|
||||
#else
|
||||
|
|
@ -44,7 +42,7 @@ struct capn {
|
|||
/* user settable */
|
||||
struct capn_segment *(*lookup)(void* /*user*/, uint32_t /*id */);
|
||||
struct capn_segment *(*create)(void* /*user*/, uint32_t /*id */, int /*sz*/);
|
||||
struct capn_segment *(*create_local)(void* /*user*/, uint32_t /*id */, int /*sz*/);
|
||||
struct capn_segment *(*create_local)(void* /*user*/, int /*sz*/);
|
||||
void *user;
|
||||
/* zero initialized, user should not modify */
|
||||
uint32_t segnum;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue