Skip to content

Commit

Permalink
Rework pointer and array handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jwharm committed Aug 13, 2023
1 parent 4e8407c commit 39797bb
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 5 deletions.
16 changes: 16 additions & 0 deletions glib/main/java/io/github/jwharm/javagi/interop/Interop.java
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,22 @@ public static int[] getIntegerArrayFrom(MemorySegment address, long length, Segm
return array;
}

/**
* Read a null-terminated array of integers from native memory
* @param address address of the memory segment
* @param scope the memory scope
* @param free if the array must be freed
* @return array of integers
*/
public static int[] getIntegerArrayFrom(MemorySegment address, SegmentScope scope, boolean free) {
// Find the null value
long idx = 0;
while (address.get(ValueLayout.JAVA_INT, idx) != 0) {
idx++;
}
return getIntegerArrayFrom(address, idx, scope, free);
}

/**
* Read an array of longs with the given length from native memory
* @param address address of the memory segment
Expand Down
2 changes: 1 addition & 1 deletion src/bld/java/io/github/jwharm/javagi/model/Variable.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private String marshalNativeToJavaArray(Type type, String size, String identifie
return type.qualifiedJavaType + ".fromNativeArray(" + identifier + ", " + free + ")";

if (type.isPrimitive)
return "Interop.get" + Conversions.primitiveClassName(array.type.simpleJavaType) + "ArrayFrom("
return "Interop.get" + Conversions.primitiveClassName(type.simpleJavaType) + "ArrayFrom("
+ identifier + ", " + identifier + ".scope(), " + free + ")";

if (type.girElementInstance instanceof Record && (! type.isPointer()) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public AdwaitaBuild(JavaGIBuild bld) {
.source("cairo-1.0.gir", "org.freedesktop.cairo", null, false, new CairoPatch())
.source("freetype2-2.0.gir", "org.freedesktop.freetype", null, false, null)
.source("HarfBuzz-0.0.gir", "org.freedesktop.harfbuzz", null, false, new HarfBuzzPatch())
.source("Pango-1.0.gir", "org.gnome.pango", "https://docs.gtk.org/Pango/", false, null)
.source("Pango-1.0.gir", "org.gnome.pango", "https://docs.gtk.org/Pango/", false, new PangoPatch())
.source("PangoCairo-1.0.gir", "org.gnome.pango.cairo", "https://docs.gtk.org/Pango/", false, null)
.source("GdkPixbuf-2.0.gir", "org.gnome.gdkpixbuf", "https://docs.gtk.org/gdk-pixbuf/", false, null)
.source("Gdk-4.0.gir", "org.gnome.gdk", "https://docs.gtk.org/gdk4/", false, null)
Expand Down
2 changes: 1 addition & 1 deletion src/bld/java/io/github/jwharm/javagi/modules/GtkBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public GtkBuild(JavaGIBuild bld) {
.source("freetype2-2.0.gir", "org.freedesktop.freetype", null, false, null)

.source("HarfBuzz-0.0.gir", "org.freedesktop.harfbuzz", null, true, new HarfBuzzPatch())
.source("Pango-1.0.gir", "org.gnome.pango", "https://docs.gtk.org/Pango/", true, null)
.source("Pango-1.0.gir", "org.gnome.pango", "https://docs.gtk.org/Pango/", true, new PangoPatch())
.source("PangoCairo-1.0.gir", "org.gnome.pango.cairo", "https://docs.gtk.org/Pango/", true, null)
.source("GdkPixbuf-2.0.gir", "org.gnome.gdkpixbuf", "https://docs.gtk.org/gdk-pixbuf/", true, null)
.source("Gdk-4.0.gir", "org.gnome.gdk", "https://docs.gtk.org/gdk4/", true, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public GtkSourceViewBuild(JavaGIBuild bld) {
.source("cairo-1.0.gir", "org.freedesktop.cairo", null, false, new CairoPatch())
.source("freetype2-2.0.gir", "org.freedesktop.freetype", null, false, null)
.source("HarfBuzz-0.0.gir", "org.freedesktop.harfbuzz", null, false, new HarfBuzzPatch())
.source("Pango-1.0.gir", "org.gnome.pango", "https://docs.gtk.org/Pango/", false, null)
.source("Pango-1.0.gir", "org.gnome.pango", "https://docs.gtk.org/Pango/", false, new PangoPatch())
.source("PangoCairo-1.0.gir", "org.gnome.pango.cairo", "https://docs.gtk.org/Pango/", false, null)
.source("GdkPixbuf-2.0.gir", "org.gnome.gdkpixbuf", "https://docs.gtk.org/gdk-pixbuf/", false, null)
.source("Gdk-4.0.gir", "org.gnome.gdk", "https://docs.gtk.org/gdk4/", false, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public WebKitGtkBuild(JavaGIBuild bld) {
.source("cairo-1.0.gir", "org.freedesktop.cairo", null, false, new CairoPatch())
.source("freetype2-2.0.gir", "org.freedesktop.freetype", null, false, null)
.source("HarfBuzz-0.0.gir", "org.freedesktop.harfbuzz", null, false, new HarfBuzzPatch())
.source("Pango-1.0.gir", "org.gnome.pango", "https://docs.gtk.org/Pango/", false, null)
.source("Pango-1.0.gir", "org.gnome.pango", "https://docs.gtk.org/Pango/", false, new PangoPatch())
.source("PangoCairo-1.0.gir", "org.gnome.pango.cairo", "https://docs.gtk.org/Pango/", false, null)
.source("GdkPixbuf-2.0.gir", "org.gnome.gdkpixbuf", "https://docs.gtk.org/gdk-pixbuf/", false, null)
.source("Gdk-4.0.gir", "org.gnome.gdk", "https://docs.gtk.org/gdk4/", false, null)
Expand Down
14 changes: 14 additions & 0 deletions src/bld/java/io/github/jwharm/javagi/patches/PangoPatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.jwharm.javagi.patches;

import io.github.jwharm.javagi.generator.Patch;
import io.github.jwharm.javagi.model.Repository;

public class PangoPatch implements Patch {

@Override
public void patch(Repository repo) {
// Return type defined as "Language" but should be "Language*"
removeMethod(repo, "Font", "get_languages");
}

}

0 comments on commit 39797bb

Please sign in to comment.