You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Expose a PBN converter and withdraw the unreleased PBN twins - #401
Reworked following @tameware's review question — "have we considered deprecating the twins and providing a PBN to Deal convertor instead?". Investigated, and yes, for the unreleased part of the surface it's a clear win.
Expose the parser as dds_c_convert_from_pbn. Deal/DealPBN and DdTableDeal/DdTableDealPBN differ in exactly one field — the holdings; trump, first and currentTrick* are already binary — so one converter replaces a twin per function. Two consumers (the WASM shim at web/dds_web_wasm.cpp:191 and the Python context path at python/src/bindings.cpp:173) already hand-roll this conversion.
Withdraw dds_c_solve_board_pbn and dds_c_calc_par_pbn, plus their dds_* layer-2 counterparts. All four arrived in 5f8d4b11, which is not an ancestor of v3.1.0 — no tagged release carried them, so there's no compatibility window to honour. That window closes when v3.2.0 ships.
Keep dds_c_calc_dd_table_pbn. It shipped in v3.1.0 (3cbd3ea4), is in the pinned export set, and .NET binds it.
Keep the C++ solve_board_pbn / calc_par_pbn overloads as non-exported static-link conveniences. Neither is DLLEXPORT, so neither appears in any export list and neither carries ABI cost.
Java FFM binds the surviving twin plus the converter (the DEAL_PBN layout is gone with the twin it served).
Net effect on the pinned ABI: −2 symbols.
On the converter's contract
Copilot correctly spotted that dds_c_convert_from_pbn returns RETURN_NO_FAULT for a deal whose rank character is unrecognized (verified — it returns 1), which contradicted my header's promise of RETURN_PBN_FAULT for malformed input.
The resolution is documentation, not parser validation, because the leniency is deliberate:
library/tests/deal_input_validation_test.cpp:40 already pins this exact case ("a card replaced by an invalid rank") as rejected downstream with RETURN_CARD_COUNT, a resolution that came out of a fuzz finding (a 51-card deal reading past rel_rank_storage).
That same leniency is what lets a deal string carry a trailing \n/\r\n/\t from a PBN file. Making the parser strict breaks that test and would reject PBN-file line terminators across all 10 legacy *PBN entry points.
The converter cannot count cards itself either, since partial deals are legitimate mid-trick.
So the header now states what it actually guarantees: a successful parse is not a validated deal (check the solve/table status for RETURN_CARD_COUNT / RETURN_DUPLICATE_CARDS), and a failed parse does not preserve the output block — it is zeroed before validation, so converting in place into a live deal destroys the previous holdings. Both are pinned by tests.
Not addressed here
.NET needs no change — it binds the legacy dll.h twins (SolveBoardPBN, CalcParPBN) directly and dds_c_calc_dd_table_pbn, and never referenced the withdrawn symbols. Whether .NET should move onto the converter is a separate question that needs input from people who actually use that binding.
dll.h's 10 PBN twins are frozen for compatibility and unchanged.
Follow-up: deprecate the twins that did ship?
This PR only withdraws the two twins that never shipped — free to remove, no compatibility window. Two more PBN twins remain and are a genuinely separate decision, both blocked on the same thing:
dds_c_calc_dd_table_pbn / dds_calc_dd_table_pbn — the one surviving modern-layer twin. Shipped in v3.1.0; DdsNative.cs:86 binds it directly.
The 10 legacy dll.h twins (SolveBoardPBN, CalcDDtablePBN (+N/X), CalcAllTablesPBN (+N/X), SolveAllChunksPBN, CalcParPBN, AnalysePlayPBN, AnalyseAllPlaysPBN) — frozen for compatibility per this repo's own convention. Several are also bound directly by .NET.
Deprecating either means managing a real compatibility window for a shipped, bound symbol, not a free removal like this PR's withdrawal. Since .NET binds into both pools, this needs input from whoever owns that binding relationship before anyone touches it.
Test plan
bazel test //... — 100/100 pass.
dds_c_api_test covers the converter: reference-fixture agreement, null args → RETURN_UNKNOWN_FAULT, unparseable string → RETURN_PBN_FAULT, convert-then-solve reproducing the withdrawn twin's result, converter-vs-surviving-twin table agreement, unrecognized rank parsing through to RETURN_CARD_COUNT, and output-clobbering on failure.
dds_ffm_smoke_test covers convert-then-solve and pins RETURN_PBN_FAULT end to end through the JVM binding.
Export lists regenerated via gen_export_lists.py; export_set_test green.
dds_c_solve_board_pbn and dds_c_calc_par_pbn (and dds_c_calc_dd_table_pbn)
were already implemented and tested in the C shim per #284, but the Java
FFM binding (Dds.java) had no PBN support at all. Add the DealPBN /
DdTableDealPBN layouts and downcall handles, with smoke-test coverage
cross-checked against the same reference fixture used by dds_c_api_test.
Also fix specs/dds-public-api.md, which still claimed the shim had only
one PBN twin.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
This is fine if we want to make the existing PBN twins available in every API. Have we considered deprecating the twins and providing a PBN to Deal convertor instead?
Per review on #401: rather than grow one *_pbn twin per entry point in
every API, expose the parser itself. Deal/DealPBN and DdTableDeal/
DdTableDealPBN differ in exactly one field -- the holdings -- so a single
converter lets a binding parse a PBN string into the binary block and
then use the binary entry points.
Withdraw dds_c_solve_board_pbn and dds_c_calc_par_pbn, plus their dds_*
layer-2 counterparts. All four arrived in 5f8d4b1, which is not an
ancestor of v3.1.0, so nothing has shipped them and there is no
compatibility window to honour. dds_c_calc_dd_table_pbn did ship in
v3.1.0 and is bound by .NET, so it stays.
The C++ solve_board_pbn / calc_par_pbn overloads are kept: they cost
nothing at the ABI level and the batch/analyse paths still need them.
.NET is unaffected -- it binds the legacy dll.h twins directly and never
referenced the withdrawn symbols.
Co-Authored-By: Claude Opus 5 <[email protected]>
zzcgumn
changed the title
Add PBN bindings to the Java FFM shim
Expose a PBN converter and withdraw the unreleased PBN twins
Sep 26, 2026
@tameware , Claude agreed that your suggestion creates a cleaner API. This pull request has been updated accordingly, but previous reviews are now stale.
Copilot flagged that dds_c_convert_from_pbn returns RETURN_NO_FAULT for a
deal with an unrecognized rank character, contradicting the header's
promise of RETURN_PBN_FAULT for malformed input. Verified: it returns 1.
The parser's leniency is deliberate, not a defect. Skipping unrecognized
characters is what lets a deal string carry a trailing newline from a PBN
file, and deal_input_validation_test already pins this exact case --
"a card replaced by an invalid rank" -- as rejected downstream on card
count, a resolution that came out of a fuzz finding. The converter also
cannot count cards itself, since partial deals are legitimate mid-trick.
So the defect was the contract I wrote, not the parser: making it strict
broke that test and would reject PBN-file line terminators.
Document what the function actually guarantees: a successful parse is not
a validated deal, and a failed parse does not preserve the output block
(it is zeroed before validation, so converting in place into a live deal
destroys the previous holdings). Both are now pinned by tests.
Also from the local branch review:
- Drop the false claim that the C++ solve_board_pbn / calc_par_pbn
overloads serve the batch/analyse paths. They do not: those call
convert_from_pbn directly, solve_board_pbn has one in-tree caller and
calc_par_pbn has none. Neither is DLLEXPORT, so "for C++ consumers"
was also wrong for shared-library consumers.
- Say "before any tagged release" rather than "before ever shipping", and
note DDS_VERSION is not bumped between tags.
- Un-stale docs/jni_interface.md: add dds_c_convert_from_pbn and
DD_TABLE_DEAL_PBN, and correct "the .NET binding uses all of it".
- Pin RETURN_PBN_FAULT in the JVM test instead of just "not success".
- Bump the spec's last-updated stamp.
Co-Authored-By: Claude Opus 5 <[email protected]>
Copilot correctly flagged that "unrecognized characters are skipped
rather than refused" overgeneralized: convert_from_pbn's else-if chain
(library/src/pbn.cpp:113-114) explicitly returns 0 for a compass letter
(N/E/S/W) found after the first hand, rather than falling through to the
silent skip that every other unrecognized character gets. Verified with
a new test pinning RETURN_PBN_FAULT for a stray compass letter, distinct
from the existing test pinning silent-skip-then-card-count-rejection for
an unrecognized rank.
Corrected both copies of the claim (dds_c_api.h, Dds.java); the spec
bullet doesn't get into this level of detail, so it needed no change.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Narrow clobbering guarantee to valid native parse failures
jni/java/org/dds/ffm/Dds.java:324
This repeats the same overbroad failure contract as the C header: passing a null MemorySegment for pbnDeal causes the native guard to return RETURN_UNKNOWN_FAULT before the output is cleared, and Java-side invocation errors can also occur before native parsing. Document the clobbering guarantee only for parse failures after valid segments/pointers have reached the native parser.
Document valid 80-byte PBN field boundary
library/src/api/dds_c_api.h:77
The parser accepts a complete string whose NUL terminator is at byte 79 (80 bytes including the terminator); it rejects only when no terminator is seen within the 80-byte scan window, as covered by library/tests/pbn_test.cpp:136-149. Saying "shorter than 80 bytes including its terminator" incorrectly excludes that valid boundary case.
Narrow failure clobbering promise for null inputs
library/src/api/dds_c_api.h:100
When pbn_deal is null, the implementation returns RETURN_UNKNOWN_FAULT before calling convert_from_pbn, so a non-null cards block is left unchanged. The blanket “On failure” wording here is therefore false for null-input failures and can make callers assume stale holdings were clobbered; narrow this promise to parse failures after both pointers have been validated (or explicitly clear cards before that return).
Copilot flagged two more overbroad claims in dds_c_convert_from_pbn's
contract, both confirmed against the implementation before fixing:
- "On failure the output is NOT preserved" was stated as a blanket rule,
but dds_c_api.cpp's null-pointer guard returns RETURN_UNKNOWN_FAULT
before convert_from_pbn is ever called, so a null pbn_deal leaves an
existing cards block completely untouched, not zeroed. The clobbering
only happens once the string reaches the parser and is rejected with
RETURN_PBN_FAULT. Pinned with a new test that pre-fills cards with a
sentinel and asserts it survives a null pbn_deal.
- "must be shorter than 80 bytes including its terminator" excluded a
valid boundary: library/tests/pbn_test.cpp already pins that a
terminator at byte 79 (80 bytes total) is accepted, since the parser's
scan loop runs while bp < 80. Pinned at this layer too: the reference
deal padded with skip-characters out to exactly that length still
converts and solves identically.
Corrected both dds_c_api.h and the matching Dds.java javadoc, which also
needed the Java-specific case Copilot pointed out: an exception thrown
before the native call completes leaves cards untouched the same way a
null segment does. The spec doesn't restate either claim at this level
of detail, so it needed no change.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
@tameware on dds_c_api.h:82: "clients with PBN will need to call
dds_c_convert_from_pbn and then the binary solve or par" -- the comment
said solve/par have no PBN twin "because of" this function without
saying what a caller actually does with it. State the calling pattern
directly and name the two entry points, in both dds_c_api.h and the
matching Dds.java javadoc.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reworked following @tameware's review question — "have we considered deprecating the twins and providing a PBN to Deal convertor instead?". Investigated, and yes, for the unreleased part of the surface it's a clear win.
dds_c_convert_from_pbn.Deal/DealPBNandDdTableDeal/DdTableDealPBNdiffer in exactly one field — the holdings;trump,firstandcurrentTrick*are already binary — so one converter replaces a twin per function. Two consumers (the WASM shim atweb/dds_web_wasm.cpp:191and the Python context path atpython/src/bindings.cpp:173) already hand-roll this conversion.dds_c_solve_board_pbnanddds_c_calc_par_pbn, plus theirdds_*layer-2 counterparts. All four arrived in5f8d4b11, which is not an ancestor ofv3.1.0— no tagged release carried them, so there's no compatibility window to honour. That window closes when v3.2.0 ships.dds_c_calc_dd_table_pbn. It shipped in v3.1.0 (3cbd3ea4), is in the pinned export set, and .NET binds it.solve_board_pbn/calc_par_pbnoverloads as non-exported static-link conveniences. Neither isDLLEXPORT, so neither appears in any export list and neither carries ABI cost.DEAL_PBNlayout is gone with the twin it served).Net effect on the pinned ABI: −2 symbols.
On the converter's contract
Copilot correctly spotted that
dds_c_convert_from_pbnreturnsRETURN_NO_FAULTfor a deal whose rank character is unrecognized (verified — it returns1), which contradicted my header's promise ofRETURN_PBN_FAULTfor malformed input.The resolution is documentation, not parser validation, because the leniency is deliberate:
library/tests/deal_input_validation_test.cpp:40already pins this exact case ("a card replaced by an invalid rank") as rejected downstream withRETURN_CARD_COUNT, a resolution that came out of a fuzz finding (a 51-card deal reading pastrel_rank_storage).\n/\r\n/\tfrom a PBN file. Making the parser strict breaks that test and would reject PBN-file line terminators across all 10 legacy*PBNentry points.So the header now states what it actually guarantees: a successful parse is not a validated deal (check the solve/table status for
RETURN_CARD_COUNT/RETURN_DUPLICATE_CARDS), and a failed parse does not preserve the output block — it is zeroed before validation, so converting in place into a live deal destroys the previous holdings. Both are pinned by tests.Not addressed here
.NET needs no change — it binds the legacy
dll.htwins (SolveBoardPBN,CalcParPBN) directly anddds_c_calc_dd_table_pbn, and never referenced the withdrawn symbols. Whether .NET should move onto the converter is a separate question that needs input from people who actually use that binding.dll.h's 10 PBN twins are frozen for compatibility and unchanged.Follow-up: deprecate the twins that did ship?
This PR only withdraws the two twins that never shipped — free to remove, no compatibility window. Two more PBN twins remain and are a genuinely separate decision, both blocked on the same thing:
dds_c_calc_dd_table_pbn/dds_calc_dd_table_pbn— the one surviving modern-layer twin. Shipped in v3.1.0;DdsNative.cs:86binds it directly.dll.htwins (SolveBoardPBN,CalcDDtablePBN(+N/X),CalcAllTablesPBN(+N/X),SolveAllChunksPBN,CalcParPBN,AnalysePlayPBN,AnalyseAllPlaysPBN) — frozen for compatibility per this repo's own convention. Several are also bound directly by .NET.Deprecating either means managing a real compatibility window for a shipped, bound symbol, not a free removal like this PR's withdrawal. Since .NET binds into both pools, this needs input from whoever owns that binding relationship before anyone touches it.
Test plan
bazel test //...— 100/100 pass.dds_c_api_testcovers the converter: reference-fixture agreement, null args →RETURN_UNKNOWN_FAULT, unparseable string →RETURN_PBN_FAULT, convert-then-solve reproducing the withdrawn twin's result, converter-vs-surviving-twin table agreement, unrecognized rank parsing through toRETURN_CARD_COUNT, and output-clobbering on failure.dds_ffm_smoke_testcovers convert-then-solve and pinsRETURN_PBN_FAULTend to end through the JVM binding.gen_export_lists.py;export_set_testgreen.🤖 Generated with Claude Code