jna

GitHub

用于在 Kotlin/Java 中实现或调试 JNA 绑定及 ABI 布局。涵盖复用映射、保持反射类型可访问、匹配原生 ABI 及验证测试等规范。

.agents/skills/jna/SKILL.md DetachHead/rebased

触发场景

实现 JNA 绑定 调试 JNA 绑定 修复 ABI 布局问题

安装

npx skills add DetachHead/rebased --skill jna -g -y
更多选项

非标准路径

npx skills add https://github.com/DetachHead/rebased/tree/master/.agents/skills/jna -g -y

不安装直接使用

npx skills use DetachHead/rebased@jna

指定 Agent (Claude Code)

npx skills add DetachHead/rebased --skill jna -a claude-code -g -y

安装 repo 全部 skill

npx skills add DetachHead/rebased --all -g -y

预览 repo 内 skill

npx skills add DetachHead/rebased --list

SKILL.md

Frontmatter
{
    "name": "jna",
    "description": "Implement or debug JNA bindings and ABI layouts in Kotlin or Java."
}

JNA bindings

Treat every mapping as an ABI contract. Verify the native declaration, target architectures, and ownership rules before changing Kotlin or Java code.

Reuse existing mappings

Search JNA Platform and the repository before declaring a native type. Prefer a maintained platform mapping when its field types, alignment, and calling convention match the target API.

Keep reflected types accessible

JNA reflects mapped classes and fields while deriving layouts and invoking callbacks. Make every Structure, Union, callback, and related declaring class JVM-accessible from com.sun.jna:

  • In Kotlin, use internal or public mapped classes; never use private, local, or anonymous mapped classes.
  • Keep the mapped class's enclosing chain accessible too.
  • Expose structure fields as real public JVM fields, normally with @JvmField.
  • Do not assume public fields compensate for a non-public declaring class. Layout can fail with IllegalAccessException from Structure.getFieldValue.

Prefer moving visibility only as far as needed over suppressing reflection errors or opening accessibility globally.

Match the native ABI

  • Declare structure fields in native order and use @Structure.FieldOrder.
  • Map fixed-width integers, pointers, size_t, native booleans, wide strings, and platform-dependent numeric types deliberately. Do not infer their size from Kotlin or Java names.
  • Model embedded values with Structure.ByValue; model pointers separately with Pointer or the appropriate reference type.
  • Check packing and alignment requirements instead of relying on defaults when the native declaration specifies them.
  • Use the correct calling convention and library options.
  • Keep callback objects and native memory strongly reachable for the full native lifetime, and release owned resources according to the native API.
  • For pointer-backed structures, call read() and write() at the required ownership boundary.

Verify without requiring native UI or permissions

Add a small JVM regression test that constructs each mapped structure and calls size() or otherwise forces JNA to derive its layout. Assert stable sizes or offsets only when they are defined for the tested architecture.

Keep permission-, hardware-, and OS-dependent native integration coverage separate. A layout test should catch visibility and field-order failures before a native callback reaches production code.

When debugging, retain the complete cause chain: wrapper errors often hide the useful IllegalAccessException, invalid field type, alignment error, or callback exception underneath.

版本历史

  • 2af32ff 当前 2026-09-22 01:03

同 Skill 集合

.agents/skills/actions/SKILL.md
.agents/skills/bazel-test-migration/SKILL.md
.agents/skills/code-style/SKILL.md
.agents/skills/commits/SKILL.md
.agents/skills/compare-python-typecheckers/SKILL.md
.agents/skills/conda-env-tests/SKILL.md
.agents/skills/debugging/SKILL.md
.agents/skills/driver-ui-tests/SKILL.md
.agents/skills/eel/SKILL.md
.agents/skills/extract-module/SKILL.md
.agents/skills/fix-project-leak-from-tc-report/SKILL.md
.agents/skills/icon-resources/SKILL.md
.agents/skills/icons/SKILL.md
.agents/skills/ide-diagnostics-mcp/SKILL.md
.agents/skills/jewel-markdown/SKILL.md
.agents/skills/jewel-pr-preparer/SKILL.md
.agents/skills/jewel-release-helper/SKILL.md
.agents/skills/kotlin-ui-dsl/SKILL.md
.agents/skills/kotlin-ui-swing-component-architecture/SKILL.md
.agents/skills/module-dependencies/SKILL.md
.agents/skills/module-set-pluginization/SKILL.md
.agents/skills/notebook-for-experiment/SKILL.md
.agents/skills/platform-coroutines-structured-concurrency/SKILL.md
.agents/skills/plugin-model-analyzer/SKILL.md
.agents/skills/poly-context/SKILL.md
.agents/skills/poly-symbols/SKILL.md
.agents/skills/pseudo-kmp/SKILL.md
.agents/skills/registry/SKILL.md
.agents/skills/remote-dev/SKILL.md
.agents/skills/safe-push/SKILL.md
.agents/skills/ssr/SKILL.md
.agents/skills/symbols-api/SKILL.md
.agents/skills/testing-internals/SKILL.md
.agents/skills/testing/SKILL.md
.agents/skills/treehouse/SKILL.md
.agents/skills/ui-accessibility/SKILL.md
.agents/skills/writing-tests/SKILL.md
.agents/skills/youtrack-community/SKILL.md
.claude/skills/actions/SKILL.md
.claude/skills/bazel-test-migration/SKILL.md
.claude/skills/code-style/SKILL.md
.claude/skills/commits/SKILL.md
.claude/skills/compare-python-typecheckers/SKILL.md
.claude/skills/conda-env-tests/SKILL.md
.claude/skills/debugging/SKILL.md
.claude/skills/driver-ui-tests/SKILL.md
.claude/skills/eel/SKILL.md
.claude/skills/extract-module/SKILL.md
.claude/skills/fix-project-leak-from-tc-report/SKILL.md

元信息

文件数
0
版本
2af32ff
Hash
f3e06df5
收录时间
2026-09-22 01:03

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-22 10:54
浙ICP备14020137号-1