Passing same buffer as two method arguments does not read back modified content
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia dal percorso della chiamata JNA per l’entry point do_something(ByteBuffer out, ByteBuffer in) e dalla gestione degli argomenti ByteBuffer supportati dall’heap. Riproduci la chiamata passando lo stesso buffer per entrambi i parametri con JNA 5.5.0, quindi verifica che l’output modificato rimanga visibile dopo il ritorno della funzione nativa.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Java
- Stelle
- 8.9k
- Fork
- 1.7k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di java-native-access/jna
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 66/100
java-native-access/jna#1738 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
java-native-access/jna#1736 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
java-native-access/jna#1717 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
java-native-access/jna#1700 · 11 commenti ·
-
feature request
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
java-native-access/jna#1698 · 1 commento ·
Tutte le issue di java-native-access/jna
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
bug needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 94/100
objectionary/hone-maven-plugin#1061 ·
-
type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100