From 9b483625e653d2ea89533c99b501a2e296c4d366 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 22 Dec 2022 20:40:33 -0500 Subject: LibIPC+Everywhere: Change IPC decoders to construct values in-place Currently, the generated IPC decoders will default-construct the type to be decoded, then pass that value by reference to the concrete decoder. This, of course, requires that the type is default-constructible. This was an issue for decoding Variants, which had to require the first type in the Variant list is Empty, to ensure it is default constructible. Further, this made it possible for values to become uninitialized in user-defined decoders. This patch makes the decoder interface such that the concrete decoders themselves contruct the decoded type upon return from the decoder. To do so, the default decoders in IPC::Decoder had to be moved to the IPC namespace scope, as these decoders are now specializations instead of overloaded methods (C++ requires specializations to be in a namespace scope). --- Userland/Libraries/LibGfx/Size.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'Userland/Libraries/LibGfx/Size.cpp') diff --git a/Userland/Libraries/LibGfx/Size.cpp b/Userland/Libraries/LibGfx/Size.cpp index 718312d052..b737e7af15 100644 --- a/Userland/Libraries/LibGfx/Size.cpp +++ b/Userland/Libraries/LibGfx/Size.cpp @@ -35,14 +35,11 @@ bool encode(Encoder& encoder, Gfx::IntSize const& size) } template<> -ErrorOr decode(Decoder& decoder, Gfx::IntSize& size) +ErrorOr decode(Decoder& decoder) { - int width = 0; - int height = 0; - TRY(decoder.decode(width)); - TRY(decoder.decode(height)); - size = { width, height }; - return {}; + auto width = TRY(decoder.decode()); + auto height = TRY(decoder.decode()); + return Gfx::IntSize { width, height }; } } -- cgit v1.2.3