Skip to content

Free owned char* returns in the generated MEOS facade#21

Open
estebanzimanyi wants to merge 1 commit into
MobilityDB:mainfrom
estebanzimanyi:fix/free-owned-char-main
Open

Free owned char* returns in the generated MEOS facade#21
estebanzimanyi wants to merge 1 commit into
MobilityDB:mainfrom
estebanzimanyi:fix/free-owned-char-main

Conversation

@estebanzimanyi
Copy link
Copy Markdown
Member

MEOS functions that return a non-const char* (temporal_out, the *_out / *_as_hexwkb / _as_hexewkb family) transfer ownership of the allocation to the caller. Binding such a return as a JNR-FFI String copies the C string into a Java String and leaves the original native allocation unreferenced, so it accumulates on the native heap across repeated calls. The generator binds these returns as Pointer in the part interface; the public wrapper copies the string with getString(0), releases the allocation through sun.misc.Unsafe.freeMemory (the system free, avoiding JNR-FFI classloader-boundary issues), and returns the Java String. const char returns (temporal_interp, temporal_subtype, geo_typename) are borrowed and remain String. The regenerated GeneratedFunctions facade and a unit test for the owned-vs-const classifier travel in the same commit.

MEOS functions that return a non-const char* (temporal_out, the *_out /
*_as_hexwkb / *_as_hexewkb family) transfer ownership of the allocation
to the caller. Binding such a return as a JNR-FFI String copies the C
string into a Java String and leaves the original native allocation
unreferenced, so it accumulates on the native heap across repeated calls.
The generator binds these returns as Pointer in the part interface; the
public wrapper copies the string with getString(0), releases the
allocation through sun.misc.Unsafe.freeMemory (the system free, avoiding
JNR-FFI classloader-boundary issues), and returns the Java String. const
char* returns (temporal_interp, temporal_subtype, geo_typename) are
borrowed and remain String.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant