Lab 2: Packed Meta-String Table, void ** Metacall Router & Re-Entrant Disconnect
Master Qt 6 module boundaries, d_ptr/q_ptr binary compatibility, UTF-16LE QString and QByteArray atomic Copy-on-Write detach rules, uic setupUi() C++ generation, and moc QMetaObject string tables plus qt_static_metacall void** dispatch.
Prerequisites in this module
What ./check.sh verifies
- Builds libcore.a and lab_cli cleanly with -std=c++20 -Wall -Wextra -Werror -pedantic.
- Fix compiler warnings or errors in files/core.cpp.
- Archives core.o into libcore.a and links independent TAP verifier.
- Preserve public declarations in files/core.hpp so tests.cpp links.
step 1/15 · inspect starter files and specification
Debugging subtle Qt 6 signal bugs—nested QSignalBlocker scopes prematurely unblocking an editor, custom qt_metacall bridges miscalculating base method offsets, or one-shot slots disconnecting themselves mid-emission—requires mechanical mastery of moc dispatch. In this studio you repair a zero-allocation PackedStringTable and MetaEndpoint void ** router.
learner@ksa:~/gl-q01/lab-m02ls -lastarter/Makefilestarter/cli.cppstarter/core.cppstarter/core.hpplearner@ksa:~/gl-q01/lab-m02starter: starter/Makefile
learner@ksa:~/gl-q01/lab-m02$ bat starter/Makefile File: starter/Makefile CC_BIN = g++ AR = ar CFLAGS_ALL = -std=c++20 -Wall -Wextra -Werror -pedantic -O2 LDLIBS = all: libcore.a lab_cli libcore.a: core.o $(AR) rcs $@ $^ lab_cli: cli.o libcore.a $(CC_BIN) $(CFLAGS_ALL) cli.o libcore.a $(LDLIBS) -o $@ %.o: %.cpp core.hpp $(CC_BIN) $(CFLAGS_ALL) -c $< -o $@ .PHONY: all clean clean: rm -f core.o cli.o libcore.a lab_clistarter: starter/cli.cpp
learner@ksa:~/gl-q01/lab-m02$ bat starter/cli.cpp File: starter/cli.cpp #include "core.hpp" #include <algorithm> #include <array> #include <cstdint> #include <cstdio> #include <cstring> #include <ctime> #include <vector> namespace { static constexpr char kBlob[] = "GaugeNode\0pressureChanged\0applyReading\0"; static constexpr hmi::MetaSlice kSlices[] = {{0, 9}, {10, 15}, {26, 12}}; struct GaugeNode final : public hmi::MetaEndpoint { GaugeNode() : hmi::MetaEndpoint(&GaugeNode::dispatch, 5, 3) {} std::int64_t acc = 0; void emit_pressure(int kpa, int status) { void *a[] = {nullptr, &kpa, &status}; activate(0, a); } static void dispatch(hmi::MetaEndpoint *base, int local_id, void **a) { auto *self = static_cast<GaugeNode *>(base); if (local_id == 1) { const int kpa = *static_cast<const int *>(a[1]); const int st = *static_cast<const int *>(a[2]); self->acc += kpa * 10 + st; } else if (local_id == 2 && a[0]) { *static_cast<int *>(a[0]) = *static_cast<const int *>(a[1]) * 4; } } }; static std::uint64_t now_ns() noexcept { timespec ts{}; clock_gettime(CLOCK_MONOTONIC, &ts); return static_cast<std::uint64_t>(ts.tv_sec) * 1000000000ULL + static_cast<std::uint64_t>(ts.tv_nsec); } static int run_bench() { hmi::PackedStringTable tbl(kBlob, kSlices, 3); GaugeNode tx; GaugeNode rx1, rx2; tx.connect_to(5, &rx1, 6); tx.connect_to(5, &rx2, 6); constexpr int kWarmup = 5; constexpr int kSamples = 40; constexpr int kInner = 500; std::array<std::uint64_t, kSamples> ns{}; volatile std::int64_t sink = 0; for (int w = 0; w < kWarmup + kSamples; ++w) { const std::uint64_t t0 = now_ns(); for (int i = 0; i < kInner; ++i) { tx.emit_pressure(i, 1); sink += tbl.find_index("applyReading"); } const std::uint64_t dt = (now_ns() - t0) / static_cast<std::uint64_t>(kInner); if (w >= kWarmup) { ns[static_cast<std::size_t>(w - kWarmup)] = dt; } } sink += rx1.acc + rx2.acc; std::sort(ns.begin(), ns.end()); std::printf("BENCH lab_m02_moc_signal_dispatch clock=CLOCK_MONOTONIC " "benchmark_samples=40 warmup=5 p50_ns=%llu p95_ns=%llu p99_ns=%llu sink=%lld\n", static_cast<unsigned long long>(ns[20]), static_cast<unsigned long long>(ns[38]), static_cast<unsigned long long>(ns[39]), static_cast<long long>(sink)); return 0; } } // namespace int main(int argc, char **argv) { if (argc > 1 && std::strcmp(argv[1], "--bench") == 0) { return run_bench(); } hmi::PackedStringTable tbl(kBlob, kSlices, 3); GaugeNode tx, rx; tx.connect_to(5, &rx, 6); tx.emit_pressure(42, 7); int ret = 0, in_val = 15; void *args[] = {&ret, &in_val}; rx.qt_metacall(7, args); std::printf("str_idx=%d rx_acc=%lld scaled_ret=%d\n", tbl.find_index("pressureChanged"), static_cast<long long>(rx.acc), ret); return (tbl.find_index("pressureChanged") == 1 && rx.acc == 427 && ret == 60) ? 0 : 1; }starter: starter/core.cpp
learner@ksa:~/gl-q01/lab-m02$ bat starter/core.cpp File: starter/core.cpp #include "core.hpp" #include <algorithm> namespace hmi { std::string_view PackedStringTable::get(std::size_t idx) const noexcept { if (!m_blob || !m_slices || idx >= m_count) { return {}; } return std::string_view(m_blob + m_slices[idx].offset, m_slices[idx].len); } int PackedStringTable::find_index(std::string_view name) const noexcept { for (std::size_t i = 0; i < m_count; ++i) { if (get(i) == name) { return static_cast<int>(i); } } return -1; } int MetaEndpoint::connect_to(int global_signal_id, MetaEndpoint *receiver, int global_slot_id) { if (!receiver || global_signal_id < 0 || global_slot_id < 0) { return 0; } const int cid = m_next_id++; m_links.push_back({cid, global_signal_id, receiver, global_slot_id, true}); return cid; } bool MetaEndpoint::disconnect_id(int conn_id) noexcept { for (auto &lnk : m_links) { if (lnk.id == conn_id && lnk.active) { lnk.active = false; return true; } } return false; } bool MetaEndpoint::block_signals(bool block) noexcept { m_blocked = block; return m_blocked; /* BUG: returns new state instead of prior state */ } int MetaEndpoint::qt_metacall(int global_id, void **args) { if (global_id < 0) { return global_id; } if (global_id < m_offset) { return -1; } const int local_id = global_id; /* BUG: forgets to subtract base m_offset */ if (local_id < m_count) { if (m_fn) { m_fn(this, local_id, args); } return -1; } return local_id - m_count; } void MetaEndpoint::activate(int local_signal_id, void **args) { if (m_blocked) { return; } const int global_sig = local_signal_id; /* BUG: omits m_offset when matching global_signal_id */ std::vector<int> snapshot; snapshot.reserve(m_links.size()); for (const auto &lnk : m_links) { if (lnk.active && lnk.global_signal_id == global_sig) { snapshot.push_back(lnk.id); } } for (int cid : snapshot) { for (const auto &lnk : m_links) { if (lnk.id == cid && lnk.active && lnk.receiver) { lnk.receiver->qt_metacall(lnk.global_slot_id, args); break; } } } m_links.erase( std::remove_if(m_links.begin(), m_links.end(), [] (const Link &l) { return !l.active; }), m_links.end()); } } // namespace hmistarter: starter/core.hpp
learner@ksa:~/gl-q01/lab-m02$ bat starter/core.hpp File: starter/core.hpp #pragma once #include <cstddef> #include <cstdint> #include <string_view> #include <vector> namespace hmi { struct MetaSlice { std::uint32_t offset; std::uint32_t len; }; class PackedStringTable { public: PackedStringTable(const char *blob, const MetaSlice *slices, std::size_t count) noexcept : m_blob(blob), m_slices(slices), m_count(count) {} std::string_view get(std::size_t idx) const noexcept; int find_index(std::string_view name) const noexcept; std::size_t count() const noexcept { return m_count; } private: const char *m_blob; const MetaSlice *m_slices; std::size_t m_count; }; class MetaEndpoint; using MetacallFn = void (*)(MetaEndpoint *self, int local_id, void **args); class MetaEndpoint { public: MetaEndpoint(MetacallFn fn, int base_method_offset, int local_method_count) noexcept : m_fn(fn), m_offset(base_method_offset), m_count(local_method_count) {} virtual ~MetaEndpoint() = default; int connect_to(int global_signal_id, MetaEndpoint *receiver, int global_slot_id); bool disconnect_id(int conn_id) noexcept; bool signals_blocked() const noexcept { return m_blocked; } bool block_signals(bool block) noexcept; int qt_metacall(int global_id, void **args); void activate(int local_signal_id, void **args); private: struct Link { int id; int global_signal_id; MetaEndpoint *receiver; int global_slot_id; bool active; }; MetacallFn m_fn; int m_offset; int m_count; bool m_blocked = false; int m_next_id = 1; std::vector<Link> m_links; }; } // namespace hmistep 2/15 · 2. learning objectives
- Resolve packed
.rodatastring slices and subtractm_offsetaccurately inMetaEndpoint::qt_metacallandactivate. - Return the prior boolean state from
MetaEndpoint::block_signals(bool)so nested RAII signal blockers restore state without leaks. - Preserve iteration safety when a connected slot calls
disconnect_id()on its own connection duringactivate().
step 3/15 · 3. environment requirements
All automated verification steps run in unprivileged user space on a POSIX Linux host using g++ -std=c++20 -Wall -Wextra -Werror -pedantic and clock_gettime(CLOCK_MONOTONIC). Recorded transcripts in captures.json were generated on x86_64 running kernel 7.0.0-42-generic and prove protocol, state-machine, and memory invariants only. Physical bus timing, DMA cache coherency, and board peripheral behavior require target validation on Linux kernel 6.12 LTS (ARMv7-A Cortex-A7).
step 4/15 · 4. required software and hardware
- Host workstation:
g++(-std=c++20 -Wall -Wextra -Werror -pedantic), GNUmake,ar(binutils), and POSIX/bin/sh. - Target environment (optional hardware step, Section 13):
ARMv7-ACortex-A7target runningLinux kernel6.12 LTS and Qt 6.8 to inspect.rodataqt_meta_stringdatasymbols viaarm-linux-gnueabihf-objdump -s -j .rodataand traceqt_static_metacallingdbserver.
step 5/15 · 5. complete executable commands
learner@ksa:~/gl-q01/lab-m02$ bat script.sh File: script.sh make -B -C files ./files/lab_cli ./files/lab_cli --bench sh check.shstep 6/15 · 6. annotated source code
files/core.cpp enforces the production invariants that starter/core.cpp breaks:
learner@ksa:~/gl-q01/lab-m02$ bat example.cpp File: example.cpp bool MetaEndpoint::block_signals(bool block) noexcept { const bool previous = m_blocked; m_blocked = block; return previous; // Essential for nested QSignalBlocker scopes! } int MetaEndpoint::qt_metacall(int global_id, void **args) { ... const int local_id = global_id - m_offset; if (local_id < m_count) { if (m_fn) m_fn(this, local_id, args); return -1; } return local_id - m_count; }starter/core.cpp contains three meta-object bugs: (1) qt_metacall() forgets to subtract m_offset from global_id; (2) block_signals(bool) returns the newly assigned m_blocked flag instead of the previous state, breaking nested blocker restoration; and (3) activate() omits m_offset when computing global_sig.
step 7/15 · 7. expected output
Passing files/ run (sh check.sh, exit code 0):
learner@ksa:~/gl-q01/lab-m02$ bat listing.txt File: listing.txt TAP version 13 1..5 ok 1 - builds libcore.a and lab_cli cleanly with -std=c++20 -Wall -Wextra -Werror -pedantic ok 2 - archives core.o into libcore.a and links independent TAP verifier ok 3 - slices PackedStringTable without heap copies and subtracts m_offset in qt_metacall ok 4 - returns previous blocked state from block_signals(bool) and suppresses emissions ok 5 - delivers multi-slot void** packs safely across re-entrant mid-dispatch self-disconnect # pass 5/5CLI verification output (./files/lab_cli):
learner@ksa:~/gl-q01/lab-m02$ bat listing.txt File: listing.txt str_idx=1 rx_acc=427 scaled_ret=60Defective starter/ run (exit code 1): emits FAIL: diagnostics on the broken contract assertions.
step 8/15 · 8. explanation of observed behavior
Restoring base-offset arithmetic and prior-state preservation in files/core.cpp allows sh check.sh to compile libcore.a cleanly under -std=c++20 -Wall -Wextra -Werror -pedantic and pass all 5/5 TAP version 13 verification checks.
step 9/15 · 9. experiment variations
- Near transfer: Write a 12-line RAII
SignalBlockerclass wrappingMetaEndpoint &that callsm_prev = ep.block_signals(true)in its constructor andep.block_signals(m_prev)in its destructor, proving nested scopes work automatically. - Far transfer: Extend
MetaEndpoint::connect_towith abool unique_connectionflag modelingQt::UniqueConnectionthat rejects duplicate(global_signal_id, receiver, global_slot_id)tuples.
step 10/15 · 10. performance measurements
Recorded host benchmark (./files/lab_cli --bench, CLOCK_MONOTONIC, warmup=5, N=40 batches):
learner@ksa:~/gl-q01/lab-m02$ bat listing.txt File: listing.txt BENCH lab_m02_moc_signal_dispatch clock=CLOCK_MONOTONIC benchmark_samples=40 warmup=5 p50_ns=55 p95_ns=56 p99_ns=68 sink=112365000The CLOCK_MONOTONIC --bench percentiles measure two synchronous void ** metacall dispatches plus one packed string lookup per iteration in host RAM (p50 tens of nanoseconds). Never extrapolate host DirectConnection speed to cross-thread QueuedConnection heap marshaling or target ARMv7-A eventfd kernel wakeups.
step 11/15 · 11. troubleshooting
| Symptom | Root cause | Fix |
|---|---|---|
not ok 3 - slices PackedStringTable... | qt_metacall or activate omitted m_offset conversion between global and local IDs. | Compute local_id = global_id - m_offset in qt_metacall and global_sig = m_offset + local_signal_id in activate. |
not ok 4 - returns previous blocked state... | block_signals(true) returned true on the first call instead of the prior false value. | Capture const bool previous = m_blocked; before overwriting m_blocked = block; and return previous;. |
not ok 5 - delivers multi-slot void** packs... | activate() failed to match global_sig or invalidated m_links while iterating. | Add m_offset + local_signal_id and iterate over the snapshot ID vector before erasing inactive links. |
step 12/15 · 12. guided questions
- Why does
MetaEndpoint::activate()snapshot matching connection IDs before invokinglnk.receiver->qt_metacall(...)instead of ranging directly overm_links?
- *Hint 1:* What happens to
std::vector<Link>::iteratorif a slot invoked insideqt_metacallcallssender->connect_to(...)and triggers a vector reallocation? - *Hint 2:* Calling
connect_toinside an active slot can reallocatem_links's backing buffer, immediately invalidating raw iterators or references intom_links!
- Why does Qt's
QObject::blockSignals(bool)return the PREVIOUS boolean state rather thanvoid?
- *Hint 1:* Imagine function
outer()blocks signals, calls helperinner()which also temporarily blocks and unblocks signals, and thenouter()continues. - *Hint 2:* If
inner()unconditionally calledblockSignals(false)on exit instead ofblockSignals(previous), it would prematurely re-enable signals whileouter()still expects them blocked!
step 13/15 · 13. independent challenges
Add a QueuedEnvelope ring queue to MetaEndpoint that deep-copies two int32_t arguments out of void **args when a connection is marked queued = true, and drains queued metacalls later after the sender's stack frame has returned.
step 14/15 · 14. solutions and explanations
The reference files/core.cpp computes local_id = global_id - m_offset in qt_metacall(), global_sig = m_offset + local_signal_id in activate(), and preserves const bool previous = m_blocked in block_signals().
step 15/15 · run verification and inspect output
Run the verification command and confirm the output matches the expected contract.
learner@ksa:~/gl-q01/lab-m02./files/lab_clilearner@ksa:~/gl-q01/lab-m02str_idx=1 rx_acc=427 scaled_ret=60Progressive hints & solution
hint 1
Compare starter/Makefile against the module lessons. Focus first on: Builds libcore.a and lab_cli cleanly with -std=c++20 -Wall -Wextra -Werror -pedantic.
hint 2
Compile with -std=c11 -Wall -Wextra -Werror, check every system-call return value before touching output buffers, and verify cleanup on error paths.
solution
warning: Reveal the reference solution files? Running ./check.sh against your own attempt first builds stronger retention.
solution: files/Makefile
learner@ksa:~/gl-q01/lab-m02$ bat files/Makefile File: files/Makefile CC_BIN = g++ AR = ar CFLAGS_ALL = -std=c++20 -Wall -Wextra -Werror -pedantic -O2 LDLIBS = all: libcore.a lab_cli libcore.a: core.o $(AR) rcs $@ $^ lab_cli: cli.o libcore.a $(CC_BIN) $(CFLAGS_ALL) cli.o libcore.a $(LDLIBS) -o $@ %.o: %.cpp core.hpp $(CC_BIN) $(CFLAGS_ALL) -c $< -o $@ .PHONY: all clean clean: rm -f core.o cli.o libcore.a lab_clisolution: files/cli.cpp
learner@ksa:~/gl-q01/lab-m02$ bat files/cli.cpp File: files/cli.cpp #include "core.hpp" #include <algorithm> #include <array> #include <cstdint> #include <cstdio> #include <cstring> #include <ctime> #include <vector> namespace { static constexpr char kBlob[] = "GaugeNode\0pressureChanged\0applyReading\0"; static constexpr hmi::MetaSlice kSlices[] = {{0, 9}, {10, 15}, {26, 12}}; struct GaugeNode final : public hmi::MetaEndpoint { GaugeNode() : hmi::MetaEndpoint(&GaugeNode::dispatch, 5, 3) {} std::int64_t acc = 0; void emit_pressure(int kpa, int status) { void *a[] = {nullptr, &kpa, &status}; activate(0, a); } static void dispatch(hmi::MetaEndpoint *base, int local_id, void **a) { auto *self = static_cast<GaugeNode *>(base); if (local_id == 1) { const int kpa = *static_cast<const int *>(a[1]); const int st = *static_cast<const int *>(a[2]); self->acc += kpa * 10 + st; } else if (local_id == 2 && a[0]) { *static_cast<int *>(a[0]) = *static_cast<const int *>(a[1]) * 4; } } }; static std::uint64_t now_ns() noexcept { timespec ts{}; clock_gettime(CLOCK_MONOTONIC, &ts); return static_cast<std::uint64_t>(ts.tv_sec) * 1000000000ULL + static_cast<std::uint64_t>(ts.tv_nsec); } static int run_bench() { hmi::PackedStringTable tbl(kBlob, kSlices, 3); GaugeNode tx; GaugeNode rx1, rx2; tx.connect_to(5, &rx1, 6); tx.connect_to(5, &rx2, 6); constexpr int kWarmup = 5; constexpr int kSamples = 40; constexpr int kInner = 500; std::array<std::uint64_t, kSamples> ns{}; volatile std::int64_t sink = 0; for (int w = 0; w < kWarmup + kSamples; ++w) { const std::uint64_t t0 = now_ns(); for (int i = 0; i < kInner; ++i) { tx.emit_pressure(i, 1); sink += tbl.find_index("applyReading"); } const std::uint64_t dt = (now_ns() - t0) / static_cast<std::uint64_t>(kInner); if (w >= kWarmup) { ns[static_cast<std::size_t>(w - kWarmup)] = dt; } } sink += rx1.acc + rx2.acc; std::sort(ns.begin(), ns.end()); std::printf("BENCH lab_m02_moc_signal_dispatch clock=CLOCK_MONOTONIC " "benchmark_samples=40 warmup=5 p50_ns=%llu p95_ns=%llu p99_ns=%llu sink=%lld\n", static_cast<unsigned long long>(ns[20]), static_cast<unsigned long long>(ns[38]), static_cast<unsigned long long>(ns[39]), static_cast<long long>(sink)); return 0; } } // namespace int main(int argc, char **argv) { if (argc > 1 && std::strcmp(argv[1], "--bench") == 0) { return run_bench(); } hmi::PackedStringTable tbl(kBlob, kSlices, 3); GaugeNode tx, rx; tx.connect_to(5, &rx, 6); tx.emit_pressure(42, 7); int ret = 0, in_val = 15; void *args[] = {&ret, &in_val}; rx.qt_metacall(7, args); std::printf("str_idx=%d rx_acc=%lld scaled_ret=%d\n", tbl.find_index("pressureChanged"), static_cast<long long>(rx.acc), ret); return (tbl.find_index("pressureChanged") == 1 && rx.acc == 427 && ret == 60) ? 0 : 1; }solution: files/core.cpp
learner@ksa:~/gl-q01/lab-m02$ bat files/core.cpp File: files/core.cpp #include "core.hpp" #include <algorithm> namespace hmi { std::string_view PackedStringTable::get(std::size_t idx) const noexcept { if (!m_blob || !m_slices || idx >= m_count) { return {}; } return std::string_view(m_blob + m_slices[idx].offset, m_slices[idx].len); } int PackedStringTable::find_index(std::string_view name) const noexcept { for (std::size_t i = 0; i < m_count; ++i) { if (get(i) == name) { return static_cast<int>(i); } } return -1; } int MetaEndpoint::connect_to(int global_signal_id, MetaEndpoint *receiver, int global_slot_id) { if (!receiver || global_signal_id < 0 || global_slot_id < 0) { return 0; } const int cid = m_next_id++; m_links.push_back({cid, global_signal_id, receiver, global_slot_id, true}); return cid; } bool MetaEndpoint::disconnect_id(int conn_id) noexcept { for (auto &lnk : m_links) { if (lnk.id == conn_id && lnk.active) { lnk.active = false; return true; } } return false; } bool MetaEndpoint::block_signals(bool block) noexcept { const bool previous = m_blocked; m_blocked = block; return previous; } int MetaEndpoint::qt_metacall(int global_id, void **args) { if (global_id < 0) { return global_id; } if (global_id < m_offset) { return -1; } const int local_id = global_id - m_offset; if (local_id < m_count) { if (m_fn) { m_fn(this, local_id, args); } return -1; } return local_id - m_count; } void MetaEndpoint::activate(int local_signal_id, void **args) { if (m_blocked) { return; } const int global_sig = m_offset + local_signal_id; std::vector<int> snapshot; snapshot.reserve(m_links.size()); for (const auto &lnk : m_links) { if (lnk.active && lnk.global_signal_id == global_sig) { snapshot.push_back(lnk.id); } } for (int cid : snapshot) { for (const auto &lnk : m_links) { if (lnk.id == cid && lnk.active && lnk.receiver) { lnk.receiver->qt_metacall(lnk.global_slot_id, args); break; } } } m_links.erase( std::remove_if(m_links.begin(), m_links.end(), [] (const Link &l) { return !l.active; }), m_links.end()); } } // namespace hmisolution: files/core.hpp
learner@ksa:~/gl-q01/lab-m02$ bat files/core.hpp File: files/core.hpp #pragma once #include <cstddef> #include <cstdint> #include <string_view> #include <vector> namespace hmi { struct MetaSlice { std::uint32_t offset; std::uint32_t len; }; class PackedStringTable { public: PackedStringTable(const char *blob, const MetaSlice *slices, std::size_t count) noexcept : m_blob(blob), m_slices(slices), m_count(count) {} std::string_view get(std::size_t idx) const noexcept; int find_index(std::string_view name) const noexcept; std::size_t count() const noexcept { return m_count; } private: const char *m_blob; const MetaSlice *m_slices; std::size_t m_count; }; class MetaEndpoint; using MetacallFn = void (*)(MetaEndpoint *self, int local_id, void **args); class MetaEndpoint { public: MetaEndpoint(MetacallFn fn, int base_method_offset, int local_method_count) noexcept : m_fn(fn), m_offset(base_method_offset), m_count(local_method_count) {} virtual ~MetaEndpoint() = default; int connect_to(int global_signal_id, MetaEndpoint *receiver, int global_slot_id); bool disconnect_id(int conn_id) noexcept; bool signals_blocked() const noexcept { return m_blocked; } bool block_signals(bool block) noexcept; int qt_metacall(int global_id, void **args); void activate(int local_signal_id, void **args); private: struct Link { int id; int global_signal_id; MetaEndpoint *receiver; int global_slot_id; bool active; }; MetacallFn m_fn; int m_offset; int m_count; bool m_blocked = false; int m_next_id = 1; std::vector<Link> m_links; }; } // namespace hmiRun the check
From labs/lab_m02_moc_signal_dispatch/, run ./check.sh. A complete solution emits TAP version 13 with every test point marked ok and exits 0:
learner@ksa:~/gl-q01/lab-m02./check.shTAP version 131..5ok 1 - builds libcore.a and lab_cli cleanly with -std=c++20 -Wall -Wextra -Werror -pedanticok 2 - archives core.o into libcore.a and links independent TAP verifierok 3 - slices PackedStringTable without heap copies and subtracts m_offset in qt_metacallok 4 - returns previous blocked state from block_signals(bool) and suppresses emissionsok 5 - delivers multi-slot void** packs safely across re-entrant mid-dispatch self-disconnect# pass 5/5On an incomplete starter tree, ./check.sh exits non-zero and marks the unmet assertion not ok with an indented YAML diagnostic block:
learner@ksa:~/gl-q01/lab-m02./check.shTAP version 131..5ok 1 - builds libcore.a and lab_cli cleanly with -std=c++20 -Wall -Wextra -Werror -pedanticok 2 - archives core.o into libcore.a and links independent TAP verifiernot ok 3 - slices PackedStringTable without heap copies and subtracts m_offset in qt_metacallFAIL: compute local_id = global_id - m_offset in MetaEndpoint::qt_metacall and global_sig = m_offset + local_signal_id in activate --- message: 'got expected history {427}, got size 0' hint: 'compute local_id = global_id - m_offset in MetaEndpoint::qt_metacall and global_sig = m_offset + local_signal_id in activate' ...not ok 4 - returns previous blocked state from block_signals(bool) and suppresses emissionsFAIL: save const bool previous = m_blocked before assigning m_blocked = block and return previous --- message: 'got prev1 should be false' hint: 'save const bool previous = m_blocked before assigning m_blocked = block and return previous' ...not ok 5 - delivers multi-slot void** packs safely across re-entrant mid-dispatch self-disconnectFAIL: snapshot active connection IDs in MetaEndpoint::activate and match global_sig = m_offset + local_signal_id --- message: 'got self-disconnecting slot fired 0 times' hint: 'snapshot active connection IDs in MetaEndpoint::activate and match global_sig = m_offset + local_signal_id' ...# pass 2/5note: How to read TAP diagnostics: 1..N states the total test plan; each ok k confirms a passed check; not ok k pinpoints the failing check alongside message: (what went wrong) and hint: (where to look next) between --- and ....
inspect harness: check.sh
learner@ksa:~/gl-q01/lab-m02$ bat check.sh File: check.sh #!/bin/sh set -u cd "$(dirname "$0")" || exit 1 PASS=0 WORK=$(mktemp -d "${TMPDIR:-/tmp}/ksa_lab.XXXXXX") || exit 1 trap 'rm -rf "$WORK"' EXIT HUP INT TERM cp -R files "$WORK/files" printf 'TAP version 13\n1..5\n' if make -B -C "$WORK/files" >"$WORK/build.log" 2>&1; then printf 'ok 1 - builds libcore.a and lab_cli cleanly with -std=c++20 -Wall -Wextra -Werror -pedantic\n' PASS=$((PASS + 1)) else printf 'not ok 1 - builds libcore.a and lab_cli cleanly with -std=c++20 -Wall -Wextra -Werror -pedantic\n' printf 'FAIL: fix compiler warnings or errors in files/core.cpp\n' fi if [ -f "$WORK/files/libcore.a" ] && g++ -std=c++20 -Wall -Wextra -Werror -pedantic -O2 -I"$WORK/files" tests.cpp "$WORK/files/libcore.a" -o "$WORK/verify" >>"$WORK/build.log" 2>&1; then printf 'ok 2 - archives core.o into libcore.a and links independent TAP verifier\n' PASS=$((PASS + 1)) else printf 'not ok 2 - archives core.o into libcore.a and links independent TAP verifier\n' printf 'FAIL: preserve public declarations in files/core.hpp so tests.cpp links\n' fi if [ -x "$WORK/verify" ] && OUT=$("$WORK/verify" 1 2>&1); then printf 'ok 3 - slices PackedStringTable without heap copies and subtracts m_offset in qt_metacall\n' PASS=$((PASS + 1)) else printf 'not ok 3 - slices PackedStringTable without heap copies and subtracts m_offset in qt_metacall\n' printf 'FAIL: compute local_id = global_id - m_offset in MetaEndpoint::qt_metacall and global_sig = m_offset + local_signal_id in activate\n' printf " ---\n message: 'got %s'\n hint: 'compute local_id = global_id - m_offset in MetaEndpoint::qt_metacall and global_sig = m_offset + local_signal_id in activate'\n ...\n" "${OUT:-build_failed}" fi if [ -x "$WORK/verify" ] && OUT=$("$WORK/verify" 2 2>&1); then printf 'ok 4 - returns previous blocked state from block_signals(bool) and suppresses emissions\n' PASS=$((PASS + 1)) else printf 'not ok 4 - returns previous blocked state from block_signals(bool) and suppresses emissions\n' printf 'FAIL: save const bool previous = m_blocked before assigning m_blocked = block and return previous\n' printf " ---\n message: 'got %s'\n hint: 'save const bool previous = m_blocked before assigning m_blocked = block and return previous'\n ...\n" "${OUT:-build_failed}" fi if [ -x "$WORK/verify" ] && OUT=$("$WORK/verify" 3 2>&1); then printf 'ok 5 - delivers multi-slot void** packs safely across re-entrant mid-dispatch self-disconnect\n' PASS=$((PASS + 1)) else printf 'not ok 5 - delivers multi-slot void** packs safely across re-entrant mid-dispatch self-disconnect\n' printf 'FAIL: snapshot active connection IDs in MetaEndpoint::activate and match global_sig = m_offset + local_signal_id\n' printf " ---\n message: 'got %s'\n hint: 'snapshot active connection IDs in MetaEndpoint::activate and match global_sig = m_offset + local_signal_id'\n ...\n" "${OUT:-build_failed}" fi printf '# pass %d/5\n' "$PASS" [ "$PASS" -eq 5 ]Definition of done
Verification checklist
status: 0/3 checks verified
Troubleshooting
Compiler fails under -Werror on sign conversion or unused args
Use exact POSIX return types (ssize_t for read()/write(), size_t for byte counts) rather than relaxing flags.
./check.sh reports missing files in files/
Invoke ./check.sh from inside labs/lab_m02_moc_signal_dispatch/ so relative paths to files/ resolve directly.