From 6855f6cdfee8c479f1e0ae440ce87a91ff41a708 Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Sat, 9 Apr 2016 03:16:30 +0200 Subject: Python-API: Inital commit of Python bindings for the VPP API. See: https://wiki.fd.io/view/VPP/Python_API Change-Id: If135fc32208c7031787e1935b399d930e0e1ea1f Signed-off-by: Ole Troan --- vlib-api/vlibmemory/memory_shared.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'vlib-api/vlibmemory/memory_shared.c') diff --git a/vlib-api/vlibmemory/memory_shared.c b/vlib-api/vlibmemory/memory_shared.c index ecd5cff7339..a32194310a4 100644 --- a/vlib-api/vlibmemory/memory_shared.c +++ b/vlib-api/vlibmemory/memory_shared.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -38,11 +39,6 @@ #include #undef vl_typedefs -typedef struct msgbuf_ { - unix_shared_memory_queue_t *q; - u8 data[0]; -} msgbuf_t; - static inline void *vl_msg_api_alloc_internal(int nbytes, int pool) { int i; @@ -119,12 +115,13 @@ static inline void *vl_msg_api_alloc_internal(int nbytes, int pool) pthread_mutex_lock (&am->vlib_rp->mutex); oldheap = svm_push_data_heap (am->vlib_rp); - rv = clib_mem_alloc(nbytes + sizeof(msgbuf_t)); + rv = clib_mem_alloc(nbytes); rv->q = 0; svm_pop_heap (oldheap); pthread_mutex_unlock (&am->vlib_rp->mutex); out: + rv->data_len = htonl(nbytes - sizeof(msgbuf_t)); return(rv->data); } @@ -152,7 +149,8 @@ void vl_msg_api_free(void *a) void *oldheap; api_main_t *am = &api_main; - rv = (msgbuf_t *)(((u8 *)a) - sizeof(*rv)); + rv = (msgbuf_t *)(((u8 *)a) - offsetof(msgbuf_t, data)); + /* * Here's the beauty of the scheme. Only one proc/thread has * control of a given message buffer. To free a buffer, we just clear the @@ -176,7 +174,7 @@ static void vl_msg_api_free_nolock (void *a) void *oldheap; api_main_t *am = &api_main; - rv = (msgbuf_t *)(((u8 *)a) - sizeof(*rv)); + rv = (msgbuf_t *)(((u8 *)a) - offsetof(msgbuf_t, data)); /* * Here's the beauty of the scheme. Only one proc/thread has * control of a given message buffer. To free a buffer, we just clear the -- cgit 1.2.3-korg