Skip to content

Commit 0a47cbf

Browse files
luisleo526claude
andcommitted
Tests: both spellings are one double at one offset, proved from C (R5 gap lane P2c, item 4)
`tests/test_c_abi.c` is the only unit compiled by a C compiler against the installed header, so it is where the deprecated-alias contract belongs. The existing `m.equity.sharpe_tv` roundtrip is kept verbatim; beside it the unit now writes through each spelling and reads back through the other, in both directions, for both pairs, and pins the layout the alias must not move: offsets 48 / 56 / 64 / 112, `sizeof(pf_equity_stats_t) == 120`, `offsetof(pf_metrics_t, equity) == 648`, `sizeof(pf_metrics_t) == 768` — the numbers measured on 1974e87, before the union existed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 329e021 commit 0a47cbf

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

‎tests/test_c_abi.c‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <pineforge/pineforge.h>
1515

16+
#include <stddef.h>
1617
#include <stdio.h>
1718
#include <string.h>
1819
#include <stdint.h>
@@ -50,6 +51,46 @@ int main(void) {
5051
CHECK(m.all.num_trades == 42, "m.all.num_trades roundtrip");
5152
CHECK(m.equity.sharpe_tv == 1.5, "m.equity.sharpe_tv roundtrip");
5253
CHECK(p.time_ms == 1700000000000LL, "p.time_ms roundtrip");
54+
55+
/* R5 gap lane P2c: sharpe_monthly / sortino_monthly are the generic
56+
* spelling of the fields this ABI shipped as sharpe_tv / sortino_tv.
57+
* The old names are DEPRECATED aliases, removed at the next
58+
* PF_ABI_VERSION (ADR-0001, "Deprecated public spellings"). Both
59+
* spellings must name ONE double at ONE offset, in both directions,
60+
* with no growth of the struct. Checked from C because that is the
61+
* language of the contract. */
62+
CHECK(m.equity.sharpe_monthly == 1.5,
63+
"m.equity.sharpe_monthly reads what sharpe_tv wrote");
64+
m.equity.sharpe_monthly = -0.25;
65+
CHECK(m.equity.sharpe_tv == -0.25,
66+
"m.equity.sharpe_tv reads what sharpe_monthly wrote");
67+
m.equity.sortino_monthly = 3.75;
68+
CHECK(m.equity.sortino_tv == 3.75,
69+
"m.equity.sortino_tv reads what sortino_monthly wrote");
70+
m.equity.sortino_tv = -1.125;
71+
CHECK(m.equity.sortino_monthly == -1.125,
72+
"m.equity.sortino_monthly reads what sortino_tv wrote");
73+
CHECK(offsetof(pf_equity_stats_t, sharpe_monthly)
74+
== offsetof(pf_equity_stats_t, sharpe_tv),
75+
"sharpe_monthly / sharpe_tv share one offset");
76+
CHECK(offsetof(pf_equity_stats_t, sortino_monthly)
77+
== offsetof(pf_equity_stats_t, sortino_tv),
78+
"sortino_monthly / sortino_tv share one offset");
79+
/* The offsets and the size measured on 1974e87e, the commit before
80+
* the alias: the union must not move or grow anything. */
81+
CHECK(offsetof(pf_equity_stats_t, sharpe_monthly) == 48,
82+
"pf_equity_stats_t::sharpe_monthly is still at offset 48");
83+
CHECK(offsetof(pf_equity_stats_t, sortino_monthly) == 56,
84+
"pf_equity_stats_t::sortino_monthly is still at offset 56");
85+
CHECK(offsetof(pf_equity_stats_t, sharpe_bar) == 64,
86+
"pf_equity_stats_t::sharpe_bar is still at offset 64");
87+
CHECK(offsetof(pf_equity_stats_t, open_pl) == 112,
88+
"pf_equity_stats_t::open_pl is still at offset 112");
89+
CHECK(sizeof(pf_equity_stats_t) == 120,
90+
"sizeof(pf_equity_stats_t) is still 120");
91+
CHECK(offsetof(pf_metrics_t, equity) == 648,
92+
"pf_metrics_t::equity is still at offset 648");
93+
CHECK(sizeof(pf_metrics_t) == 768, "sizeof(pf_metrics_t) is still 768");
5394
}
5495

5596
/* ── Bar field access ────────────────────────────────────────── */

0 commit comments

Comments
 (0)