Skip to content

Commit

Permalink
Merge pull request #953 from kovdan01/fix_name_conflicts_c
Browse files Browse the repository at this point in the history
Fix name conflicts (C)
  • Loading branch information
redboltz authored May 9, 2021
2 parents 825017a + 6b4a7b3 commit 5d30e42
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
14 changes: 8 additions & 6 deletions include/msgpack/vrefbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

#if defined(unix) || defined(__unix) || defined(__linux__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__QNX__) || defined(__QNXTO__) || defined(__HAIKU__)
#include <sys/uio.h>
typedef struct iovec msgpack_iovec;
#else
struct iovec {
struct msgpack_iovec {
void *iov_base;
size_t iov_len;
};
typedef struct msgpack_iovec msgpack_iovec;
#endif

#ifdef __cplusplus
Expand All @@ -44,9 +46,9 @@ typedef struct msgpack_vrefbuffer_inner_buffer {
} msgpack_vrefbuffer_inner_buffer;

typedef struct msgpack_vrefbuffer {
struct iovec* tail;
struct iovec* end;
struct iovec* array;
msgpack_iovec* tail;
msgpack_iovec* end;
msgpack_iovec* array;

size_t chunk_size;
size_t ref_size;
Expand Down Expand Up @@ -74,7 +76,7 @@ static inline void msgpack_vrefbuffer_free(msgpack_vrefbuffer* vbuf);

static inline int msgpack_vrefbuffer_write(void* data, const char* buf, size_t len);

static inline const struct iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref);
static inline const msgpack_iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref);
static inline size_t msgpack_vrefbuffer_veclen(const msgpack_vrefbuffer* vref);

MSGPACK_DLLEXPORT
Expand Down Expand Up @@ -126,7 +128,7 @@ static inline int msgpack_vrefbuffer_write(void* data, const char* buf, size_t l
}
}

static inline const struct iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref)
static inline const msgpack_iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref)
{
return vref->array;
}
Expand Down
22 changes: 11 additions & 11 deletions src/vrefbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
size_t ref_size, size_t chunk_size)
{
size_t nfirst;
struct iovec* array;
msgpack_iovec* array;
msgpack_vrefbuffer_chunk* chunk;

if (ref_size == 0) {
Expand All @@ -40,11 +40,11 @@ bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
return false;
}

nfirst = (sizeof(struct iovec) < 72/2) ?
72 / sizeof(struct iovec) : 8;
nfirst = (sizeof(msgpack_iovec) < 72/2) ?
72 / sizeof(msgpack_iovec) : 8;

array = (struct iovec*)malloc(
sizeof(struct iovec) * nfirst);
array = (msgpack_iovec*)malloc(
sizeof(msgpack_iovec) * nfirst);
if(array == NULL) {
return false;
}
Expand Down Expand Up @@ -114,8 +114,8 @@ int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf,
const size_t nused = (size_t)(vbuf->tail - vbuf->array);
const size_t nnext = nused * 2;

struct iovec* nvec = (struct iovec*)realloc(
vbuf->array, sizeof(struct iovec)*nnext);
msgpack_iovec* nvec = (msgpack_iovec*)realloc(
vbuf->array, sizeof(msgpack_iovec)*nnext);
if(nvec == NULL) {
return -1;
}
Expand Down Expand Up @@ -194,7 +194,7 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
{
const size_t nused = (size_t)(vbuf->tail - vbuf->array);
if(to->tail + nused < vbuf->end) {
struct iovec* nvec;
msgpack_iovec* nvec;
const size_t tosize = (size_t)(to->tail - to->array);
const size_t reqsize = nused + tosize;
size_t nnext = (size_t)(to->end - to->array) * 2;
Expand All @@ -207,8 +207,8 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
nnext = tmp_nnext;
}

nvec = (struct iovec*)realloc(
to->array, sizeof(struct iovec)*nnext);
nvec = (msgpack_iovec*)realloc(
to->array, sizeof(msgpack_iovec)*nnext);
if(nvec == NULL) {
free(empty);
return -1;
Expand All @@ -219,7 +219,7 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
to->tail = nvec + tosize;
}

memcpy(to->tail, vbuf->array, sizeof(struct iovec)*nused);
memcpy(to->tail, vbuf->array, sizeof(msgpack_iovec)*nused);

to->tail += nused;
vbuf->tail = vbuf->array;
Expand Down
2 changes: 1 addition & 1 deletion test/buffer_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ TEST(buffer, vrefbuffer_c)
MSGPACK_VREFBUFFER_REF_SIZE + 1,
ref_size, chunk_size + 1};
size_t iovcnt;
const iovec *iov;
const msgpack_iovec *iov;
size_t len = 0, i;
char *buf;

Expand Down
2 changes: 1 addition & 1 deletion test/msgpack_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ TEST(MSGPACKC, object_bin_print_buffer_overflow) {
#define GEN_TEST_VREFBUFFER_PREPARE(...) \
msgpack_vrefbuffer vbuf; \
msgpack_packer pk; \
const iovec *iov; \
const msgpack_iovec *iov; \
size_t iovcnt, len = 0, i; \
char buf[1024]; \
msgpack_vrefbuffer_init(&vbuf, 0, 0); \
Expand Down

0 comments on commit 5d30e42

Please sign in to comment.