Skip to content

Commit

Permalink
Do not avoid copying array content for const ** arrays. Do that for `…
Browse files Browse the repository at this point in the history
…* const`s.

This fixes bytedeco#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.
  • Loading branch information
atsushieno committed Sep 2, 2024
1 parent 2fd35c6 commit 7b8944a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/bytedeco/javacpp/tools/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 7b8944a

Please sign in to comment.