Skip to content

Commit

Permalink
GList and GSList have their own cleaners; do not register them with t…
Browse files Browse the repository at this point in the history
…he MemoryCleaner
  • Loading branch information
jwharm committed Aug 1, 2024
1 parent 6f76239 commit 189d362
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ else if (!returnValue.anyType().isVoid()) {
}

// Add cleaner to struct/union pointer
else if (((target instanceof Record record && !record.foreign())
else if (((target instanceof Record record
&& !record.foreign()
&& !record.checkIsGList())
|| target instanceof Boxed
|| target instanceof Union)
&& returnValue.transferOwnership() != TransferOwnership.NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ PartialStatement marshalNativeToJava(Type type,
"$" + targetTypeTag + ":T.of(" + identifier + ")",
targetTypeTag, target.typeName());

if (type.isGList() && target != null) {
if (type.checkIsGList() && target != null) {
if (type.anyTypes() == null || type.anyTypes().size() > 1)
throw new UnsupportedOperationException("Unsupported element type: " + type);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import io.github.jwharm.javagi.configuration.ClassNames;
import io.github.jwharm.javagi.util.PartialStatement;

import java.util.List;

import static io.github.jwharm.javagi.util.Conversions.toJavaQualifiedType;
import static io.github.jwharm.javagi.util.Conversions.uncapitalize;

Expand Down Expand Up @@ -61,6 +63,7 @@ default PartialStatement destructorName() {
return PartialStatement.of("$glib:T::free", "glib", ClassNames.GLIB);
}

/** Return true if this class is GObject or is derived from GObject */
default boolean checkIsGObject() {
return switch(this) {
case Class c -> c.isInstanceOf("GObject", "Object");
Expand All @@ -73,6 +76,11 @@ default boolean checkIsGObject() {
};
}

/** Return true if this is GList or GSList */
default boolean checkIsGList() {
return cType() != null && List.of("GList", "GSList").contains(cType());
}

default boolean isFloating() {
// GObject has a ref_sink function, but we don't want to treat all
// GObjects as floating references.
Expand Down
12 changes: 6 additions & 6 deletions buildSrc/src/main/java/io/github/jwharm/javagi/gir/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public List<AnyType> anyTypes() {

@Override
public TypeName typeName() {
if (isGList())
if (checkIsGList())
return glistTypeName();

String javaBaseType = toJavaBaseType(name());
Expand Down Expand Up @@ -117,11 +117,6 @@ public boolean isLong() {
return "glong".equals(cType) || "gulong".equals(cType);
}

public boolean isGList() {
return name() != null
&& List.of("GLib.List", "GLib.SList").contains(name());
}

public boolean isPointer() {
String cType = cType();
return cType != null
Expand All @@ -145,6 +140,11 @@ public boolean checkIsGObject() {
return target != null && target.checkIsGObject();
}

public boolean checkIsGList() {
RegisteredType target = get();
return target != null && target.checkIsGList();
}

public boolean isActuallyAnArray() {
return cType() != null && cType().endsWith("**")
&& (! (parent() instanceof Parameter p && p.isOutParameter()));
Expand Down

0 comments on commit 189d362

Please sign in to comment.