From 4ce936529eb738e23b3e6d23bb851f78151a6fee Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 25 Apr 2025 19:02:04 +0200 Subject: [PATCH] Upgrade: fix test-failures(2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit seems that I've played too much with »undefined behaviour« in this test; basically we can not assume ''any'' specific placement of local variables in a stack frame.... In this test, what I wanted to demonstrate is that the overflow-block can reside just »anywhere«, and that HeteraoData is just a light-weight front-End and accessor. However, I can just demonstrate that without totally ''undefined behaviour;'' placement-new can be used to force the storage at a specific location (in the UninitialiesdStorage); continue to access and use that data after leaving the nested scope is still kind-of borderline, yet demonstrates that the data itself is just residing in a storage block... --- tests/library/hetero-data-test.cpp | 19 ++++++++++------- wiki/thinkPad.ichthyo.mm | 33 +++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/tests/library/hetero-data-test.cpp b/tests/library/hetero-data-test.cpp index fbd87afea..0197ad590 100644 --- a/tests/library/hetero-data-test.cpp +++ b/tests/library/hetero-data-test.cpp @@ -226,11 +226,11 @@ namespace test{ CHECK (get4(front) == "Ψ"); // further allocations can even be »elsewhere« - const void* loc; + lib::UninitialisedStorage evilSpace; + const void* loc = &evilSpace; { Acc6 get6; - auto magic = Cons3::build("magic","cloud"); - loc = getAdr(magic); + auto& magic = * new(&evilSpace) Cons3::NewFrame{"magic","cloud"}; CHECK (magic.get<0>() == "magic"_expect); CHECK (magic.get<1>() == "cloud"_expect); // link into the cloud... @@ -240,13 +240,18 @@ namespace test{ // it's gone // Evil, evil... - lib::UninitialisedStorage evilSpace; Data3& d3 = evilSpace[0]; // note: working with left-over data from expired stack frame CHECK (isSameAdr (d3, loc)); CHECK (d3.get<0>() == "magic"_expect); // const char* points into static data, so the chars are still there - new(&d3.get<1>()) string{"mushrooms"}; // the "cloud"-string was destroyed by magic's destructor + new(&d3.get<1>()) string{"mushrooms"}; // ...but we can implant another message here.... - auto& [v1,v2,v3,v4,v5,v6] = Cons3::recast(front); // using connectivity from the linked list connecting the segments + // All of this demonstrates that HeteroData is really + // just a light-weight front-end and access structure + // pointing to a data block that can be »anywhere« + // Since for this test we keep the evilSpace allocated, + // it is possible to continue accessing the data block, + // using connectivity from the linked list connecting the segments + auto& [v1,v2,v3,v4,v5,v6] = Cons3::recast(front); CHECK (v1 == "0"_expect); CHECK (v2 == "2.3"_expect); CHECK (v3 == "false"_expect); @@ -293,7 +298,7 @@ namespace test{ // Note: basically we are still using stale memory, // previously allocated to the "magic" block, - // and now covered by the UninitialisedStorage + // and still covered by the UninitialisedStorage CHECK (loc == & d3); CHECK (loc < & v5); CHECK (loc < & v6); diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index c55772d84..600d7c8c0 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -161877,8 +161877,39 @@ Since then others have made contributions, see the log for the history. - + + + + + + + +

+ Überraschung: wer sich in den Fuß schießt, schießt sich in den Fuß +

+ + +
+
+ + + + + + + + + + + +

+ ...ohne die implizite Annahme eines Layout, einfach indem ich den Overflow-Frame gleich per placement-New erzeuge; dann kann man trotzdem immer noch zeigen, daß die Daten weiterhin in der UninitialisedStorage liegen und dort verwendet werden können +

+ + +
+