aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-02-11 11:14:34 -0800
committerChris Robinson <[email protected]>2019-02-11 11:14:34 -0800
commit21aaa18c500c554fc6af39d9256b83cff8d07516 (patch)
treeeb0b8a3dd0f5b79f80aef37c8d58a3687ddf2747
parent995c9649cbaa16742ef7c9c20aa58e422ba90a35 (diff)
Get rid of the FAM_SIZE macro
-rw-r--r--OpenAL32/Include/alMain.h6
-rw-r--r--OpenAL32/Include/alSource.h6
-rw-r--r--OpenAL32/alSource.cpp8
3 files changed, 10 insertions, 10 deletions
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 1c1d9d90..e93d3db4 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -54,12 +54,6 @@ constexpr inline size_t countof(const T(&)[N]) noexcept
#endif
#endif
-/* Calculates the size of a struct with N elements of a flexible array member.
- * GCC and Clang allow offsetof(Type, fam[N]) for this, but MSVC seems to have
- * trouble, so a bit more verbose workaround is needed.
- */
-#define FAM_SIZE(T, M, N) (offsetof(T, M) + sizeof(((T*)NULL)->M[0])*(N))
-
using ALint64 = ALint64SOFT;
using ALuint64 = ALuint64SOFT;
diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h
index d02dbd5b..0343a943 100644
--- a/OpenAL32/Include/alSource.h
+++ b/OpenAL32/Include/alSource.h
@@ -21,6 +21,12 @@ struct ALbufferlistitem {
ALsizei max_samples;
ALsizei num_buffers;
ALbuffer *buffers[];
+
+ static constexpr size_t Sizeof(size_t num_buffers) noexcept
+ {
+ return maxz(offsetof(ALbufferlistitem, buffers) + sizeof(ALbuffer*)*num_buffers,
+ sizeof(ALbufferlistitem));
+ }
};
diff --git a/OpenAL32/alSource.cpp b/OpenAL32/alSource.cpp
index 7a711bfb..e15b0f59 100644
--- a/OpenAL32/alSource.cpp
+++ b/OpenAL32/alSource.cpp
@@ -1270,7 +1270,7 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co
{
/* Add the selected buffer to a one-item queue */
auto newlist = static_cast<ALbufferlistitem*>(al_calloc(DEF_ALIGN,
- FAM_SIZE(ALbufferlistitem, buffers, 1)));
+ ALbufferlistitem::Sizeof(1u)));
newlist->next.store(nullptr, std::memory_order_relaxed);
newlist->max_samples = buffer->SampleLen;
newlist->num_buffers = 1;
@@ -3019,13 +3019,13 @@ AL_API ALvoid AL_APIENTRY alSourceQueueBuffers(ALuint src, ALsizei nb, const ALu
if(!BufferListStart)
{
BufferListStart = static_cast<ALbufferlistitem*>(al_calloc(DEF_ALIGN,
- FAM_SIZE(ALbufferlistitem, buffers, 1)));
+ ALbufferlistitem::Sizeof(1u)));
BufferList = BufferListStart;
}
else
{
auto item = static_cast<ALbufferlistitem*>(al_calloc(DEF_ALIGN,
- FAM_SIZE(ALbufferlistitem, buffers, 1)));
+ ALbufferlistitem::Sizeof(1u)));
BufferList->next.store(item, std::memory_order_relaxed);
BufferList = item;
}
@@ -3122,7 +3122,7 @@ AL_API void AL_APIENTRY alSourceQueueBufferLayersSOFT(ALuint src, ALsizei nb, co
std::unique_lock<std::mutex> buflock{device->BufferLock};
auto BufferListStart = static_cast<ALbufferlistitem*>(al_calloc(DEF_ALIGN,
- FAM_SIZE(ALbufferlistitem, buffers, nb)));
+ ALbufferlistitem::Sizeof(nb)));
BufferList = BufferListStart;
BufferList->next.store(nullptr, std::memory_order_relaxed);
BufferList->max_samples = 0;