Commit b7b3b19f authored by Pavel Emelyanov's avatar Pavel Emelyanov

pb: Add a helper to collect single entry

Reviewed-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 41df032e
...@@ -40,6 +40,7 @@ struct collect_image_info { ...@@ -40,6 +40,7 @@ struct collect_image_info {
#define COLLECT_HAPPENED 0x4 /* image was opened and collected */ #define COLLECT_HAPPENED 0x4 /* image was opened and collected */
extern int collect_image(struct collect_image_info *); extern int collect_image(struct collect_image_info *);
extern int collect_entry(ProtobufCMessage *base, struct collect_image_info *cinfo);
static inline int collect_images(struct collect_image_info **array, unsigned size) static inline int collect_images(struct collect_image_info **array, unsigned size)
{ {
......
...@@ -172,6 +172,37 @@ err: ...@@ -172,6 +172,37 @@ err:
return ret; return ret;
} }
int collect_entry(ProtobufCMessage *msg, struct collect_image_info *cinfo)
{
void *obj;
void *(*o_alloc)(size_t size) = malloc;
void (*o_free)(void *ptr) = free;
if (cinfo->flags & COLLECT_SHARED) {
o_alloc = shmalloc;
o_free = shfree_last;
}
if (cinfo->priv_size) {
obj = o_alloc(cinfo->priv_size);
if (!obj)
return -1;
} else
obj = NULL;
cinfo->flags |= COLLECT_HAPPENED;
if (cinfo->collect(obj, msg, NULL) < 0) {
o_free(obj);
cr_pb_descs[cinfo->pb_type].free(msg, NULL);
return -1;
}
if (!cinfo->priv_size && !(cinfo->flags & COLLECT_NOFREE))
cr_pb_descs[cinfo->pb_type].free(msg, NULL);
return 0;
}
int collect_image(struct collect_image_info *cinfo) int collect_image(struct collect_image_info *cinfo)
{ {
int ret; int ret;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment