diff options
-rw-r--r-- | al/debug.cpp | 68 | ||||
-rw-r--r-- | al/error.cpp | 3 | ||||
-rw-r--r-- | al/event.cpp | 7 | ||||
-rw-r--r-- | al/state.cpp | 4 | ||||
-rw-r--r-- | alc/alc.cpp | 4 | ||||
-rw-r--r-- | alc/context.h | 6 |
6 files changed, 46 insertions, 46 deletions
diff --git a/al/debug.cpp b/al/debug.cpp index 5a3f4873..efc7fc09 100644 --- a/al/debug.cpp +++ b/al/debug.cpp @@ -168,28 +168,15 @@ const char *GetDebugSeverityName(DebugSeverity severity) void ALCcontext::sendDebugMessage(std::unique_lock<std::mutex> &debuglock, DebugSource source, - DebugType type, ALuint id, DebugSeverity severity, ALsizei length, const char *message) + DebugType type, ALuint id, DebugSeverity severity, std::string_view message) { if(!mDebugEnabled.load()) UNLIKELY return; - /* MaxDebugMessageLength is the size including the null terminator, - * <length> does not include the null terminator. - */ - if(length < 0) + if(message.length() >= MaxDebugMessageLength) UNLIKELY { - size_t newlen{std::strlen(message)}; - if(newlen >= MaxDebugMessageLength) UNLIKELY - { - ERR("Debug message too long (%zu >= %d):\n-> %s\n", newlen, MaxDebugMessageLength, - message); - return; - } - length = static_cast<ALsizei>(newlen); - } - else if(length >= MaxDebugMessageLength) UNLIKELY - { - ERR("Debug message too long (%d >= %d):\n-> %s\n", length, MaxDebugMessageLength, message); + ERR("Debug message too long (%zu >= %d):\n-> %s\n", message.length(), + MaxDebugMessageLength, message.data()); return; } @@ -215,7 +202,8 @@ void ALCcontext::sendDebugMessage(std::unique_lock<std::mutex> &debuglock, Debug auto param = mDebugParam; debuglock.unlock(); callback(GetDebugSourceEnum(source), GetDebugTypeEnum(type), id, - GetDebugSeverityEnum(severity), length, message, param); + GetDebugSeverityEnum(severity), static_cast<ALsizei>(message.length()), message.data(), + param); } else { @@ -229,7 +217,7 @@ void ALCcontext::sendDebugMessage(std::unique_lock<std::mutex> &debuglock, Debug " Severity: %s\n" " Message: \"%s\"\n", GetDebugSourceName(source), GetDebugTypeName(type), id, - GetDebugSeverityName(severity), message); + GetDebugSeverityName(severity), message.data()); } } @@ -251,20 +239,32 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageInsertDirectEXT(ALCcontext *context, if(!context->mContextFlags.test(ContextFlags::DebugBit)) return; - if(!message) + if(!message) UNLIKELY return context->setError(AL_INVALID_VALUE, "Null message pointer"); + if(length >= MaxDebugMessageLength) UNLIKELY + return context->setError(AL_INVALID_VALUE, "Debug message too long (%d >= %d)", length, + MaxDebugMessageLength); + + std::string tmpmessage; + std::string_view msgview; if(length < 0) + msgview = message; + /* Testing if the message is null terminated like this is kind of ugly, but + * it's the only way to avoid an otherwise unnecessary copy since the + * callback and trace calls need a null-terminated message string. + */ + else if(message[length] == '\0') + msgview = {message, static_cast<uint>(length)}; + else { - size_t newlen{std::strlen(message)}; - if(newlen >= MaxDebugMessageLength) UNLIKELY - return context->setError(AL_INVALID_VALUE, "Debug message too long (%zu >= %d)", - newlen, MaxDebugMessageLength); - length = static_cast<ALsizei>(newlen); + tmpmessage.assign(message, static_cast<uint>(length)); + msgview = tmpmessage; } - else if(length >= MaxDebugMessageLength) UNLIKELY - return context->setError(AL_INVALID_VALUE, "Debug message too long (%d > %d)", length, - MaxDebugMessageLength); + + if(msgview.length() >= MaxDebugMessageLength) UNLIKELY + return context->setError(AL_INVALID_VALUE, "Debug message too long (%zu >= %d)", + msgview.length(), MaxDebugMessageLength); auto dsource = GetDebugSource(source); if(!dsource) @@ -280,7 +280,7 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageInsertDirectEXT(ALCcontext *context, if(!dseverity) return context->setError(AL_INVALID_ENUM, "Invalid debug severity 0x%04x", severity); - context->debugMessage(*dsource, *dtype, id, *dseverity, length, message); + context->debugMessage(*dsource, *dtype, id, *dseverity, msgview); } @@ -393,7 +393,7 @@ FORCE_ALIGN void AL_APIENTRY alPushDebugGroupDirectEXT(ALCcontext *context, ALen length = static_cast<ALsizei>(newlen); } else if(length >= MaxDebugMessageLength) UNLIKELY - return context->setError(AL_INVALID_VALUE, "Debug message too long (%d > %d)", length, + return context->setError(AL_INVALID_VALUE, "Debug message too long (%d >= %d)", length, MaxDebugMessageLength); auto dsource = GetDebugSource(source); @@ -409,7 +409,8 @@ FORCE_ALIGN void AL_APIENTRY alPushDebugGroupDirectEXT(ALCcontext *context, ALen return context->setError(AL_STACK_OVERFLOW_EXT, "Pushing too many debug groups"); } - context->mDebugGroups.emplace_back(*dsource, id, message); + context->mDebugGroups.emplace_back(*dsource, id, + std::string_view{message, static_cast<uint>(length)}); auto &oldback = *(context->mDebugGroups.end()-2); auto &newback = context->mDebugGroups.back(); @@ -418,8 +419,7 @@ FORCE_ALIGN void AL_APIENTRY alPushDebugGroupDirectEXT(ALCcontext *context, ALen if(context->mContextFlags.test(ContextFlags::DebugBit)) context->sendDebugMessage(debuglock, newback.mSource, DebugType::PushGroup, newback.mId, - DebugSeverity::Notification, static_cast<ALsizei>(newback.mMessage.size()), - newback.mMessage.data()); + DebugSeverity::Notification, newback.mMessage); } FORCE_ALIGN DECL_FUNCEXT(void, alPopDebugGroup,EXT) @@ -441,7 +441,7 @@ FORCE_ALIGN void AL_APIENTRY alPopDebugGroupDirectEXT(ALCcontext *context) noexc context->mDebugGroups.pop_back(); if(context->mContextFlags.test(ContextFlags::DebugBit)) context->sendDebugMessage(debuglock, source, DebugType::PopGroup, id, - DebugSeverity::Notification, static_cast<ALsizei>(message.size()), message.data()); + DebugSeverity::Notification, message); } diff --git a/al/error.cpp b/al/error.cpp index 3a1a9ac3..9db13947 100644 --- a/al/error.cpp +++ b/al/error.cpp @@ -87,7 +87,8 @@ void ALCcontext::setError(ALenum errorCode, const char *msg, ...) ALenum curerr{AL_NO_ERROR}; mLastError.compare_exchange_strong(curerr, errorCode); - debugMessage(DebugSource::API, DebugType::Error, 0, DebugSeverity::High, msglen, msg); + debugMessage(DebugSource::API, DebugType::Error, 0, DebugSeverity::High, + {msg, static_cast<uint>(msglen)}); } /* Special-case alGetError since it (potentially) raises a debug signal and diff --git a/al/event.cpp b/al/event.cpp index f606f765..7bd5ae1b 100644 --- a/al/event.cpp +++ b/al/event.cpp @@ -121,7 +121,7 @@ int EventThread(ALCcontext *context) const std::string_view message{evt.msg}; context->debugMessage(DebugSource::System, DebugType::Error, 0, - DebugSeverity::High, static_cast<ALsizei>(message.length()), message.data()); + DebugSeverity::High, message); if(context->mEventCb && enabledevts.test(al::to_underlying(AsyncEnableBits::Disconnected))) @@ -130,9 +130,8 @@ int EventThread(ALCcontext *context) context->mEventParam); }; - std::visit(overloaded - {proc_srcstate, proc_buffercomp, proc_release, proc_disconnect, proc_killthread}, - event); + std::visit(overloaded{proc_srcstate, proc_buffercomp, proc_release, proc_disconnect, + proc_killthread}, event); } while(evt_data.len != 0); } return 0; diff --git a/al/state.cpp b/al/state.cpp index 2b6c1bb2..e831ccc1 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -188,7 +188,7 @@ void GetValue(ALCcontext *context, ALenum pname, T *values) case AL_DOPPLER_VELOCITY: if(context->mContextFlags.test(ContextFlags::DebugBit)) UNLIKELY context->debugMessage(DebugSource::API, DebugType::DeprecatedBehavior, 0, - DebugSeverity::Medium, -1, + DebugSeverity::Medium, "AL_DOPPLER_VELOCITY is deprecated in AL 1.1, use AL_SPEED_OF_SOUND; " "AL_DOPPLER_VELOCITY -> AL_SPEED_OF_SOUND / 343.3f"); *values = cast_value(context->mDopplerVelocity); @@ -619,7 +619,7 @@ AL_API void AL_APIENTRY alDopplerVelocity(ALfloat value) noexcept if(context->mContextFlags.test(ContextFlags::DebugBit)) UNLIKELY context->debugMessage(DebugSource::API, DebugType::DeprecatedBehavior, 0, - DebugSeverity::Medium, -1, + DebugSeverity::Medium, "alDopplerVelocity is deprecated in AL 1.1, use alSpeedOfSound; " "alDopplerVelocity(x) -> alSpeedOfSound(343.3f * x)"); diff --git a/alc/alc.cpp b/alc/alc.cpp index 3cad507e..88aa73c5 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2777,7 +2777,7 @@ ALC_API void ALC_APIENTRY alcSuspendContext(ALCcontext *context) noexcept } if(context->mContextFlags.test(ContextFlags::DebugBit)) UNLIKELY - ctx->debugMessage(DebugSource::API, DebugType::Portability, 0, DebugSeverity::Medium, -1, + ctx->debugMessage(DebugSource::API, DebugType::Portability, 0, DebugSeverity::Medium, "alcSuspendContext behavior is not portable -- some implementations suspend all " "rendering, some only defer property changes, and some are completely no-op; consider " "using alcDevicePauseSOFT to suspend all rendering, or alDeferUpdatesSOFT to only " @@ -2800,7 +2800,7 @@ ALC_API void ALC_APIENTRY alcProcessContext(ALCcontext *context) noexcept } if(context->mContextFlags.test(ContextFlags::DebugBit)) UNLIKELY - ctx->debugMessage(DebugSource::API, DebugType::Portability, 0, DebugSeverity::Medium, -1, + ctx->debugMessage(DebugSource::API, DebugType::Portability, 0, DebugSeverity::Medium, "alcProcessContext behavior is not portable -- some implementations resume rendering, " "some apply deferred property changes, and some are completely no-op; consider using " "alcDeviceResumeSOFT to resume rendering, or alProcessUpdatesSOFT to apply deferred " diff --git a/alc/context.h b/alc/context.h index 779be113..0611775a 100644 --- a/alc/context.h +++ b/alc/context.h @@ -191,15 +191,15 @@ struct ALCcontext : public al::intrusive_ref<ALCcontext>, ContextBase { void setError(ALenum errorCode, const char *msg, ...); void sendDebugMessage(std::unique_lock<std::mutex> &debuglock, DebugSource source, - DebugType type, ALuint id, DebugSeverity severity, ALsizei length, const char *message); + DebugType type, ALuint id, DebugSeverity severity, std::string_view message); void debugMessage(DebugSource source, DebugType type, ALuint id, DebugSeverity severity, - ALsizei length, const char *message) + std::string_view message) { if(!mDebugEnabled.load(std::memory_order_relaxed)) LIKELY return; std::unique_lock<std::mutex> debuglock{mDebugCbLock}; - sendDebugMessage(debuglock, source, type, id, severity, length, message); + sendDebugMessage(debuglock, source, type, id, severity, message); } /* Process-wide current context */ |