diff options
author | Chris Robinson <[email protected]> | 2014-04-19 02:38:32 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-04-19 03:11:23 -0700 |
commit | 1d266aa8347fadfb0db34ae27df7b728c0ab2171 (patch) | |
tree | f194a04fa74b3fe9deb0b619c7b7d3eab21602dd /OpenAL32/Include | |
parent | 59fc9aac0ee41518dba0cbd2f1518decffeaa480 (diff) |
Add a GCC-specific STATIC_UPCAST macro that checks the object type
The check is compile time, and is functionally identical to the old/alternate
version.
Diffstat (limited to 'OpenAL32/Include')
-rw-r--r-- | OpenAL32/Include/alAuxEffectSlot.h | 2 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 9 |
2 files changed, 9 insertions, 2 deletions
diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h index 75eb87ca..bc871111 100644 --- a/OpenAL32/Include/alAuxEffectSlot.h +++ b/OpenAL32/Include/alAuxEffectSlot.h @@ -33,7 +33,7 @@ DECLARE_THUNK1(T, ALeffectState, ALboolean, deviceUpdate, ALCdevice*) \ DECLARE_THUNK2(T, ALeffectState, void, update, ALCdevice*, const ALeffectslot*) \ DECLARE_THUNK3(T, ALeffectState, void, process, ALuint, const ALfloat*restrict, ALfloatBUFFERSIZE*restrict) \ static void T##_ALeffectState_Delete(void *ptr) \ -{ return T##_Delete(STATIC_UPCAST(T, ALeffectState, ptr)); } \ +{ return T##_Delete(STATIC_UPCAST(T, ALeffectState, (ALeffectState*)ptr)); } \ \ static const struct ALeffectStateVtable T##_ALeffectState_vtable = { \ T##_ALeffectState_Destruct, \ diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index ad305c4e..8b66e4e7 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -348,8 +348,15 @@ static const union { #define DERIVE_FROM_TYPE(t) t t##_parent #define STATIC_CAST(to, obj) (&(obj)->to##_parent) +#ifdef __GNUC__ +#define STATIC_UPCAST(to, from, obj) __extension__({ \ + static_assert(__builtin_types_compatible_p(from, __typeof(*(obj))), \ + "Invalid upcast object from type"); \ + (to*)((char*)(obj) - offsetof(to, from##_parent)); \ +}) +#else #define STATIC_UPCAST(to, from, obj) ((to*)((char*)(obj) - offsetof(to, from##_parent))) - +#endif #define DECLARE_FORWARD(T1, T2, rettype, func) \ rettype T1##_##func(T1 *obj) \ |