Passing same buffer as two method arguments does not read back modified content
まだ誰も着手していません。
評価
調査の方向性
エントリポイント do_something(ByteBuffer out, ByteBuffer in) に対する JNA の呼び出し経路と、ヒープによりバッキングされた ByteBuffer 引数の処理から始めます。JNA 5.5.0 で同じバッファを両方のパラメータに渡して呼び出しを再現し、ネイティブ関数から戻った後も変更された出力が可視であることを確認します。
索引モデルが issue の本文から書いたものです。
説明
Assume the following native library function, which reads from in and writes to out:
int do_something(void *out, void *in);
mapped to the following interface in Jave:
public interface mylibrary extends Library {
public int do_something(ByteBuffer out, ByteBuffer in);
}
When calling this function with the same buffer backed by a heap-allocated array as both output and input argument, i.e.:
public void process(ByteBuf buffer) {
// buffer is backed by heap-allocated array
mylibraryInstance.do_something(buffer, buffer);
}
then the buffer will not be updated to reflect the content that was written to out within the native function implementation.
I assume this is because each argument will be processed individually, the buffer will be copied two times into native memory, both instances will be read back after the function call and the second argument (in, unmodified) replaces the first argument (out, modified & expected content).
Workaround: Create a new buffer before calling the native function (and write it back afterwards):
public void process(ByteBuf buffer) {
ByteBuffer outputBuffer = ByteBuffer.allocate(buffer.remaining());
outputBuffer.limit(buffer.remaining());
mylibraryInstance.do_something(outputBuffer, buffer);
// here, outputBuffer has the expected (modified) content - write back to original buffer
}
Version of JNA and related jars: jna 5.5.0 and jna-platform 5.5.0
Version and vendor of the java virtual machine: Oracle JDK 12.0.2
- 主要言語
- Java
- スター
- 8.9k
- フォーク
- 1.7k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
java-native-access/jna のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
java-native-access/jna#1740 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 66/100
java-native-access/jna#1738 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
java-native-access/jna#1736 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
java-native-access/jna#1717 ·
-
Windows32Exception - The parameter is incorrect再び着手できるかも @marktech0813 が 331 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
java-native-access/jna#1700 · コメント 11 件 ·
java-native-access/jna の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
NationalSecurityAgency/ghidra#9748 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
spring-mcp-tools
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
explyt/spring-plugin#591 ·
メンテナーはふだん 1 日以内に返信
-
waiting-for-triage
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
spring-cloud/spring-cloud-openfeign#1443 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 84/100
ADORSYS-GIS/keycloak-oid4vp-plugin#221 ·
メンテナーはふだん 2 日以内に返信