Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions scripts/TreeSitter_java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@

public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN;
public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE;
@@ -8599,4 +8606,8 @@ public class TreeSitter {
throw new AssertionError("should not reach here", ex$);
}
}
+
+ static {
+ ts_set_allocator(malloc$address(), calloc$address(), realloc$address(), free$address());
+ }
}
4 changes: 4 additions & 0 deletions scripts/jextract.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ $lib = "$($args[0])/core/lib"
--include-struct TSRange `
--include-struct TSTreeCursor `
--include-function free `
--include-function malloc `
--include-function calloc `
--include-function realloc `
--include-function ts_set_allocator `
--include-function ts_language_copy `
--include-function ts_language_delete `
--include-function ts_language_field_count `
Expand Down
4 changes: 4 additions & 0 deletions scripts/jextract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ exec jextract \
--include-struct TSRange \
--include-struct TSTreeCursor \
--include-function free \
--include-function malloc \
--include-function calloc \
--include-function realloc \
--include-function ts_set_allocator \
--include-function ts_language_copy \
--include-function ts_language_delete \
--include-function ts_language_field_count \
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/io/github/treesitter/jtreesitter/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public final class Node {
private final Arena arena = Arena.ofAuto();
private boolean wasEdited = false;

// FIXME: figure out why free() crashes on Windows
private static final boolean IS_UNIX = !System.getProperty("os.name").startsWith("Windows");

Node(MemorySegment self, Tree tree) {
this.self = self;
this.tree = tree;
Expand Down Expand Up @@ -446,7 +443,7 @@ public TreeCursor walk() {
public String toSexp() {
var string = ts_node_string(self);
var result = string.getString(0);
if (IS_UNIX) free(string);
free(string);
return result;
}

Expand Down
7 changes: 2 additions & 5 deletions src/main/java/io/github/treesitter/jtreesitter/Tree.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public final class Tree implements AutoCloseable, Cloneable {
private final Language language;
private @Nullable List<Range> includedRanges;

// FIXME: figure out why free() crashes on Windows
private static final boolean IS_UNIX = !System.getProperty("os.name").startsWith("Windows");

Tree(MemorySegment self, Language language, @Nullable String source, @Nullable Charset charset) {
arena = Arena.ofShared();
this.self = self.reinterpret(arena, TreeSitter::ts_tree_delete);
Expand Down Expand Up @@ -95,7 +92,7 @@ public List<Range> getIncludedRanges() {
var range = TSRange.asSlice(ranges, i);
includedRanges.add(Range.from(range));
}
if (IS_UNIX) free(ranges);
free(ranges);
}
}
return Collections.unmodifiableList(includedRanges);
Expand All @@ -122,7 +119,7 @@ public List<Range> getChangedRanges(Tree newTree) {
var range = TSRange.asSlice(ranges, i);
changedRanges.add(Range.from(range));
}
if (IS_UNIX) free(ranges);
free(ranges);
return changedRanges;
}
}
Expand Down