From 7b8944a87b32aef103c22274f1612dfe0cdedf0e Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Mon, 2 Sep 2024 14:52:55 +0800 Subject: [PATCH] Do not avoid copying array content for const ** arrays. Do that for `* const`s. This fixes https://github.com/bytedeco/javacpp/issues/776 Before this change, we did not copy array contents back to the argument array for "const **" as it is regarded as immutable. But it in fact it mutable. This StackOverflow question describes it well. https://stackoverflow.com/questions/4949254/const-char-const-versus-const-char After this change, it will avoid copying if the parameter pointer itself is const. --- src/main/java/org/bytedeco/javacpp/tools/Generator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/bytedeco/javacpp/tools/Generator.java b/src/main/java/org/bytedeco/javacpp/tools/Generator.java index e703ca31..c9ca9184 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/Generator.java +++ b/src/main/java/org/bytedeco/javacpp/tools/Generator.java @@ -3031,7 +3031,7 @@ void parametersAfter(MethodInformation methodInfo) { // If const array, then use JNI_ABORT to avoid copying unmodified data back to JVM final String releaseArrayFlag; - if (cast.contains(" const *") || cast.startsWith("(const ")) { + if (cast.contains("* const") || cast.endsWith("const)")) { releaseArrayFlag = "JNI_ABORT"; } else { releaseArrayFlag = "0";