Skip to content

chore: Add debug assertions before unsafe code blocks#3655

Merged
andygrove merged 1 commit intoapache:mainfrom
andygrove:debug-assert-unsafe
Mar 10, 2026
Merged

chore: Add debug assertions before unsafe code blocks#3655
andygrove merged 1 commit intoapache:mainfrom
andygrove:debug-assert-unsafe

Conversation

@andygrove
Copy link
Copy Markdown
Member

@andygrove andygrove commented Mar 10, 2026

Summary

  • Add debug_assert! statements between SAFETY comments and unsafe blocks throughout the native Rust code
  • Assertions catch precondition violations during development/testing (null pointers, out-of-bounds indices, uninitialized globals, alignment, negative sizes)
  • Zero runtime cost in release builds

Files changed

  • native/core/src/execution/shuffle/spark_unsafe/row.rs — pointer null checks on all accessor methods, row initialization checks, loop bounds checks
  • native/core/src/execution/shuffle/spark_unsafe/list.rs — address validity and index bounds checks
  • native/core/src/execution/shuffle/spark_unsafe/map.rs — address and size validity checks
  • native/core/src/execution/jni_api.rs — address, size, and alignment checks for sort partition
  • native/core/src/execution/utils.rs — pointer alignment checks before aligned writes
  • native/core/src/jvm_bridge/mod.rs — initialization checks before get_unchecked() calls

Add debug_assert! statements between SAFETY comments and unsafe blocks
to catch precondition violations during development and testing.

Assertions cover:
- Null pointer checks before raw pointer dereference
- Index bounds checks before array/bitset access
- Initialization checks before accessing global singletons
- Alignment checks before aligned pointer writes
- Non-negative size/length checks before slice construction
@andygrove andygrove force-pushed the debug-assert-unsafe branch from b7a72e7 to 1ce1de7 Compare March 10, 2026 14:24
@andygrove andygrove changed the title Add debug assertions before unsafe code blocks chore: Add debug assertions before unsafe code blocks Mar 10, 2026
Copy link
Copy Markdown
Contributor

@mbutrovich mbutrovich left a comment

Choose a reason for hiding this comment

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

Thanks @andygrove!

@andygrove andygrove merged commit 9909535 into apache:main Mar 10, 2026
113 of 114 checks passed
@andygrove andygrove deleted the debug-assert-unsafe branch March 10, 2026 16:22
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.

2 participants