Merge pull request #953 from kovdan01/fix_name_conflicts_c

Fix name conflicts (C)
This commit is contained in:
Takatoshi Kondo 2021-05-09 12:12:18 +09:00 committed by GitHub
commit 5d30e42c01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 19 deletions

View File

@ -16,11 +16,13 @@
#if defined(unix) || defined(__unix) || defined(__linux__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__QNX__) || defined(__QNXTO__) || defined(__HAIKU__) #if defined(unix) || defined(__unix) || defined(__linux__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__QNX__) || defined(__QNXTO__) || defined(__HAIKU__)
#include <sys/uio.h> #include <sys/uio.h>
typedef struct iovec msgpack_iovec;
#else #else
struct iovec { struct msgpack_iovec {
void *iov_base; void *iov_base;
size_t iov_len; size_t iov_len;
}; };
typedef struct msgpack_iovec msgpack_iovec;
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
@ -44,9 +46,9 @@ typedef struct msgpack_vrefbuffer_inner_buffer {
} msgpack_vrefbuffer_inner_buffer; } msgpack_vrefbuffer_inner_buffer;
typedef struct msgpack_vrefbuffer { typedef struct msgpack_vrefbuffer {
struct iovec* tail; msgpack_iovec* tail;
struct iovec* end; msgpack_iovec* end;
struct iovec* array; msgpack_iovec* array;
size_t chunk_size; size_t chunk_size;
size_t ref_size; size_t ref_size;
@ -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 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); static inline size_t msgpack_vrefbuffer_veclen(const msgpack_vrefbuffer* vref);
MSGPACK_DLLEXPORT MSGPACK_DLLEXPORT
@ -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; return vref->array;
} }

View File

@ -22,7 +22,7 @@ bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
size_t ref_size, size_t chunk_size) size_t ref_size, size_t chunk_size)
{ {
size_t nfirst; size_t nfirst;
struct iovec* array; msgpack_iovec* array;
msgpack_vrefbuffer_chunk* chunk; msgpack_vrefbuffer_chunk* chunk;
if (ref_size == 0) { if (ref_size == 0) {
@ -40,11 +40,11 @@ bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
return false; return false;
} }
nfirst = (sizeof(struct iovec) < 72/2) ? nfirst = (sizeof(msgpack_iovec) < 72/2) ?
72 / sizeof(struct iovec) : 8; 72 / sizeof(msgpack_iovec) : 8;
array = (struct iovec*)malloc( array = (msgpack_iovec*)malloc(
sizeof(struct iovec) * nfirst); sizeof(msgpack_iovec) * nfirst);
if(array == NULL) { if(array == NULL) {
return false; return false;
} }
@ -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 nused = (size_t)(vbuf->tail - vbuf->array);
const size_t nnext = nused * 2; const size_t nnext = nused * 2;
struct iovec* nvec = (struct iovec*)realloc( msgpack_iovec* nvec = (msgpack_iovec*)realloc(
vbuf->array, sizeof(struct iovec)*nnext); vbuf->array, sizeof(msgpack_iovec)*nnext);
if(nvec == NULL) { if(nvec == NULL) {
return -1; return -1;
} }
@ -194,7 +194,7 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
{ {
const size_t nused = (size_t)(vbuf->tail - vbuf->array); const size_t nused = (size_t)(vbuf->tail - vbuf->array);
if(to->tail + nused < vbuf->end) { 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 tosize = (size_t)(to->tail - to->array);
const size_t reqsize = nused + tosize; const size_t reqsize = nused + tosize;
size_t nnext = (size_t)(to->end - to->array) * 2; size_t nnext = (size_t)(to->end - to->array) * 2;
@ -207,8 +207,8 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
nnext = tmp_nnext; nnext = tmp_nnext;
} }
nvec = (struct iovec*)realloc( nvec = (msgpack_iovec*)realloc(
to->array, sizeof(struct iovec)*nnext); to->array, sizeof(msgpack_iovec)*nnext);
if(nvec == NULL) { if(nvec == NULL) {
free(empty); free(empty);
return -1; return -1;
@ -219,7 +219,7 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
to->tail = nvec + tosize; 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; to->tail += nused;
vbuf->tail = vbuf->array; vbuf->tail = vbuf->array;

View File

@ -102,7 +102,7 @@ TEST(buffer, vrefbuffer_c)
MSGPACK_VREFBUFFER_REF_SIZE + 1, MSGPACK_VREFBUFFER_REF_SIZE + 1,
ref_size, chunk_size + 1}; ref_size, chunk_size + 1};
size_t iovcnt; size_t iovcnt;
const iovec *iov; const msgpack_iovec *iov;
size_t len = 0, i; size_t len = 0, i;
char *buf; char *buf;

View File

@ -1616,7 +1616,7 @@ TEST(MSGPACKC, object_bin_print_buffer_overflow) {
#define GEN_TEST_VREFBUFFER_PREPARE(...) \ #define GEN_TEST_VREFBUFFER_PREPARE(...) \
msgpack_vrefbuffer vbuf; \ msgpack_vrefbuffer vbuf; \
msgpack_packer pk; \ msgpack_packer pk; \
const iovec *iov; \ const msgpack_iovec *iov; \
size_t iovcnt, len = 0, i; \ size_t iovcnt, len = 0, i; \
char buf[1024]; \ char buf[1024]; \
msgpack_vrefbuffer_init(&vbuf, 0, 0); \ msgpack_vrefbuffer_init(&vbuf, 0, 0); \