mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2025-01-03 11:11:14 +00:00
kern: fix bug in up/downcasting of scoped auto objects
This commit is contained in:
parent
8d507aa5a1
commit
fae2daf77c
2 changed files with 12 additions and 15 deletions
|
@ -204,15 +204,20 @@ namespace ams::kern {
|
||||||
this->obj = nullptr;
|
this->obj = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U>
|
template<typename U> requires (std::derived_from<T, U> || std::derived_from<U, T>)
|
||||||
constexpr ALWAYS_INLINE KScopedAutoObject(KScopedAutoObject<U> &&rhs) {
|
constexpr ALWAYS_INLINE KScopedAutoObject(KScopedAutoObject<U> &&rhs) {
|
||||||
if constexpr (std::same_as<T, U>) {
|
if constexpr (std::derived_from<U, T>) {
|
||||||
|
/* Upcast. */
|
||||||
this->obj = rhs.obj;
|
this->obj = rhs.obj;
|
||||||
rhs.obj = nullptr;
|
rhs.obj = nullptr;
|
||||||
} else {
|
} else {
|
||||||
T *derived = rhs.obj->template DynamicCast<T *>();
|
/* Downcast. */
|
||||||
if (derived == nullptr) {
|
T *derived = nullptr;
|
||||||
rhs.obj->Close();
|
if (rhs.obj != nullptr) {
|
||||||
|
derived = rhs.obj->template DynamicCast<T *>();
|
||||||
|
if (derived == nullptr) {
|
||||||
|
rhs.obj->Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->obj = derived;
|
this->obj = derived;
|
||||||
|
@ -220,16 +225,7 @@ namespace ams::kern {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U>
|
constexpr ALWAYS_INLINE KScopedAutoObject<T> &operator=(KScopedAutoObject<T> &&rhs) {
|
||||||
constexpr ALWAYS_INLINE KScopedAutoObject &operator=(KScopedAutoObject<U> &&rhs) {
|
|
||||||
if constexpr (!std::same_as<T, U>) {
|
|
||||||
T *derived = rhs.obj->template DynamicCast<T *>();
|
|
||||||
if (derived == nullptr) {
|
|
||||||
rhs.obj->Close();
|
|
||||||
}
|
|
||||||
rhs.obj = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
rhs.Swap(*this);
|
rhs.Swap(*this);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,6 +252,7 @@ namespace ams::kern {
|
||||||
|
|
||||||
/* Switch the current process, if we're switching processes. */
|
/* Switch the current process, if we're switching processes. */
|
||||||
if (KProcess *next_process = next_thread->GetOwnerProcess(); next_process != cur_process) {
|
if (KProcess *next_process = next_thread->GetOwnerProcess(); next_process != cur_process) {
|
||||||
|
MESOSPHERE_LOG("!!! PROCESS SWITCH !!! %s -> %s\n", cur_process != nullptr ? cur_process->GetName() : nullptr, next_process != nullptr ? next_process->GetName() : nullptr);
|
||||||
KProcess::Switch(cur_process, next_process);
|
KProcess::Switch(cur_process, next_process);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue