From 8b19fdfd513de7024fb04c83868f1345a90c619d Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 2 Apr 2020 00:28:39 -0700 Subject: [PATCH] sf: fix OutArray/InArray constructors to behave as expected --- .../include/stratosphere/sf/sf_buffers.hpp | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/libraries/libstratosphere/include/stratosphere/sf/sf_buffers.hpp b/libraries/libstratosphere/include/stratosphere/sf/sf_buffers.hpp index 76f62a4ea..24d9dc526 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/sf_buffers.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/sf_buffers.hpp @@ -191,10 +191,7 @@ namespace ams::sf { public: constexpr InArrayImpl() : BaseType() { /* ... */ } constexpr InArrayImpl(const cmif::PointerAndSize &_pas) : BaseType(_pas) { /* ... */ } - constexpr InArrayImpl(uintptr_t ptr, size_t sz) : BaseType(ptr, sz) { /* ... */ } - - constexpr InArrayImpl(const void *ptr, size_t sz) : BaseType(reinterpret_cast(ptr), sz) { /* ... */ } - constexpr InArrayImpl(const T *ptr, size_t sz) : BaseType(reinterpret_cast(ptr), sz) { /* ... */ } + constexpr InArrayImpl(const T *ptr, size_t num_elements) : BaseType(reinterpret_cast(ptr), num_elements * sizeof(T)) { /* ... */ } constexpr const T *GetPointer() const { return reinterpret_cast(this->GetAddressImpl()); @@ -207,6 +204,14 @@ namespace ams::sf { constexpr const T &operator[](size_t i) const { return this->GetPointer()[i]; } + + constexpr explicit operator Span() const { + return {this->GetPointer(), static_cast(this->GetSize())}; + } + + constexpr Span ToSpan() const { + return {this->GetPointer(), static_cast(this->GetSize())}; + } }; template> @@ -218,10 +223,7 @@ namespace ams::sf { public: constexpr OutArrayImpl() : BaseType() { /* ... */ } constexpr OutArrayImpl(const cmif::PointerAndSize &_pas) : BaseType(_pas) { /* ... */ } - constexpr OutArrayImpl(uintptr_t ptr, size_t sz) : BaseType(ptr, sz) { /* ... */ } - - constexpr OutArrayImpl(void *ptr, size_t sz) : BaseType(reinterpret_cast(ptr), sz) { /* ... */ } - constexpr OutArrayImpl(T *ptr, size_t sz) : BaseType(reinterpret_cast(ptr), sz) { /* ... */ } + constexpr OutArrayImpl(T *ptr, size_t num_elements) : BaseType(reinterpret_cast(ptr), num_elements * sizeof(T)) { /* ... */ } constexpr T *GetPointer() const { return reinterpret_cast(this->GetAddressImpl()); @@ -234,6 +236,14 @@ namespace ams::sf { constexpr T &operator[](size_t i) const { return this->GetPointer()[i]; } + + constexpr explicit operator Span() const { + return {this->GetPointer(), static_cast(this->GetSize())}; + } + + constexpr Span ToSpan() const { + return {this->GetPointer(), static_cast(this->GetSize())}; + } }; }