Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@
import static com.squareup.javapoet.ClassName.get;

public final class ClassNames {
private static final String PKG_TOPLEVEL = "org.javagi";
private static final String PKG_BASE = "org.javagi.base";
private static final String PKG_INTEROP = "org.javagi.interop";
private static final String PKG_GIO = "org.javagi.gio";
private static final String PKG_GOBJECT = "org.javagi.gobject";
private static final String PKG_GOBJECT_TYPES = "org.javagi.gobject.types";
private static final String PKG_GTK_TYPES = "org.javagi.gtk.types";

public static final ClassName CONSTANTS = get(PKG_TOPLEVEL, "Constants");

public static final ClassName ALIAS = get(PKG_BASE, "Alias");
public static final ClassName CONSTANTS = get(PKG_BASE, "Constants");
public static final ClassName ENUMERATION = get(PKG_BASE, "Enumeration");
public static final ClassName FLOATING = get(PKG_BASE, "Floating");
public static final ClassName FUNCTION_POINTER = get(PKG_BASE, "FunctionPointer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,12 @@ private void takeOwnership(MethodSpec.Builder builder) {
// struct, and copy the contents manually
else if (hasMemoryLayout && copyFunc == null) {
var copyVar = v instanceof ReturnValue ? "_copy" : ("_" + getName() + "Copy");
builder.addStatement("$T $L = $T.malloc($T.getMemoryLayout().byteSize())",
MemorySegment.class, copyVar, ClassNames.G_LIB, v.anyType().typeName())
.addStatement("$T.copy($L.handle(), $L)",
ClassNames.INTEROP, paramName, copyVar)
builder.addStatement("long $Lsize = $T.getMemoryLayout().byteSize()",
copyVar, v.anyType().typeName())
.addStatement("$T $L = $T.malloc($Lsize)",
MemorySegment.class, copyVar, ClassNames.G_LIB, copyVar)
.addStatement("$T.copy($L.handle(), $L, $Lsize)",
ClassNames.INTEROP, paramName, copyVar, copyVar)
.addStatement("$L.address = $L", paramName, copyVar);
}

Expand Down
2 changes: 2 additions & 0 deletions modules/main/adw/Adw-1.metadata
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// SplitButton.getDirection() overrides Widget.getDirection()
// with a different return type. Rename to getArrowDirection()
SplitButton.get_direction name=get_arrow_direction
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

package org.javagi;
package org.javagi.base;

/**
* Java-GI global constant definitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.javagi.base;

import org.javagi.Constants;
import org.gnome.glib.GLib;
import org.gnome.glib.LogLevelFlags;

Expand Down
24 changes: 10 additions & 14 deletions modules/main/glib/src/main/java/org/javagi/interop/Interop.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.Arrays;
import java.util.function.Function;

import org.javagi.Constants;
import org.javagi.base.Constants;
import org.javagi.base.Enumeration;
import org.gnome.glib.GLib;

Expand All @@ -38,7 +38,6 @@
import org.javagi.base.Proxy;
import org.jetbrains.annotations.Nullable;

import static java.lang.Long.max;
import static java.lang.foreign.MemorySegment.NULL;
import static java.lang.foreign.ValueLayout.JAVA_BYTE;

Expand All @@ -50,13 +49,13 @@
public class Interop {

private final static int INT_UNBOUNDED = Integer.MAX_VALUE;

private final static long LONG_UNBOUNDED = Long.MAX_VALUE;

private final static boolean LONG_AS_INT = Linker.nativeLinker()
.canonicalLayouts().get("long").equals(ValueLayout.JAVA_INT);

private final static Linker LINKER = Linker.nativeLinker();
private final static Cleaner CLEANER = Cleaner.create();

private static SymbolLookup symbolLookup = LINKER.defaultLookup();

Expand Down Expand Up @@ -155,18 +154,17 @@ public static MethodHandle upcallHandle(MethodHandles.Lookup lookup,
}

/**
* Register a Cleaner that will close the arena when the instance is
* Register a Cleaner action that will close the arena when the instance is
* garbage-collected, coupling the lifetime of the arena to the lifetime of
* the instance.
*
* @param arena a memory arena that can be closed (normally
* {@link Arena#ofConfined()} or {@link Arena#ofAuto()}.
* {@link Arena#ofConfined()} or {@link Arena#ofShared()}.
* @param instance an object
* @return the arena (for method chaining)
*/
public static Arena attachArena(Arena arena, Object instance) {
Cleaner cleaner = Cleaner.create();
cleaner.register(instance, arena::close);
CLEANER.register(instance, arena::close);
return arena;
}

Expand Down Expand Up @@ -202,17 +200,15 @@ public static MemorySegment dereference(MemorySegment pointer) {
}

/**
* First reinterpret the memory segments so they have equal size, then copy
* {@code src} into {@code dst}.
* Reinterpret both memory segments to the specified size and copy
* {@code size} bytes from {@code src} into {@code dst}.
*
* @param src source memory segment
* @param dst destination memory segment
* @param size the number of bytes to copy
*/
public static void copy(MemorySegment src, MemorySegment dst) {
long size = max(src.byteSize(), dst.byteSize());
src.reinterpret(size);
dst.reinterpret(size);
dst.copyFrom(src);
public static void copy(MemorySegment src, MemorySegment dst, long size) {
dst.reinterpret(size).copyFrom(src.reinterpret(size));
}

/**
Expand Down
4 changes: 0 additions & 4 deletions modules/main/glib/src/main/java/org/javagi/package-info.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.gnome.gobject.Closure;
import org.gnome.gobject.Value;

import static org.javagi.Constants.LOG_DOMAIN;
import static org.javagi.base.Constants.LOG_DOMAIN;

/**
* An implementation of {@link Closure} that can be used with Java callbacks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.util.List;
import java.util.function.Consumer;

import static org.javagi.Constants.LOG_DOMAIN;
import static org.javagi.base.Constants.LOG_DOMAIN;

/**
* Helper class to register method overrides in a new GType.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import java.util.*;
import java.util.function.Consumer;

import static org.javagi.Constants.LOG_DOMAIN;
import static org.javagi.base.Constants.LOG_DOMAIN;
import static org.javagi.gobject.annotations.Property.NOT_SET;
import static java.lang.Character.isUpperCase;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import java.util.function.Consumer;
import java.util.function.Function;

import static org.javagi.Constants.LOG_DOMAIN;
import static org.javagi.base.Constants.LOG_DOMAIN;
import static java.util.Objects.requireNonNull;
import static org.gnome.gobject.GObjects.typeTestFlags;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.lang.reflect.Method;
import java.util.Set;

import static org.javagi.Constants.LOG_DOMAIN;
import static org.javagi.base.Constants.LOG_DOMAIN;

/**
* The {@code BuilderJavaScope} class can be used with a {@link GtkBuilder} to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import java.util.function.Consumer;
import java.util.function.Function;

import static org.javagi.Constants.LOG_DOMAIN;
import static org.javagi.base.Constants.LOG_DOMAIN;
import static org.javagi.gobject.types.Types.*;
import static java.util.Objects.requireNonNull;

Expand Down