Skip to content

Define the SbHash noexcept hash contract - #753

Draft
Dikluwe wants to merge 7 commits into
coin3d:masterfrom
Dikluwe:fix/sbhash-04-noexcept-contract
Draft

Dikluwe wants to merge 7 commits into
coin3d:masterfrom
Dikluwe:fix/sbhash-04-noexcept-contract

Conversation

@Dikluwe

@Dikluwe Dikluwe commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • declare the closed set of Coin SbHashFunc overloads and implicit key conversions noexcept
  • enforce the non-throwing hash contract at the bucket-index boundary with static_assert
  • hash const char * directly without constructing a temporary SbString, while preserving the historical content hash and prime-bucket mapping
  • cover the mapping and C-string behavior with regression tests

Stack

Depends on #752. Until the preceding PRs are merged, GitHub shows their commits here as well; the new change is the final hash-contract commit.

Testing

  • full six-commit stack: ctest --test-dir /tmp/coin-sbhash-pr-build --output-on-failure (8/8 passed)
  • integration lab: 25/25 tests passed

This is PR 4 of 6 in the SbHash cleanup series.

The self-assignment test added in the previous commit is the first
place that instantiates SbHash<unsigned int,int>::operator=() inside
CoinTests.exe. That method calls coin_geq_prime_number(), a private
Coin symbol not exported from the Windows DLL, so the test binary
failed to link with "unresolved external symbol coin_geq_prime_number".

Compile a copy of the (small, self-contained) implementation directly
into the test executable, matching the existing dict.cpp precedent
used elsewhere in this file for the same class of problem.
@Dikluwe
Dikluwe force-pushed the fix/sbhash-04-noexcept-contract branch from f935967 to 5d63abc Compare September 18, 2026 21:42
@Dikluwe
Dikluwe force-pushed the fix/sbhash-04-noexcept-contract branch from 5d63abc to f066f96 Compare September 18, 2026 21:52
On Win64 with COIN_INTERNAL defined, only the unsigned-long-long
overload of SbHashFunc is available. The test called SbHashFunc(0U),
but the literal 0U is also a valid null-pointer-constant candidate for
SbHashFunc's pointer overloads (const char *, const SoBase *, ...).
GCC/Clang resolve this to the integral conversion unambiguously; MSVC
reports it as an ambiguous call.

Use a named unsigned int variable instead of the literal: a named
value (even holding 0) is never a null-pointer constant, so the
overload set is unambiguous on every compiler.
@Dikluwe
Dikluwe force-pushed the fix/sbhash-04-noexcept-contract branch from c4a89c4 to c7adbf3 Compare September 18, 2026 22:17
The SbHash_hashes_c_strings_without_an_SbString_temporary test calls
SbHashFunc(const SbString &), a private Coin symbol defined out of
line in src/base/SbString.cpp. Like coin_geq_prime_number() before it,
this symbol is not exported from the Windows DLL, so linking
CoinTests.exe failed with LNK2019.

Compile a copy of the (small, self-contained) implementation directly
into the test executable, matching the existing dict.cpp and
CoinGeqPrimeNumberWin32TestSupport.cpp precedent in this file.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant