Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias: Misinterpretation of gchar** as String Instead of a List of Strings in Generated Bindings #154

Closed
leinardi opened this issue Nov 20, 2024 · 0 comments · Fixed by #158

Comments

@leinardi
Copy link

The generated Strv class incorrectly interprets gchar** (a pointer to an array of strings) as an alias for a single String. This misinterpretation can lead to incorrect data handling, as gchar** should be represented as a list or array of strings, not as a single string.


Generated Class:

/**
 * A typedef alias for gchar**. This is mostly useful when used together with
 * {@code g_auto()}.
 */
@Generated("io.github.jwharm.JavaGI")
public class Strv extends Alias<String> {
    /**
     * Create a new Strv with the provided value
     */
    public Strv(String value) {
        super(value);
    }

    public static Strv[] fromNativeArray(MemorySegment address, long length, boolean free) {
        Strv[] array = new Strv[(int) length];
        long byteSize = ValueLayout.ADDRESS.byteSize();
        MemorySegment segment = address.reinterpret(byteSize * length);
        for (int i = 0; i < length; i++) {
            array[i] = new Strv(Interop.getStringFrom(segment.get(ValueLayout.ADDRESS, i * byteSize), free));
        }
        if (free) GLib.free(address);
        return array;
    }
}
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 a pull request may close this issue.

1 participant