Skip to content

Commit 85d71d7

Browse files
committed
Merge branch 'topic/free_usage_in_java' into 'master'
Correct the 'free' usage in the Java bindings to avoid errors on Windows Closes AdaCore#648 See merge request eng/libadalang/langkit!832
2 parents ccf8711 + 412e99b commit 85d71d7

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

langkit/templates/java_api/jni_impl_c.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,7 @@ ${api.jni_func_sig("unit_filename", "jstring")}(
21612161
jstring res = to_j_string(env, res_native);
21622162

21632163
// Free the native allocated string
2164-
free((void *) res_native);
2164+
${nat("free")}((void *) res_native);
21652165

21662166
// Return the result
21672167
return res;

langkit/templates/java_api/main_class.mako

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,11 +2632,11 @@ public class ${ctx.lib_name.camel} {
26322632
PointerWrapper reference;
26332633

26342634
if(ImageInfo.inImageCode()) {
2635-
CCharPointer charsetNative =
2635+
final CCharPointer charsetNative =
26362636
charset == null ?
26372637
WordFactory.nullPointer() :
26382638
toCString(charset);
2639-
AnalysisContextNative resNative =
2639+
final AnalysisContextNative resNative =
26402640
NI_LIB.${nat("allocate_analysis_context")}();
26412641

26422642
NI_LIB.${nat("initialize_analysis_context")}(
@@ -3060,7 +3060,7 @@ public class ${ctx.lib_name.camel} {
30603060
this.reference.ni()
30613061
);
30623062
absoluteFile = toJString(resNative);
3063-
UnmanagedMemory.free(resNative);
3063+
NI_LIB.${nat("free")}(resNative);
30643064
} else {
30653065
absoluteFile = JNI_LIB.${nat("unit_filename")}(this);
30663066
}

langkit/templates/java_api/ni_lib.mako

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,15 @@
309309
310310
${exts.include_extension(ctx.ext("java_api", "ni_funcs"))}
311311
312+
// ----- Util functions -----
313+
314+
/** Util function to free langkit side allocated memory */
315+
@CompilerDirectives.TruffleBoundary
316+
@CFunction
317+
public static native void ${nat("free")}(
318+
PointerBase pointer
319+
);
320+
312321
// ----- Exception functions -----
313322
314323
/** Get the last exception raised by langkit */

0 commit comments

Comments
 (0)