Get rid of the FAM_SIZE macro

This commit is contained in:
Chris Robinson
2019-02-11 11:14:34 -08:00
parent 995c9649cb
commit 21aaa18c50
3 changed files with 10 additions and 10 deletions
-6
View File
@@ -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;
+6
View File
@@ -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));
}
};
+4 -4
View File
@@ -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;