Skip to content

Commit 234c60d

Browse files
committed
Convert usize to a strong number type
1 parent ed87ca3 commit 234c60d

61 files changed

Lines changed: 454 additions & 435 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

al/auxeffectslot.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ auto EnsureEffectSlots(gsl::not_null<al::Context*> const context, usize const ne
271271
-> bool
272272
try {
273273
auto count = std::accumulate(context->mEffectSlotList.cbegin(),
274-
context->mEffectSlotList.cend(), 0_uz,
274+
context->mEffectSlotList.cend(), 0_usize,
275275
[](usize const cur, const EffectSlotSubList &sublist) noexcept -> usize
276-
{ return cur + sublist.mFreeMask.popcount().c_val; });
276+
{ return cur + sublist.mFreeMask.popcount(); });
277277

278278
while(needed > count)
279279
{

al/buffer.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ constexpr auto INVALID_MAP_FLAGS = ~gsl::narrow<ALbitfieldSOFT>(AL_MAP_READ_BIT_
184184
[[nodiscard]]
185185
auto EnsureBuffers(gsl::not_null<al::Device*> const device, usize const needed) noexcept -> bool
186186
try {
187-
auto count = std::accumulate(device->BufferList.cbegin(), device->BufferList.cend(), 0_uz,
187+
auto count = std::accumulate(device->BufferList.cbegin(), device->BufferList.cend(), 0_usize,
188188
[](usize const cur, const BufferSubList &sublist) noexcept -> usize
189-
{ return cur + sublist.mFreeMask.popcount().c_val; });
189+
{ return cur + sublist.mFreeMask.popcount(); });
190190

191191
while(needed > count)
192192
{
@@ -350,7 +350,7 @@ void LoadData(gsl::not_null<al::Context*> const context, gsl::not_null<al::Buffe
350350
if(blocks > std::numeric_limits<ALsizei>::max()/samplesPerBlock)
351351
context->throw_error(AL_OUT_OF_MEMORY,
352352
"Buffer size overflow, {} blocks x {} samples per block", blocks, samplesPerBlock);
353-
if(blocks > std::numeric_limits<usize>::max()/bytesPerBlock)
353+
if(blocks > usize::max()/bytesPerBlock)
354354
context->throw_error(AL_OUT_OF_MEMORY,
355355
"Buffer size overflow, {} frames x {} bytes per frame", blocks, bytesPerBlock);
356356

@@ -364,7 +364,7 @@ void LoadData(gsl::not_null<al::Context*> const context, gsl::not_null<al::Buffe
364364
}
365365
#endif
366366

367-
auto const newsize = usize{blocks} * bytesPerBlock;
367+
auto const newsize = std::size_t{blocks} * bytesPerBlock;
368368
auto const needRealloc = std::visit([ALBuf,DstType,newsize,access]<typename T>(T &datavec)
369369
-> bool
370370
{
@@ -566,7 +566,7 @@ void PrepareUserPtr(gsl::not_null<al::Context*> const context [[maybe_unused]],
566566
if(blocks > std::numeric_limits<ALsizei>::max()/samplesPerBlock)
567567
context->throw_error(AL_OUT_OF_MEMORY,
568568
"Buffer size overflow, {} blocks x {} samples per block", blocks, samplesPerBlock);
569-
if(blocks > std::numeric_limits<usize>::max()/bytesPerBlock)
569+
if(blocks > usize::max()/bytesPerBlock)
570570
context->throw_error(AL_OUT_OF_MEMORY,
571571
"Buffer size overflow, {} frames x {} bytes per frame", blocks, bytesPerBlock);
572572

@@ -926,15 +926,15 @@ try {
926926
(albuf->mType == FmtMSADPCM) ? ((align-2u)/2u + 7u) * num_chans :
927927
(align * albuf->bytesFromFmt() * num_chans);
928928

929-
if(offset < 0 || length < 0 || gsl::narrow_cast<usize>(offset) > albuf->mOriginalSize
930-
|| gsl::narrow_cast<usize>(length) > albuf->mOriginalSize - gsl::narrow_cast<usize>(offset))
929+
if(offset < 0 || length < 0 || usize::from(offset) > albuf->mOriginalSize
930+
|| usize::from(length) > albuf->mOriginalSize - usize::from(offset))
931931
context->throw_error(AL_INVALID_VALUE, "Invalid data sub-range {}+{} on buffer {}", offset,
932932
length, buffer);
933-
if((gsl::narrow_cast<usize>(offset)%byte_align) != 0)
933+
if((usize::from(offset)%byte_align) != 0)
934934
context->throw_error(AL_INVALID_VALUE,
935935
"Sub-range offset {} is not a multiple of frame size {} ({} unpack alignment)",
936936
offset, byte_align, align);
937-
if((gsl::narrow_cast<usize>(length)%byte_align) != 0)
937+
if((usize::from(length)%byte_align) != 0)
938938
context->throw_error(AL_INVALID_VALUE,
939939
"Sub-range length {} is not a multiple of frame size {} ({} unpack alignment)",
940940
length, byte_align, align);
@@ -980,12 +980,12 @@ try {
980980
if((unavailable&AL_MAP_PERSISTENT_BIT_SOFT))
981981
context->throw_error(AL_INVALID_VALUE,
982982
"Mapping buffer {} persistently without persistent access", buffer);
983-
if(offset < 0 || length <= 0 || gsl::narrow_cast<usize>(offset) >= albuf->mOriginalSize
984-
|| gsl::narrow_cast<usize>(length) > albuf->mOriginalSize - gsl::narrow_cast<usize>(offset))
983+
if(offset < 0 || length <= 0 || usize::from(offset) >= albuf->mOriginalSize
984+
|| usize::from(length) > albuf->mOriginalSize - usize::from(offset))
985985
context->throw_error(AL_INVALID_VALUE, "Mapping invalid range {}+{} for buffer {}", offset,
986986
length, buffer);
987987

988-
auto *const retval = std::visit([ptroff=gsl::narrow_cast<usize>(offset)](auto &datavec)
988+
auto *const retval = std::visit([ptroff=gsl::narrow<std::size_t>(offset)](auto &datavec)
989989
{ return &std::as_writable_bytes(datavec)[ptroff]; }, albuf->mData);
990990
albuf->mMappedAccess = access;
991991
albuf->mMappedOffset = offset;
@@ -1602,7 +1602,7 @@ try {
16021602
{
16031603
if(!buffer->mEaxXRamIsHardware)
16041604
{
1605-
if(std::numeric_limits<usize>::max() - buffer->mOriginalSize < total_needed)
1605+
if(usize::max() - buffer->mOriginalSize < total_needed)
16061606
context->throw_error(AL_OUT_OF_MEMORY, "Size overflow ({} + {})",
16071607
buffer->mOriginalSize, total_needed);
16081608

al/debug.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ try {
208208
context->throw_error(AL_INVALID_VALUE, "Null message pointer");
209209

210210
const auto msgview = (length < 0) ? std::string_view{message}
211-
: std::string_view{message, gsl::narrow_cast<usize>(length)};
211+
: std::string_view{message, gsl::narrow<std::size_t>(length)};
212212
if(msgview.size() >= MaxDebugMessageLength)
213213
context->throw_error(AL_INVALID_VALUE, "Debug message too long ({} >= {})", msgview.size(),
214214
MaxDebugMessageLength);
@@ -367,7 +367,7 @@ try {
367367
context->throw_error(AL_STACK_OVERFLOW_EXT, "Pushing too many debug groups");
368368

369369
context->mDebugGroups.emplace_back(*dsource, id,
370-
std::string_view{message, gsl::narrow_cast<usize>(length)});
370+
std::string_view{message, gsl::narrow<std::size_t>(length)});
371371
auto &oldback = *(context->mDebugGroups.end()-2);
372372
auto &newback = context->mDebugGroups.back();
373373

@@ -506,7 +506,7 @@ try {
506506
context->throw_error(AL_INVALID_VALUE, "Null label pointer");
507507

508508
auto objname = (length < 0) ? std::string_view{label}
509-
: std::string_view{label, gsl::narrow_cast<usize>(length)};
509+
: std::string_view{label, gsl::narrow<std::size_t>(length)};
510510
if(objname.size() >= MaxObjectLabelLength)
511511
context->throw_error(AL_INVALID_VALUE, "Object label length too long ({} >= {})",
512512
objname.size(), MaxObjectLabelLength);

al/effect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ void InitEffectParams(al::Effect *const effect, ALenum const type) noexcept
145145
[[nodiscard]]
146146
auto EnsureEffects(gsl::not_null<al::Device*> const device, usize const needed) noexcept -> bool
147147
try {
148-
auto count = std::accumulate(device->EffectList.cbegin(), device->EffectList.cend(), 0_uz,
148+
auto count = std::accumulate(device->EffectList.cbegin(), device->EffectList.cend(), 0_usize,
149149
[](usize const cur, const EffectSubList &sublist) noexcept -> usize
150-
{ return cur + sublist.mFreeMask.popcount().c_val; });
150+
{ return cur + sublist.mFreeMask.popcount(); });
151151

152152
while(needed > count)
153153
{

al/filter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ void InitFilterParams(gsl::not_null<al::Filter*> const filter, ALenum const type
287287
[[nodiscard]]
288288
auto EnsureFilters(gsl::not_null<al::Device*> const device, usize const needed) noexcept -> bool
289289
try {
290-
auto count = std::accumulate(device->FilterList.cbegin(), device->FilterList.cend(), 0_uz,
290+
auto count = std::accumulate(device->FilterList.cbegin(), device->FilterList.cend(), 0_usize,
291291
[](usize const cur, const FilterSubList &sublist) noexcept -> usize
292-
{ return cur + sublist.mFreeMask.popcount().c_val; });
292+
{ return cur + sublist.mFreeMask.popcount(); });
293293

294294
while(needed > count)
295295
{

al/source.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,9 @@ auto GetSourceState(gsl::not_null<al::Source*> const source, Voice const *const
730730

731731
auto EnsureSources(gsl::not_null<al::Context*> const context, usize const needed) -> bool
732732
{
733-
auto count = std::accumulate(context->mSourceList.cbegin(), context->mSourceList.cend(), 0_uz,
734-
[](usize const cur, const SourceSubList &sublist) noexcept -> usize
735-
{ return cur + sublist.mFreeMask.popcount().c_val; });
733+
auto count = std::accumulate(context->mSourceList.cbegin(), context->mSourceList.cend(),
734+
0_usize, [](usize const cur, const SourceSubList &sublist) noexcept -> usize
735+
{ return cur + sublist.mFreeMask.popcount(); });
736736

737737
try {
738738
while(needed > count)
@@ -783,7 +783,7 @@ void FreeSource(gsl::not_null<al::Context*> const context, gsl::not_null<al::Sou
783783
context->mSourceNames.erase(source->mId);
784784

785785
auto const id = source->mId - 1;
786-
auto const lidx = usize{id >> 6};
786+
auto const lidx = std::size_t{id >> 6};
787787
auto const slidx = id & 0x3f;
788788

789789
if(auto *const voice = GetSourceVoice(source, context))
@@ -838,7 +838,7 @@ auto LookupBuffer(std::nothrow_t, gsl::not_null<al::Device*> const device,
838838

839839
if(lidx >= device->BufferList.size()) [[unlikely]]
840840
return nullptr;
841-
auto &sublist = device->BufferList[gsl::narrow_cast<usize>(lidx)];
841+
auto &sublist = device->BufferList[gsl::narrow_cast<std::size_t>(lidx)];
842842
if((sublist.mFreeMask & (1_u64 << slidx)) != 0) [[unlikely]]
843843
return nullptr;
844844
return std::to_address(std::next(sublist.mBuffers->begin(),
@@ -863,7 +863,7 @@ auto LookupFilter(std::nothrow_t, gsl::not_null<al::Device*> const device,
863863

864864
if(lidx >= device->FilterList.size()) [[unlikely]]
865865
return nullptr;
866-
auto &sublist = device->FilterList[gsl::narrow_cast<usize>(lidx)];
866+
auto &sublist = device->FilterList[gsl::narrow_cast<std::size_t>(lidx)];
867867
if((sublist.mFreeMask & (1_u64 << slidx)) != 0) [[unlikely]]
868868
return nullptr;
869869
return std::to_address(std::next(sublist.mFilters->begin(),
@@ -888,7 +888,7 @@ auto LookupEffectSlot(std::nothrow_t, gsl::not_null<al::Context*> const context,
888888

889889
if(lidx >= context->mEffectSlotList.size()) [[unlikely]]
890890
return nullptr;
891-
auto &sublist = context->mEffectSlotList[gsl::narrow_cast<usize>(lidx)];
891+
auto &sublist = context->mEffectSlotList[gsl::narrow_cast<std::size_t>(lidx)];
892892
if((sublist.mFreeMask & (1_u64 << slidx)) != 0) [[unlikely]]
893893
return nullptr;
894894
return std::to_address(std::next(sublist.mEffectSlots->begin(),
@@ -1464,12 +1464,12 @@ struct PairStruct { T First; U Second; };
14641464
template<typename T, typename U>
14651465
PairStruct(T, U) -> PairStruct<T, U>;
14661466

1467-
template<typename T, usize N>
1467+
template<typename T, std::size_t N>
14681468
auto GetCheckers(gsl::not_null<al::Context*> const context, SourceProp const prop,
14691469
std::span<T,N> const values)
14701470
{
14711471
return PairStruct{
1472-
[=](usize const expect) -> void
1472+
[=](std::size_t const expect) -> void
14731473
{
14741474
if(values.size() == expect) return;
14751475
context->throw_error(AL_INVALID_ENUM, "Property {:#04x} expects {} value{}, got {}",
@@ -1999,7 +1999,7 @@ void SetProperty(const gsl::not_null<al::Source*> Source,
19991999

20002000
if(sendidx >= device->NumAuxSends)
20012001
Context->throw_error(AL_INVALID_VALUE, "Invalid send {}", sendidx);
2002-
auto &send = Source->mSend[gsl::narrow_cast<usize>(sendidx)];
2002+
auto &send = Source->mSend[gsl::narrow_cast<std::size_t>(sendidx)];
20032003

20042004
if(filterid)
20052005
{
@@ -2048,11 +2048,11 @@ void SetProperty(const gsl::not_null<al::Source*> Source,
20482048
}
20492049

20502050

2051-
template<typename T, usize N>
2051+
template<typename T, std::size_t N>
20522052
auto GetSizeChecker(gsl::not_null<al::Context*> const context, SourceProp const prop,
20532053
std::span<T,N> const values)
20542054
{
2055-
return [=](usize const expect) -> void
2055+
return [=](std::size_t const expect) -> void
20562056
{
20572057
if(values.size() == expect) [[likely]] return;
20582058
context->throw_error(AL_INVALID_ENUM, "Property {:#04x} expects {} value{}, got {}",
@@ -3518,7 +3518,7 @@ try {
35183518
/* A buffer failed (invalid ID or format), or there was some other
35193519
* unexpected error, so release the buffers we had.
35203520
*/
3521-
source->mQueue.resize(gsl::narrow_cast<usize>(NewListStart));
3521+
source->mQueue.resize(gsl::narrow_cast<std::size_t>(NewListStart));
35223522
throw;
35233523
}
35243524
/* All buffers good. */
@@ -3556,7 +3556,7 @@ try {
35563556

35573557
/* Make sure enough buffers have been processed to unqueue. */
35583558
const auto bids = std::views::counted(buffers, nb);
3559-
auto processed = 0_uz;
3559+
auto processed = 0_usize;
35603560
if(source->mState != AL_INITIAL) [[likely]]
35613561
{
35623562
const auto Current = std::invoke([source,context]() -> const VoiceBufferItem*
@@ -3567,7 +3567,7 @@ try {
35673567
});
35683568
const auto qiter = std::ranges::find(source->mQueue, Current,
35693569
[](al::BufferQueueItem const &item) { return &item; });
3570-
processed = gsl::narrow_cast<usize>(std::distance(source->mQueue.begin(), qiter));
3570+
processed = isize{std::distance(source->mQueue.begin(), qiter)}.reinterpret_as<usize>();
35713571
}
35723572
if(processed < bids.size())
35733573
context->throw_error(AL_INVALID_VALUE, "Unqueueing {} buffer{} (only {} processed)",
@@ -3576,7 +3576,7 @@ try {
35763576
std::ranges::generate(bids, [source]() noexcept -> ALuint
35773577
{
35783578
auto bid = 0u;
3579-
if(auto *buffer = source->mQueue.front().mBuffer.get())
3579+
if(auto const *const buffer = source->mQueue.front().mBuffer.get())
35803580
bid = buffer->mId;
35813581
source->mQueue.pop_front();
35823582
return bid;
@@ -3750,7 +3750,7 @@ void al::Source::eax_fail_unknown_receiving_fx_slot_id() {eax_fail("Unknown rece
37503750

37513751
void al::Source::eax_set_sends_defaults(EaxSends& sends, const EaxFxSlotIds& ids) noexcept
37523752
{
3753-
for(auto const i : std::views::iota(0_uz, usize{EAX_MAX_FXSLOTS}))
3753+
for(auto const i : std::views::iota(0_uz, std::size_t{EAX_MAX_FXSLOTS}))
37543754
{
37553755
auto& send = sends[i];
37563756
send.guidReceivingFXSlotID = *(ids[i]);
@@ -3863,7 +3863,7 @@ void al::Source::eax5_set_active_fx_slots_defaults(EAX50ACTIVEFXSLOTS& slots) no
38633863

38643864
void al::Source::eax5_set_speaker_levels_defaults(EaxSpeakerLevels& speaker_levels) noexcept
38653865
{
3866-
for(auto const i : std::views::iota(0_uz, usize{eax_max_speakers}))
3866+
for(auto const i : std::views::iota(0_uz, std::size_t{eax_max_speakers}))
38673867
{
38683868
auto& speaker_level = speaker_levels[i];
38693869
speaker_level.lSpeakerID = gsl::narrow_cast<eax_long>(EAXSPEAKER_FRONT_LEFT + i);
@@ -3968,7 +3968,7 @@ void al::Source::eax4_translate(const Eax4Props& src, Eax5Props& dst) noexcept
39683968
//
39693969
dst.sends = src.sends;
39703970

3971-
for(auto const i : std::views::iota(0_uz, usize{EAX_MAX_FXSLOTS}))
3971+
for(auto const i : std::views::iota(0_uz, std::size_t{EAX_MAX_FXSLOTS}))
39723972
dst.sends[i].guidReceivingFXSlotID = *(eax5_fx_slot_ids[i]);
39733973

39743974
// Active FX slots.
@@ -4018,7 +4018,7 @@ auto al::Source::eax_create_direct_filter_param() const noexcept -> EaxAlLowPass
40184018
* source.mObstruction.flObstructionLFRatio;
40194019
auto gainhf_mb = gsl::narrow_cast<float>(source.mObstruction.lObstruction);
40204020

4021-
for(const auto i : std::views::iota(0_uz, usize{EAX_MAX_FXSLOTS}))
4021+
for(const auto i : std::views::iota(0_uz, std::size_t{EAX_MAX_FXSLOTS}))
40224022
{
40234023
if(!mEaxActiveFxSlots.test(i))
40244024
continue;
@@ -4123,7 +4123,7 @@ void al::Source::eax_update_direct_filter()
41234123

41244124
void al::Source::eax_update_room_filters()
41254125
{
4126-
for(const auto i : std::views::iota(0_uz, usize{EAX_MAX_FXSLOTS}))
4126+
for(const auto i : std::views::iota(0_uz, std::size_t{EAX_MAX_FXSLOTS}))
41274127
{
41284128
if(!mEaxActiveFxSlots.test(i))
41294129
continue;
@@ -4444,7 +4444,7 @@ void al::Source::eax5_defer_speaker_levels(const EaxCall& call, EaxSpeakerLevels
44444444

44454445
for(const auto &value : values)
44464446
{
4447-
const auto index = gsl::narrow_cast<usize>(value.lSpeakerID - EAXSPEAKER_FRONT_LEFT);
4447+
const auto index = gsl::narrow_cast<std::size_t>(value.lSpeakerID-EAXSPEAKER_FRONT_LEFT);
44484448
props[index].lLevel = value.lLevel;
44494449
}
44504450
}
@@ -4774,7 +4774,7 @@ void al::Source::eax_get(const EaxCall &call) const
47744774
}
47754775

47764776
void al::Source::eax_set_al_source_send(al::intrusive_ptr<al::EffectSlot> slot,
4777-
usize const sendidx, const EaxAlLowPassParam &filter)
4777+
std::size_t const sendidx, const EaxAlLowPassParam &filter)
47784778
{
47794779
if(sendidx >= EAX_MAX_FXSLOTS)
47804780
return;
@@ -4819,7 +4819,7 @@ void al::Source::eax_commit_active_fx_slots()
48194819

48204820
// Deactivate EFX auxiliary effect slots for inactive slots. Active slots
48214821
// will be updated with the room filters.
4822-
for(const auto i : std::views::iota(0_uz, usize{EAX_MAX_FXSLOTS}))
4822+
for(const auto i : std::views::iota(0_uz, std::size_t{EAX_MAX_FXSLOTS}))
48234823
{
48244824
if(!mEaxActiveFxSlots.test(i))
48254825
eax_set_al_source_send({}, i, EaxAlLowPassParam{1.0f, 1.0f});

al/source.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ struct Source {
10071007
void eax_set(const EaxCall& call);
10081008

10091009
// `alSource3i(source, AL_AUXILIARY_SEND_FILTER, ...)`
1010-
void eax_set_al_source_send(intrusive_ptr<EffectSlot> slot, usize sendidx,
1010+
void eax_set_al_source_send(intrusive_ptr<EffectSlot> slot, std::size_t sendidx,
10111011
EaxAlLowPassParam const &filter);
10121012

10131013
void eax_commit_active_fx_slots();

alc/alc.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ auto UpdateDeviceParams(gsl::not_null<al::Device*> device,
16771677
case DevFmtAmbi3D: break;
16781678
}
16791679

1680-
auto sample_delay = 0_uz;
1680+
auto sample_delay = 0_usize;
16811681
if(auto *uhjenc = std::get_if<UhjPostProcess>(&device->mPostProcess))
16821682
sample_delay += uhjenc->mUhjEncoder->getDelay();
16831683

@@ -1770,8 +1770,8 @@ auto UpdateDeviceParams(gsl::not_null<al::Device*> device,
17701770
}
17711771

17721772
/* Convert the sample delay from samples to nanosamples to nanoseconds. */
1773-
sample_delay = std::min(sample_delay, usize{std::numeric_limits<int>::max()});
1774-
device->FixedLatency += nanoseconds{seconds{sample_delay}} / device->mSampleRate;
1773+
sample_delay = std::min(sample_delay, i32::max().as<usize>());
1774+
device->FixedLatency += nanoseconds{seconds{sample_delay.c_val}} / device->mSampleRate;
17751775
TRACE("Fixed device latency: {}ns", device->FixedLatency.count());
17761776

17771777
auto mixer_mode = FPUCtl{};
@@ -2203,7 +2203,7 @@ DefineAlcAlias(alcGetString)
22032203

22042204
namespace {
22052205
auto GetIntegerv(al::Device *const device, ALCenum const param, std::span<ALCint> const values)
2206-
-> usize
2206+
-> std::size_t
22072207
{
22082208
Expects(!values.empty());
22092209

@@ -3385,7 +3385,7 @@ try {
33853385
}
33863386

33873387
backend->captureSamples(std::span{static_cast<std::byte*>(buffer),
3388-
usize{usamples}*dev->frameSizeFromFmt()});
3388+
std::size_t{usamples}*dev->frameSizeFromFmt()});
33893389
}
33903390
catch(al::base_exception&) {
33913391
}

0 commit comments

Comments
 (0)