Skip to content

Commit 38f0f63

Browse files
committed
stack_pops test: sentinel-below stack-hygiene check
Address review on #3836 (same fix as #3828's setpointer test): the trailing 'push 5.0, pop, expect 5.0' proved nothing -- a stack returns the most recently pushed item, so a sentinel pushed after the pops only probes the current top. Push the sentinel FIRST, before any symbol/object push, and recover it at the end; that proves the pops neither over-popped into what lay beneath nor left anything behind.
1 parent d69f6de commit 38f0f63

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

test/api/stack_pops.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ int main(void) {
3131

3232
bool ok = true;
3333

34+
// Push a sentinel FIRST, below everything else the test does. The stack is
35+
// LIFO, so if every push below is matched by exactly one pop the sentinel
36+
// resurfaces on top at the end; recovering it then proves the pops neither
37+
// over-popped into what lay beneath them nor left anything behind. A
38+
// sentinel pushed *after* the pops could prove neither -- it would only ever
39+
// probe the current top.
40+
const double SENTINEL = 424242.0;
41+
nrn_double_push(SENTINEL);
42+
3443
// nrn_symbol_pop returns the Symbol on top of the stack, LIFO.
3544
Symbol* v = nrn_symbol("v");
3645
Symbol* t = nrn_symbol("t");
@@ -57,9 +66,10 @@ int main(void) {
5766
nrn_object_push(nullptr);
5867
ok &= check(nrn_object_pop() == nullptr, "object pop returns NULL for a nil objref");
5968

60-
// Stack balance: the pops above consumed exactly what was pushed.
61-
nrn_double_push(5.0);
62-
ok &= check(nrn_double_pop() == 5.0, "stack is balanced after the pops");
69+
// Balance: with every push above consumed by exactly one pop, the sentinel
70+
// from the very start is what remains on top.
71+
ok &= check(nrn_double_pop() == SENTINEL,
72+
"sentinel from before the pops is intact -- the stack is balanced");
6373

6474
return ok ? 0 : 1;
6575
}

0 commit comments

Comments
 (0)