diff options
author | Chris Robinson <[email protected]> | 2023-05-14 19:39:25 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-05-14 19:39:25 -0700 |
commit | 5d89ea32c2bb6d5a137cb345bec616b0d6708789 (patch) | |
tree | 6e914a89d45d2cacce34c265e03d9ab3b02024ef /al/direct_defs.h | |
parent | 5ab9ce58808a6c92bbb92c8f58d7694cb86e5414 (diff) |
Don't check for a null context in direct functions
Diffstat (limited to 'al/direct_defs.h')
-rw-r--r-- | al/direct_defs.h | 62 |
1 files changed, 49 insertions, 13 deletions
diff --git a/al/direct_defs.h b/al/direct_defs.h index c36211ae..4ab72730 100644 --- a/al/direct_defs.h +++ b/al/direct_defs.h @@ -1,83 +1,119 @@ #ifndef AL_DIRECT_DEFS_H #define AL_DIRECT_DEFS_H +namespace detail_ { + +template<typename T> +constexpr T DefaultVal() noexcept { return T{}; } + +template<> +constexpr void DefaultVal() noexcept { } + +} // namespace detail_ + #define DECL_FUNC(R, Name) \ R AL_API Name(void) START_API_FUNC \ { \ - return Name##Direct(GetContextRef().get()); \ + auto context = GetContextRef(); \ + if(!context) UNLIKELY return detail_::DefaultVal<R>(); \ + return Name##Direct(context.get()); \ } END_API_FUNC #define DECL_FUNC1(R, Name, T1) \ R AL_API Name(T1 a) START_API_FUNC \ { \ - return Name##Direct(GetContextRef().get(), a); \ + auto context = GetContextRef(); \ + if(!context) UNLIKELY return detail_::DefaultVal<R>(); \ + return Name##Direct(context.get(), a); \ } END_API_FUNC #define DECL_FUNC2(R, Name, T1, T2) \ R AL_API Name(T1 a, T2 b) START_API_FUNC \ { \ - return Name##Direct(GetContextRef().get(), a, b); \ + auto context = GetContextRef(); \ + if(!context) UNLIKELY return detail_::DefaultVal<R>(); \ + return Name##Direct(context.get(), a, b); \ } END_API_FUNC #define DECL_FUNC3(R, Name, T1, T2, T3) \ R AL_API Name(T1 a, T2 b, T3 c) START_API_FUNC \ { \ - return Name##Direct(GetContextRef().get(), a, b, c); \ + auto context = GetContextRef(); \ + if(!context) UNLIKELY return detail_::DefaultVal<R>(); \ + return Name##Direct(context.get(), a, b, c); \ } END_API_FUNC #define DECL_FUNC4(R, Name, T1, T2, T3, T4) \ R AL_API Name(T1 a, T2 b, T3 c, T4 d) START_API_FUNC \ { \ - return Name##Direct(GetContextRef().get(), a, b, c, d); \ + auto context = GetContextRef(); \ + if(!context) UNLIKELY return detail_::DefaultVal<R>(); \ + return Name##Direct(context.get(), a, b, c, d); \ } END_API_FUNC #define DECL_FUNC5(R, Name, T1, T2, T3, T4, T5) \ R AL_API Name(T1 a, T2 b, T3 c, T4 d, T5 e) START_API_FUNC \ { \ - return Name##Direct(GetContextRef().get(), a, b, c, d, e); \ + auto context = GetContextRef(); \ + if(!context) UNLIKELY return detail_::DefaultVal<R>(); \ + return Name##Direct(context.get(), a, b, c, d, e); \ } END_API_FUNC #define DECL_FUNCEXT(R, Name,Ext) \ R AL_API Name##Ext(void) START_API_FUNC \ { \ - return Name##Direct##Ext(GetContextRef().get()); \ + auto context = GetContextRef(); \ + if(!context) UNLIKELY return detail_::DefaultVal<R>(); \ + return Name##Direct##Ext(context.get()); \ } END_API_FUNC #define DECL_FUNCEXT1(R, Name,Ext, T1) \ R AL_API Name##Ext(T1 a) START_API_FUNC \ { \ - return Name##Direct##Ext(GetContextRef().get(), a); \ + auto context = GetContextRef(); \ + if(!context) UNLIKELY return detail_::DefaultVal<R>(); \ + return Name##Direct##Ext(context.get(), a); \ } END_API_FUNC #define DECL_FUNCEXT2(R, Name,Ext, T1, T2) \ R AL_API Name##Ext(T1 a, T2 b) START_API_FUNC \ { \ - return Name##Direct##Ext(GetContextRef().get(), a, b); \ + auto context = GetContextRef(); \ + if(!context) UNLIKELY return detail_::DefaultVal<R>(); \ + return Name##Direct##Ext(context.get(), a, b); \ } END_API_FUNC #define DECL_FUNCEXT3(R, Name,Ext, T1, T2, T3) \ R AL_API Name##Ext(T1 a, T2 b, T3 c) START_API_FUNC \ { \ - return Name##Direct##Ext(GetContextRef().get(), a, b, c); \ + auto context = GetContextRef(); \ + if(!context) UNLIKELY return detail_::DefaultVal<R>(); \ + return Name##Direct##Ext(context.get(), a, b, c); \ } END_API_FUNC #define DECL_FUNCEXT4(R, Name,Ext, T1, T2, T3, T4) \ R AL_API Name##Ext(T1 a, T2 b, T3 c, T4 d) START_API_FUNC \ { \ - return Name##Direct##Ext(GetContextRef().get(), a, b, c, d); \ + auto context = GetContextRef(); \ + if(!context) UNLIKELY return detail_::DefaultVal<R>(); \ + return Name##Direct##Ext(context.get(), a, b, c, d); \ } END_API_FUNC #define DECL_FUNCEXT5(R, Name,Ext, T1, T2, T3, T4, T5) \ R AL_API Name##Ext(T1 a, T2 b, T3 c, T4 d, T5 e) START_API_FUNC \ { \ - return Name##Direct##Ext(GetContextRef().get(), a, b, c, d, e); \ + auto context = GetContextRef(); \ + if(!context) UNLIKELY return detail_::DefaultVal<R>(); \ + return Name##Direct##Ext(context.get(), a, b, c, d, e); \ } END_API_FUNC #define DECL_FUNCEXT6(R, Name,Ext, T1, T2, T3, T4, T5, T6) \ R AL_API Name##Ext(T1 a, T2 b, T3 c, T4 d, T5 e, T6 f) START_API_FUNC \ { \ - return Name##Direct##Ext(GetContextRef().get(), a, b, c, d, e, f); \ + auto context = GetContextRef(); \ + if(!context) UNLIKELY return detail_::DefaultVal<R>(); \ + return Name##Direct##Ext(context.get(), a, b, c, d, e, f); \ } END_API_FUNC #endif /* AL_DIRECT_DEFS_H */ |