aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-08-10 08:46:55 -0700
committerChris Robinson <[email protected]>2014-08-10 08:46:55 -0700
commit94013216b62ff6f78c46fb67bf6d7b9dcbe1170f (patch)
tree0e7968f792a32271657e651bafe9496abc419e88 /Alc
parent22856844c6a8e3e495680906936bc81f3ef25592 (diff)
Pass pointer-to-vector types as char* instead of void*
C aliasing rules only allow char* to alias an otherwise-incompatible type, rather than void*.
Diffstat (limited to 'Alc')
-rw-r--r--Alc/helpers.c16
-rw-r--r--Alc/vector.h17
2 files changed, 16 insertions, 17 deletions
diff --git a/Alc/helpers.c b/Alc/helpers.c
index 28efc82e..39a704fb 100644
--- a/Alc/helpers.c
+++ b/Alc/helpers.c
@@ -594,9 +594,9 @@ void SetRTPriority(void)
}
-ALboolean vector_reserve(void *ptr, size_t base_size, size_t obj_count, size_t obj_size, ALboolean exact)
+ALboolean vector_reserve(char *ptr, size_t base_size, size_t obj_count, size_t obj_size, ALboolean exact)
{
- vector_ *vecptr = ptr;
+ vector_ *vecptr = (vector_*)ptr;
if((size_t)(*vecptr ? (*vecptr)->Capacity : 0) < obj_count)
{
ALsizei old_size = (*vecptr ? (*vecptr)->Size : 0);
@@ -627,21 +627,21 @@ ALboolean vector_reserve(void *ptr, size_t base_size, size_t obj_count, size_t o
return AL_TRUE;
}
-ALboolean vector_resize(void *ptr, size_t base_size, size_t obj_count, size_t obj_size)
+ALboolean vector_resize(char *ptr, size_t base_size, size_t obj_count, size_t obj_size)
{
- vector_ *vecptr = ptr;
+ vector_ *vecptr = (vector_*)ptr;
if(*vecptr || obj_count > 0)
{
- if(!vector_reserve(vecptr, base_size, obj_count, obj_size, AL_TRUE))
+ if(!vector_reserve((char*)vecptr, base_size, obj_count, obj_size, AL_TRUE))
return AL_FALSE;
(*vecptr)->Size = (ALsizei)obj_count;
}
return AL_TRUE;
}
-ALboolean vector_insert(void *ptr, size_t base_size, size_t obj_size, void *ins_pos, const void *datstart, const void *datend)
+ALboolean vector_insert(char *ptr, size_t base_size, size_t obj_size, void *ins_pos, const void *datstart, const void *datend)
{
- vector_ *vecptr = ptr;
+ vector_ *vecptr = (vector_*)ptr;
if(datstart != datend)
{
ptrdiff_t ins_elem = ((char*)ins_pos - ((char*)(*vecptr) + base_size)) / obj_size;
@@ -649,7 +649,7 @@ ALboolean vector_insert(void *ptr, size_t base_size, size_t obj_size, void *ins_
assert(numins > 0);
if(INT_MAX-VECTOR_SIZE(*vecptr) <= numins ||
- !vector_reserve(vecptr, base_size, VECTOR_SIZE(*vecptr)+numins, obj_size, AL_TRUE))
+ !vector_reserve((char*)vecptr, base_size, VECTOR_SIZE(*vecptr)+numins, obj_size, AL_TRUE))
return AL_FALSE;
/* NOTE: ins_pos may have been invalidated if *vecptr moved. Use ins_elem instead. */
diff --git a/Alc/vector.h b/Alc/vector.h
index b98e87f4..b04b65eb 100644
--- a/Alc/vector.h
+++ b/Alc/vector.h
@@ -30,12 +30,11 @@ typedef const _##N* const_##N;
#define VECTOR_DEINIT(_x) do { free((_x)); (_x) = NULL; } while(0)
/* Helper to increase a vector's reserve. Do not call directly. */
-ALboolean vector_reserve(void *ptr, size_t base_size, size_t obj_count, size_t obj_size, ALboolean exact);
-#define VECTOR_RESERVE(_x, _c) (vector_reserve(&(_x), sizeof(*(_x)), (_c), sizeof((_x)->Data[0]), AL_TRUE))
+ALboolean vector_reserve(char *ptr, size_t base_size, size_t obj_count, size_t obj_size, ALboolean exact);
+#define VECTOR_RESERVE(_x, _c) (vector_reserve((char*)&(_x), sizeof(*(_x)), (_c), sizeof((_x)->Data[0]), AL_TRUE))
-/* Helper to change a vector's size. Do not call directly. */
-ALboolean vector_resize(void *ptr, size_t base_size, size_t obj_count, size_t obj_size);
-#define VECTOR_RESIZE(_x, _c) (vector_resize(&(_x), sizeof(*(_x)), (_c), sizeof((_x)->Data[0])))
+ALboolean vector_resize(char *ptr, size_t base_size, size_t obj_count, size_t obj_size);
+#define VECTOR_RESIZE(_x, _c) (vector_resize((char*)&(_x), sizeof(*(_x)), (_c), sizeof((_x)->Data[0])))
#define VECTOR_CAPACITY(_x) ((_x) ? (_x)->Capacity : 0)
#define VECTOR_SIZE(_x) ((_x) ? (_x)->Size : 0)
@@ -43,7 +42,7 @@ ALboolean vector_resize(void *ptr, size_t base_size, size_t obj_count, size_t ob
#define VECTOR_ITER_BEGIN(_x) ((_x)->Data + 0)
#define VECTOR_ITER_END(_x) ((_x)->Data + VECTOR_SIZE(_x))
-ALboolean vector_insert(void *ptr, size_t base_size, size_t obj_size, void *ins_pos, const void *datstart, const void *datend);
+ALboolean vector_insert(char *ptr, size_t base_size, size_t obj_size, void *ins_pos, const void *datstart, const void *datend);
#ifdef __GNUC__
#define TYPE_CHECK(T1, T2) __builtin_types_compatible_p(T1, T2)
#define VECTOR_INSERT(_x, _i, _s, _e) __extension__({ \
@@ -51,14 +50,14 @@ ALboolean vector_insert(void *ptr, size_t base_size, size_t obj_size, void *ins_
static_assert(TYPE_CHECK(__typeof((_x)->Data[0]), __typeof(*(_i))), "Incompatible insertion iterator"); \
static_assert(TYPE_CHECK(__typeof((_x)->Data[0]), __typeof(*(_s))), "Incompatible insertion source type"); \
static_assert(TYPE_CHECK(__typeof(*(_s)), __typeof(*(_e))), "Incompatible iterator sources"); \
- _r = vector_insert(&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i), (_s), (_e)); \
+ _r = vector_insert((char*)&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i), (_s), (_e)); \
_r; \
})
#else
-#define VECTOR_INSERT(_x, _i, _s, _e) (vector_insert(&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i), (_s), (_e)))
+#define VECTOR_INSERT(_x, _i, _s, _e) (vector_insert((char*)&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i), (_s), (_e)))
#endif
-#define VECTOR_PUSH_BACK(_x, _obj) (vector_reserve(&(_x), sizeof(*(_x)), VECTOR_SIZE(_x)+1, sizeof((_x)->Data[0]), AL_FALSE) && \
+#define VECTOR_PUSH_BACK(_x, _obj) (vector_reserve((char*)&(_x), sizeof(*(_x)), VECTOR_SIZE(_x)+1, sizeof((_x)->Data[0]), AL_FALSE) && \
(((_x)->Data[(_x)->Size++] = (_obj)),AL_TRUE))
#define VECTOR_POP_BACK(_x) ((void)((_x)->Size--))