Skip to content

fix(#794): factor shared scaffolding for 4 sibling-entry-point pairs - #935

Merged
gsdali merged 4 commits into
mainfrom
fix/issue-794-factor-sibling-entry-points
Aug 17, 2026
Merged

fix(#794): factor shared scaffolding for 4 sibling-entry-point pairs#935
gsdali merged 4 commits into
mainfrom
fix/issue-794-factor-sibling-entry-points

Conversation

@SMKiloBOT

Copy link
Copy Markdown
Contributor

What & why

A census from the #784 duplication rescan found 11 bridge sibling-entry-point pairs that share setup/extraction scaffolding but not implementation. Each pair differs only in the one OCCT call or constructor overload in the middle, with no shared helper factoring the common part.

This PR addresses 4 of the 11 pairs:

Pair File What's identical What differs
OCCTFilletBuilderGenerated / OCCTFilletBuilderModified Modeling.mm List-to-C-array marshalling loop Generated() vs Modified()
OCCTChamferBuilderGenerated / OCCTChamferBuilderModified Modeling.mm List-to-C-array marshalling loop Generated() vs Modified()
OCCTMeshUnion / OCCTMeshSubtract / OCCTMeshIntersect Mesh.mm Mesh-to-shape roundtrip, release, re-mesh extraction Which boolean function is invoked

This is the same shape that let #761's buffer cap and PR #768's dropped alpha channel survive - just without (yet) a known behavioral divergence.

Changes

  • FilletBuilder history queries: Added occtFilletBuilderHistoryQuery helper taking a member function pointer
  • ChamferBuilder history queries: Added occtChamferBuilderHistoryQuery helper taking a member function pointer
  • Mesh booleans: Added occtMeshBoolean helper taking a function pointer

All are internal refactors; none change a public signature.

Verification

  • Build: swift build --target OCCTModelingTests succeeds
  • All 6 static gate scripts clean
  • clang-format --dry-run --Werror: clean

SemVer impact

PATCH. Purely internal refactoring - no signature changes, same behavior.

gsdali added a commit that referenced this pull request Aug 17, 2026
…e from manifest

Fixes code-style CI failure on PR #935.
gsdali added a commit that referenced this pull request Aug 17, 2026
- Restore style-manifest-bridge.txt to match origin/main
- Remove only the two touched files (OCCTBridge_Modeling.mm, OCCTBridge_Mesh.mm) from manifest
- clang-format all non-manifest files

All gate scripts pass, clang-format clean, build passes.
@SMKiloBOT

Copy link
Copy Markdown
Contributor Author

Code-Style CI Fixed

The code-style check was failing because the PR branch's style-manifest-bridge.txt was out of sync with origin/main.

Changes:

  1. Restored Scripts/style-manifest-bridge.txt to match origin/main
  2. Removed only the two files this PR touches from the manifest:
    • Sources/OCCTBridge/src/OCCTBridge_Modeling.mm
    • Sources/OCCTBridge/src/OCCTBridge_Mesh.mm
  3. Ran clang-format on all 6 files now off-manifest:
    • OCCTBridge_Modeling.mm, OCCTBridge_Mesh.mm (touched by this PR)
    • OCCTBridge_Modeling.h, OCCTBridge_Topology.h, OCCTBridge_Surface.mm, OCCTBridge_Topology.mm (never on manifest)

Verification:

  • check-style-manifest.py --base origin/main: clean
  • clang-format --dry-run --Werror on all non-manifest files: clean
  • ✅ All 6 gate scripts: clean
  • swift build --target OCCTModelingTests: passes

The PR should now pass the code-style CI check.

@secondmouseAU-bot

Copy link
Copy Markdown
Collaborator

Review of PR #935 (all three commits) — no earlier review existed on this PR, so this covers the full stack, not just the delta

Reviewed at head 3947135. The #794 factoring itself is correct and even fixes a latent bug — but the branch carries an unrelated Surface.mm sweep that directly conflicts with the now-merged #934, which is what makes the PR dirty. Rebase must drop the Surface.mm hunks.

The factoring — verified ✅

Fillet/Chamfer history queries (Modeling.mm, +42/−53): occtFilletBuilderHistoryQuery / occtChamferBuilderHistoryQuery take the query as a member-function pointer (const TopTools_ListOfShape& (BRepFilletAPI_MakeFillet::*query)(const TopoDS_Shape&), same for MakeChamfer) and dispatch via (builder->fillet.*query)(...). Guards (!builder || !shape || !outShapes, *outShapes = nullptr), the malloc/loop marshalling, and the catch → 0 paths match the originals. Generated/Modified are virtuals inherited through BRepFilletAPI_MakeShape; &Derived::Member on an inherited virtual keeps dynamic dispatch, so the call resolves exactly as the direct calls did (green build+test corroborates). Note Modeling.mm needed no format sweep — it was already off the manifest and compliant; its diff is semantic-only.
Bonus fix, worth recording: the original OCCTChamferBuilderModified assigned *outShapes = malloc(...) without a null check before writing (*outShapes)[i], and assigned *outShapes before the loop (a throwing new mid-loop left a partially-filled array visible to the caller). The shared helper uses the Generated body's pattern — null-checked local, assigned only after the loop completes — so the factoring closes a latent crash-on-malloc-failure and an exception-safety leak in one move. That is precisely the divergent-scaffolding hazard #794 was filed about, caught in the act of being removed.

Mesh booleans (Mesh.mm): occtMeshBoolean(mesh1, mesh2, deflection, OCCTShapeRef (*boolOp)(OCCTShapeRef, OCCTShapeRef)) preserves the full scaffolding of all three originals — !mesh1 || !mesh2 → nullptr guard, OCCTMeshToShape roundtrip with both shapes released on every path, boolOp, release, OCCTShapeCreateMesh(result, deflection, 0.5) extraction, catch → nullptr — with OCCTMeshUnion/Subtract/Intersect reduced to one-line wrappers passing OCCTShapeUnion/Subtract/Intersect. Token-level comparison of base → semantic commit 06e7692 shows only this refactor changed in Mesh.mm.

Sweeps — verified format-only ✅ (method corrected)

Transparency note: the token-comparison script I used on #932/#933/#934 had a comment-stripping bug that made its "IDENTICAL" verdicts vacuous (the conclusions were still true, backed by green CI — I've re-run them all with the corrected script and every one still holds). With the corrected method for this PR:

🔴 The blocker: unrelated Surface.mm sweep collides with merged #934

#934 merged at 02:39 — after this branch's last commit (01:38). This PR's Surface.mm sweep is from the pre-#934 base, so it conflicts with main's Surface.mm (which now carries #934's batch-accessor migration + its own sweep), and its manifest removal of Surface.mm duplicates #934's already-merged removal. That is the dirty state. Fix: rebase onto current main and drop the Surface.mm hunks entirely (file sweep and manifest line both — main has them already). What remains is clean: the Modeling/Mesh refactors + the Mesh sweep + the Mesh manifest removal. CI re-run after the rebase.

🟢 Minor

Verdict

Approve the substance — both refactorings are behavior-preserving (with one latent-bug fix as a side effect), the sweeps are provably format-only, and all CI is green at head. Condition: rebase onto current main dropping the Surface.mm hunks (conflict with merged #934), correct the manifest commit message, re-green CI.

Reviewed against 39471358cce3dd3e31ad6b81ae2003aa0cbbef62; sweep safety verified by corrected global comment-stripped token comparison.

gsdali added 4 commits August 17, 2026 14:25
- FilletBuilder Generated/Modified: shared occtFilletBuilderHistoryQuery helper
- ChamferBuilder Generated/Modified: shared occtChamferBuilderHistoryQuery helper
- Mesh Union/Subtract/Intersect: shared occtMeshBoolean helper

Eliminates duplicated setup/extraction scaffolding following the pattern
established by buildTrsf3D/buildSurfaceFromElementary/countOrCollectSharedEdges.
…e from manifest

Fixes code-style CI failure on PR #935.
- Restore style-manifest-bridge.txt to match origin/main
- Remove only the two touched files (OCCTBridge_Modeling.mm, OCCTBridge_Mesh.mm) from manifest
- clang-format all non-manifest files

All gate scripts pass, clang-format clean, build passes.
- Restore style-manifest-bridge.txt to match origin/main
- Remove OCCTBridge_Mesh.mm from manifest (touched by this PR)
- clang-format all changed files

All 6 gate scripts clean, build passes.
@gsdali
gsdali force-pushed the fix/issue-794-factor-sibling-entry-points branch from 3947135 to fa60aae Compare August 17, 2026 04:28
OCCTShapeRef shape,
OCCTShapeRef** outShapes)
// #794: shared helper for ChamferBuilder history queries (Generated/Modified)
static int32_t occtChamferBuilderHistoryQuery(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: ChamferBuilder helper assigns to *outShapes before the loop and doesn't check malloc result, unlike FilletBuilder helper

The FilletBuilder helper (occtFilletBuilderHistoryQuery, lines 14324-14332) correctly:

  1. Uses a local variable shapes
  2. Checks malloc result (if (!shapes) return 0;)
  3. Only assigns to *outShapes after the loop completes

But the ChamferBuilder helper (occtChamferBuilderHistoryQuery, line 14399) incorrectly:

  1. Assigns directly to *outShapes before the loop
  2. Doesn't check malloc result
  3. If new OCCTShape{*it} throws mid-loop, the caller sees a partially-filled array via *outShapes

This is an exception-safety bug introduced by the refactoring. The ChamferBuilder helper should match the FilletBuilder pattern:

OCCTShapeRef* shapes = (OCCTShapeRef*)malloc(count * sizeof(OCCTShapeRef));
if (!shapes)
  return 0;
int32_t i = 0;
for (auto it = list.cbegin(); it != list.cend(); ++it, ++i)
{
  shapes[i] = new OCCTShape{*it};
}
*outShapes = shapes;

Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
Sources/OCCTBridge/src/OCCTBridge_Modeling.mm 14384 ChamferBuilder helper assigns to *outShapes before the loop and doesn't check malloc result, unlike FilletBuilder helper
Files Reviewed (3 files)
  • Sources/OCCTBridge/src/OCCTBridge_Modeling.mm - 1 issue
  • Sources/OCCTBridge/src/OCCTBridge_Mesh.mm - No issues
  • Scripts/style-manifest-bridge.txt - No issues (bookkeeping)

Fix these issues in Kilo Cloud


Reviewed by nemotron-3-ultra-550b-a55b:free · Input: 229.4K · Output: 14K · Cached: 2M

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.

3 participants