Fix name conflicts (C version)

Same as #952, but for C
This commit is contained in:
Daniil Kovalev 2021-05-08 16:51:02 +03:00
parent 825017ac50
commit 0f1d0ed78c
2 changed files with 19 additions and 17 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__)
#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
@ -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;
@ -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
@ -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;
}

View File

@ -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) {
@ -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;
}
@ -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;
}
@ -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;
@ -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;
@ -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;