Skip to content

Commit

Permalink
Remove void from empty parameter lists
Browse files Browse the repository at this point in the history
Also convert some functions to trailing return types and remove (void) casts.
  • Loading branch information
kcat committed Dec 13, 2023
1 parent 60aa22f commit bdd5401
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 66 deletions.
28 changes: 14 additions & 14 deletions al/direct_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,47 @@ constexpr void DefaultVal() noexcept { }
} // namespace detail_

#define DECL_FUNC(R, Name) \
R AL_APIENTRY Name(void) noexcept \
auto AL_APIENTRY Name() noexcept -> R \
{ \
auto context = GetContextRef(); \
if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
return Name##Direct(context.get()); \
}

#define DECL_FUNC1(R, Name, T1) \
R AL_APIENTRY Name(T1 a) noexcept \
auto AL_APIENTRY Name(T1 a) noexcept -> R \
{ \
auto context = GetContextRef(); \
if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
return Name##Direct(context.get(), a); \
}

#define DECL_FUNC2(R, Name, T1, T2) \
R AL_APIENTRY Name(T1 a, T2 b) noexcept \
auto AL_APIENTRY Name(T1 a, T2 b) noexcept -> R \
{ \
auto context = GetContextRef(); \
if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
return Name##Direct(context.get(), a, b); \
}

#define DECL_FUNC3(R, Name, T1, T2, T3) \
R AL_APIENTRY Name(T1 a, T2 b, T3 c) noexcept \
auto AL_APIENTRY Name(T1 a, T2 b, T3 c) noexcept -> R \
{ \
auto context = GetContextRef(); \
if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
return Name##Direct(context.get(), a, b, c); \
}

#define DECL_FUNC4(R, Name, T1, T2, T3, T4) \
R AL_APIENTRY Name(T1 a, T2 b, T3 c, T4 d) noexcept \
auto AL_APIENTRY Name(T1 a, T2 b, T3 c, T4 d) noexcept -> R \
{ \
auto context = GetContextRef(); \
if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
return Name##Direct(context.get(), a, b, c, d); \
}

#define DECL_FUNC5(R, Name, T1, T2, T3, T4, T5) \
R AL_APIENTRY Name(T1 a, T2 b, T3 c, T4 d, T5 e) noexcept \
auto AL_APIENTRY Name(T1 a, T2 b, T3 c, T4 d, T5 e) noexcept -> R \
{ \
auto context = GetContextRef(); \
if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
Expand All @@ -61,63 +61,63 @@ R AL_APIENTRY Name(T1 a, T2 b, T3 c, T4 d, T5 e) noexcept \


#define DECL_FUNCEXT(R, Name,Ext) \
R AL_APIENTRY Name##Ext(void) noexcept \
auto AL_APIENTRY Name##Ext() noexcept -> R \
{ \
auto context = GetContextRef(); \
if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
return Name##Direct##Ext(context.get()); \
}

#define DECL_FUNCEXT1(R, Name,Ext, T1) \
R AL_APIENTRY Name##Ext(T1 a) noexcept \
auto AL_APIENTRY Name##Ext(T1 a) noexcept -> R \
{ \
auto context = GetContextRef(); \
if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
return Name##Direct##Ext(context.get(), a); \
}

#define DECL_FUNCEXT2(R, Name,Ext, T1, T2) \
R AL_APIENTRY Name##Ext(T1 a, T2 b) noexcept \
auto AL_APIENTRY Name##Ext(T1 a, T2 b) noexcept -> R \
{ \
auto context = GetContextRef(); \
if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
return Name##Direct##Ext(context.get(), a, b); \
}

#define DECL_FUNCEXT3(R, Name,Ext, T1, T2, T3) \
R AL_APIENTRY Name##Ext(T1 a, T2 b, T3 c) noexcept \
auto AL_APIENTRY Name##Ext(T1 a, T2 b, T3 c) noexcept -> R \
{ \
auto context = GetContextRef(); \
if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
return Name##Direct##Ext(context.get(), a, b, c); \
}

#define DECL_FUNCEXT4(R, Name,Ext, T1, T2, T3, T4) \
R AL_APIENTRY Name##Ext(T1 a, T2 b, T3 c, T4 d) noexcept \
auto AL_APIENTRY Name##Ext(T1 a, T2 b, T3 c, T4 d) noexcept -> R \
{ \
auto context = GetContextRef(); \
if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
return Name##Direct##Ext(context.get(), a, b, c, d); \
}

#define DECL_FUNCEXT5(R, Name,Ext, T1, T2, T3, T4, T5) \
R AL_APIENTRY Name##Ext(T1 a, T2 b, T3 c, T4 d, T5 e) noexcept \
auto AL_APIENTRY Name##Ext(T1 a, T2 b, T3 c, T4 d, T5 e) noexcept -> R \
{ \
auto context = GetContextRef(); \
if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
return Name##Direct##Ext(context.get(), a, b, c, d, e); \
}

#define DECL_FUNCEXT6(R, Name,Ext, T1, T2, T3, T4, T5, T6) \
R AL_APIENTRY Name##Ext(T1 a, T2 b, T3 c, T4 d, T5 e, T6 f) noexcept \
auto AL_APIENTRY Name##Ext(T1 a, T2 b, T3 c, T4 d, T5 e, T6 f) noexcept -> R \
{ \
auto context = GetContextRef(); \
if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
return Name##Direct##Ext(context.get(), a, b, c, d, e, f); \
}

#define DECL_FUNCEXT8(R, Name,Ext, T1, T2, T3, T4, T5, T6, T7, T8) \
R AL_APIENTRY Name##Ext(T1 a, T2 b, T3 c, T4 d, T5 e, T6 f, T7 g, T8 h) noexcept \
auto AL_APIENTRY Name##Ext(T1 a, T2 b, T3 c, T4 d, T5 e, T6 f, T7 g, T8 h) noexcept -> R \
{ \
auto context = GetContextRef(); \
if(!context) UNLIKELY return detail_::DefaultVal<R>(); \
Expand Down
54 changes: 26 additions & 28 deletions al/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,41 +99,39 @@ void ALCcontext::setError(ALenum errorCode, const char *msg, ...)
/* Special-case alGetError since it (potentially) raises a debug signal and
* returns a non-default value for a null context.
*/
AL_API ALenum AL_APIENTRY alGetError(void) noexcept
AL_API auto AL_APIENTRY alGetError() noexcept -> ALenum
{
auto context = GetContextRef();
if(!context) UNLIKELY
if(auto context = GetContextRef()) LIKELY
return alGetErrorDirect(context.get());

static const ALenum deferror{[](const char *envname, const char *optname) -> ALenum
{
static const ALenum deferror{[](const char *envname, const char *optname) -> ALenum
{
auto optstr = al::getenv(envname);
if(!optstr)
optstr = ConfigValueStr(nullptr, "game_compat", optname);

if(optstr)
{
char *end{};
auto value = std::strtoul(optstr->c_str(), &end, 0);
if(end && *end == '\0' && value <= std::numeric_limits<ALenum>::max())
return static_cast<ALenum>(value);
ERR("Invalid default error value: \"%s\"", optstr->c_str());
}
return AL_INVALID_OPERATION;
}("__ALSOFT_DEFAULT_ERROR", "default-error")};

WARN("Querying error state on null context (implicitly 0x%04x)\n", deferror);
if(TrapALError)
auto optstr = al::getenv(envname);
if(!optstr)
optstr = ConfigValueStr(nullptr, "game_compat", optname);

if(optstr)
{
char *end{};
auto value = std::strtoul(optstr->c_str(), &end, 0);
if(end && *end == '\0' && value <= std::numeric_limits<ALenum>::max())
return static_cast<ALenum>(value);
ERR("Invalid default error value: \"%s\"", optstr->c_str());
}
return AL_INVALID_OPERATION;
}("__ALSOFT_DEFAULT_ERROR", "default-error")};

WARN("Querying error state on null context (implicitly 0x%04x)\n", deferror);
if(TrapALError)
{
#ifdef _WIN32
if(IsDebuggerPresent())
DebugBreak();
if(IsDebuggerPresent())
DebugBreak();
#elif defined(SIGTRAP)
raise(SIGTRAP);
raise(SIGTRAP);
#endif
}
return deferror;
}
return alGetErrorDirect(context.get());
return deferror;
}

FORCE_ALIGN ALenum AL_APIENTRY alGetErrorDirect(ALCcontext *context) noexcept
Expand Down
6 changes: 3 additions & 3 deletions al/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ inline void UpdateProps(ALCcontext *context)
/* WARNING: Non-standard export! Not part of any extension, or exposed in the
* alcFunctions list.
*/
AL_API const ALchar* AL_APIENTRY alsoft_get_version(void) noexcept
AL_API auto AL_APIENTRY alsoft_get_version() noexcept -> const ALchar*
{
static const auto spoof = al::getenv("ALSOFT_SPOOF_VERSION");
if(spoof) return spoof->c_str();
Expand Down Expand Up @@ -388,15 +388,15 @@ FORCE_ALIGN ALboolean AL_APIENTRY alIsEnabledDirect(ALCcontext *context, ALenum
}

#define DECL_GETFUNC(R, Name, Ext) \
AL_API R AL_APIENTRY Name##Ext(ALenum pname) noexcept \
AL_API auto AL_APIENTRY Name##Ext(ALenum pname) noexcept -> R \
{ \
R value{}; \
auto context = GetContextRef(); \
if(!context) UNLIKELY return value; \
Name##vDirect##Ext(GetContextRef().get(), pname, &value); \
return value; \
} \
FORCE_ALIGN R AL_APIENTRY Name##Direct##Ext(ALCcontext *context, ALenum pname) noexcept \
FORCE_ALIGN auto AL_APIENTRY Name##Direct##Ext(ALCcontext *context, ALenum pname) noexcept -> R \
{ \
R value{}; \
Name##vDirect##Ext(context, pname, &value); \
Expand Down
4 changes: 2 additions & 2 deletions alc/alc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2782,15 +2782,15 @@ ALC_API void ALC_APIENTRY alcDestroyContext(ALCcontext *context) noexcept
}


ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(void) noexcept
ALC_API auto ALC_APIENTRY alcGetCurrentContext() noexcept -> ALCcontext*
{
ALCcontext *Context{ALCcontext::getThreadContext()};
if(!Context) Context = ALCcontext::sGlobalContext.load();
return Context;
}

/** Returns the currently active thread-local context. */
ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void) noexcept
ALC_API auto ALC_APIENTRY alcGetThreadContext() noexcept -> ALCcontext*
{ return ALCcontext::getThreadContext(); }

ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context) noexcept
Expand Down
2 changes: 1 addition & 1 deletion common/opthelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#elif HAS_BUILTIN(__builtin_unreachable)
#define ASSUME(x) do { if(x) break; __builtin_unreachable(); } while(0)
#else
#define ASSUME(x) ((void)0)
#define ASSUME(x) (static_cast<void>(0))
#endif

/* This shouldn't be needed since unknown attributes are ignored, but older
Expand Down
2 changes: 1 addition & 1 deletion core/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ std::vector<std::string> SearchDataFiles(const char *ext, const char *subdir)
return results;
}

void SetRTPriority(void)
void SetRTPriority()
{
#if !defined(ALSOFT_UWP)
if(RTPrioLevel > 0)
Expand Down
5 changes: 3 additions & 2 deletions core/hrtf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <mutex>
#include <numeric>
#include <optional>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -903,7 +904,7 @@ std::unique_ptr<HrtfStore> LoadHrtf02(std::istream &data, const char *filename)
elevs__end = std::copy_backward(elevs_src, elevs_src+field.evCount, elevs__end);
return ebase + field.evCount;
};
(void)std::accumulate(fields.cbegin(), fields.cend(), ptrdiff_t{0}, copy_azs);
std::ignore = std::accumulate(fields.cbegin(), fields.cend(), ptrdiff_t{0}, copy_azs);
assert(elevs_.begin() == elevs__end);

/* Reestablish the IR offset for each elevation index, given the new
Expand Down Expand Up @@ -938,7 +939,7 @@ std::unique_ptr<HrtfStore> LoadHrtf02(std::istream &data, const char *filename)

return ebase + field.evCount;
};
(void)std::accumulate(fields.cbegin(), fields.cend(), ptrdiff_t{0}, copy_irs);
std::ignore = std::accumulate(fields.cbegin(), fields.cend(), ptrdiff_t{0}, copy_irs);
assert(coeffs_.begin() == coeffs_end);
assert(delays_.begin() == delays_end);

Expand Down
19 changes: 12 additions & 7 deletions router/al.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@

#include "config.h"

#include <stddef.h>
#include <cstddef>

#include "AL/al.h"
#include "router.h"


#define DECL_THUNK1(R,n,T1) AL_API R AL_APIENTRY n(T1 a) noexcept \
#define DECL_THUNK1(R,n,T1) \
AL_API auto AL_APIENTRY n(T1 a) noexcept -> R \
{ \
DriverIface *iface = GetThreadDriver(); \
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
return iface->n(a); \
}
#define DECL_THUNK2(R,n,T1,T2) AL_API R AL_APIENTRY n(T1 a, T2 b) noexcept \
#define DECL_THUNK2(R,n,T1,T2) \
AL_API auto AL_APIENTRY n(T1 a, T2 b) noexcept -> R \
{ \
DriverIface *iface = GetThreadDriver(); \
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
return iface->n(a, b); \
}
#define DECL_THUNK3(R,n,T1,T2,T3) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c) noexcept \
#define DECL_THUNK3(R,n,T1,T2,T3) \
AL_API auto AL_APIENTRY n(T1 a, T2 b, T3 c) noexcept -> R \
{ \
DriverIface *iface = GetThreadDriver(); \
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
return iface->n(a, b, c); \
}
#define DECL_THUNK4(R,n,T1,T2,T3,T4) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d) noexcept \
#define DECL_THUNK4(R,n,T1,T2,T3,T4) \
AL_API auto AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d) noexcept -> R \
{ \
DriverIface *iface = GetThreadDriver(); \
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
return iface->n(a, b, c, d); \
}
#define DECL_THUNK5(R,n,T1,T2,T3,T4,T5) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d, T5 e) noexcept \
#define DECL_THUNK5(R,n,T1,T2,T3,T4,T5) \
AL_API auto AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d, T5 e) noexcept -> R \
{ \
DriverIface *iface = GetThreadDriver(); \
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
Expand All @@ -42,7 +47,7 @@
/* Ugly hack for some apps calling alGetError without a current context, and
* expecting it to be AL_NO_ERROR.
*/
AL_API ALenum AL_APIENTRY alGetError(void) noexcept
AL_API auto AL_APIENTRY alGetError() noexcept -> ALenum
{
DriverIface *iface = GetThreadDriver();
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire);
Expand Down
13 changes: 7 additions & 6 deletions router/alc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#include <string.h>
#include <stdio.h>

#include <mutex>
#include <algorithm>
#include <array>
#include <mutex>
#include <tuple>

#include "AL/alc.h"
#include "alstring.h"
Expand Down Expand Up @@ -413,12 +414,12 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *devicename) noexcep
{
std::lock_guard<std::recursive_mutex> _{EnumerationLock};
if(DevicesList.Names.empty())
(void)alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
std::ignore = alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
idx = GetDriverIndexForName(&DevicesList, devicename);
if(idx < 0)
{
if(AllDevicesList.Names.empty())
(void)alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER);
std::ignore = alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER);
idx = GetDriverIndexForName(&AllDevicesList, devicename);
}
}
Expand Down Expand Up @@ -578,7 +579,7 @@ ALC_API void ALC_APIENTRY alcDestroyContext(ALCcontext *context) noexcept
ContextIfaceMap.removeByKey(context);
}

ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(void) noexcept
ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext() noexcept
{
DriverIface *iface = GetThreadDriver();
if(!iface) iface = CurrentCtxDriver.load();
Expand Down Expand Up @@ -884,7 +885,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *devicename,
{
std::lock_guard<std::recursive_mutex> _{EnumerationLock};
if(CaptureDevicesList.Names.empty())
(void)alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER);
std::ignore = alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER);
idx = GetDriverIndexForName(&CaptureDevicesList, devicename);
}

Expand Down Expand Up @@ -1009,7 +1010,7 @@ ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context) noexcep
return ALC_FALSE;
}

ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void) noexcept
ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext() noexcept
{
DriverIface *iface = GetThreadDriver();
if(iface) return iface->alcGetThreadContext();
Expand Down
Loading

0 comments on commit bdd5401

Please sign in to comment.