From e95f729ad06bd8bb952b58b15e99df7f47e51fef Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 25 Nov 2023 01:09:37 +0100 Subject: [PATCH] Chain-Load: verify simple usage of LazyInit ...turns out I'd used the wrong Opaque buffer component; ...but other than that, the freaky mechanism seems to work --- src/lib/lazy-init.hpp | 2 +- tests/library/lazy-init-test.cpp | 24 ++++++++++++++++++++++++ wiki/thinkPad.ichthyo.mm | 24 ++++++++++++------------ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/lib/lazy-init.hpp b/src/lib/lazy-init.hpp index 9aa7badca..3fdbc5592 100644 --- a/src/lib/lazy-init.hpp +++ b/src/lib/lazy-init.hpp @@ -206,7 +206,7 @@ namespace lib { using DelegateType = std::function&(RawAddr)>; using PlaceholderType = DelegateType; - using HeapStorage = OpaqueHolder; + using HeapStorage = InPlaceBuffer; using PendingInit = std::shared_ptr; PendingInit pendingInit_; diff --git a/tests/library/lazy-init-test.cpp b/tests/library/lazy-init-test.cpp index 222635386..002bf2d8b 100644 --- a/tests/library/lazy-init-test.cpp +++ b/tests/library/lazy-init-test.cpp @@ -297,6 +297,30 @@ namespace test{ void verify_lazyInitialisation() { + using Fun = std::function; + using Lazy = LazyInit; + + bool init{false}; + uint invoked{0}; + Lazy funny{funny, [&](Lazy* self) + { + Fun& thisFun = static_cast (*self); + + thisFun = [&invoked](int num) + { + ++invoked; + return num * 0.555f; + }; + init = true; + }}; + CHECK (not invoked); + CHECK (not init); + CHECK (funny); + + int feed = 1 + rand()%99; + CHECK (feed*0.555f == funny(feed)); + CHECK (1 == invoked); + CHECK (init); } }; diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 9ce86568f..8e62e33f3 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -97133,13 +97133,12 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
In die eigentliche Auswertungsfunktion kann man eine »trojanische Funktion« installieren, die etwas völlig anderes macht, nämlich die Initialisierung. Danach überschreibt sie sich selbst mit der fertig gebundenen Funktion

- - + - + @@ -97273,7 +97272,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + @@ -97302,8 +97301,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + @@ -97313,8 +97312,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + @@ -97355,7 +97354,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + @@ -97375,7 +97374,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + + @@ -97418,14 +97418,14 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- +

- OpaqueHolder mißbraucht + InPlaceBuffer mißbraucht