Skip to content

refactor: extract native-call helpers into NativeCall#14

Merged
dfa1 merged 3 commits into
mainfrom
refactor/native-call-helper
Jun 26, 2026
Merged

refactor: extract native-call helpers into NativeCall#14
dfa1 merged 3 commits into
mainfrom
refactor/native-call-helper

Conversation

@dfa1

@dfa1 dfa1 commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Related internal refactors, all package-private — no public API / javadoc surface change.

1. Extract NativeCall

Move the FFM-downcall conventions out of Zstd:

  • interface ZstdCall (was SizeCall)
  • checkReturnValue(ZstdCall) (was call) — run a size_t call, decode a ZSTD_isError code into a ZstdException
  • isError / errorCode / errorName
  • requireNative segment guard

Zstd keeps its public one-shot byte[] API + copyIn/copyOut. All call sites repointed.

2. Collapse duplicated rethrow/sneaky

13 binding classes each carried their own copy of the unchecked-rethrow helper. Replaced with one shared NativeCall.rethrow.

3. Read ZSTD_bounds via its named layout

Name BOUNDS_LAYOUT's fields and derive ZstdBounds.query's read offsets with byteOffset(groupElement(...)) instead of hand-counted 0/8/12, plus a comment on how the struct-by-value return allocates through the arena SegmentAllocator.

Test

./mvnw -pl zstd,integration-tests -am verify — 138 unit + 79 integration green, checkstyle + javadoc clean.

🤖 Generated with Claude Code

dfa1 and others added 3 commits June 26, 2026 20:37
Move the FFM-downcall conventions out of Zstd into a dedicated
package-private NativeCall:

- interface ZstdCall (was SizeCall)
- checkReturnValue(ZstdCall) (was call) — run a size_t call, decode a
  ZSTD_isError code into a ZstdException
- isError / errorCode / errorName
- requireNative segment guard

Zstd keeps its one-shot byte[] API plus copyIn/copyOut. All call sites
(contexts, streams, dicts, frame, bounds) repointed. No behaviour change;
these are all package-private internals.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…Call

Every binding class carried its own private rethrow/sneaky to launder the
checked Throwable from MethodHandle.invokeExact. Replace them with one
shared NativeCall.rethrow and repoint all catch blocks.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Name BOUNDS_LAYOUT's fields (error/lowerBound/upperBound) and derive the
read offsets from it with byteOffset(groupElement(...)), so the struct
reads track the definition instead of hand-counted 0/8/12. Document how
the struct-by-value return allocates through the arena SegmentAllocator.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dfa1 dfa1 merged commit 720243e into main Jun 26, 2026
1 check passed
@dfa1 dfa1 deleted the refactor/native-call-helper branch June 26, 2026 18:49
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