-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
307 changed files
with
78,279 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[workspace] | ||
members = [ | ||
"feature", | ||
"cli", | ||
"jextrsact" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mkdir feature/tmp | ||
cargo run -p diplomat-java -- -e feature/src/lib.rs -l feature/diplomat-java-conf.toml feature/tmp/ | ||
mv feature/tmp/* feature/java/somelib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "diplomat-feature-tests" | ||
version = "0.0.0" | ||
publish = false | ||
authors = [ | ||
"Jan Cristina <[email protected]>", | ||
"Manish Goregaokar <[email protected]>", | ||
] | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["staticlib", "rlib", "cdylib"] | ||
|
||
[dependencies] | ||
diplomat-runtime = { git = "https://github.com/jcrist1/diplomat", branch = "tool-and-c-backend-pub", package = "diplomat-runtime"} | ||
diplomat = { git = "https://github.com/jcrist1/diplomat", branch = "tool-and-c-backend-pub", package = "diplomat" } | ||
log = { version = "0.4" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
domain = "dev.diplomattest" | ||
lib_name = "somelib" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
.idea/encodings.xml | ||
.idea/misc.xml | ||
.idea/vcs.xml | ||
.idea/codeStyles | ||
.idea/** | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store | ||
|
||
libsomelib.dylib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>dev.diplomattest.somelib</groupId> | ||
<artifactId>somelib</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>22</maven.compiler.source> | ||
<maven.compiler.target>22</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>net.java.dev.jna</groupId> | ||
<artifactId>jna</artifactId> | ||
<version>5.14.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<version>5.10.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openjdk.jmh</groupId> | ||
<artifactId>jmh-core</artifactId> | ||
<version>1.37</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openjdk.jmh</groupId> | ||
<artifactId>jmh-generator-annprocess</artifactId> | ||
<version>1.37</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.surefire</groupId> | ||
<artifactId>surefire-junit47</artifactId> | ||
<version>3.5.0</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>3.5.0</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
28 changes: 28 additions & 0 deletions
28
feature/java/somelib/src/jmh/java/dev/diplomattest/somelib/OpaqueBench.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.diplomattest.somelib; | ||
|
||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
public class OpaqueBench { | ||
@Benchmark | ||
public static void benchOpaque(Blackhole bh) { | ||
var opaque = Opaque.fromStr("it's amazing to be here"); | ||
bh.consume(opaque); | ||
// opaque.destroy(); | ||
} | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
Options opt = new OptionsBuilder() | ||
.include(OpaqueBench.class.getSimpleName()) | ||
.warmupIterations(2) | ||
.measurementIterations(2) | ||
.forks(1) | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
feature/java/somelib/src/main/java/dev/diplomattest/somelib/Bar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package dev.diplomattest.somelib; | ||
|
||
import dev.diplomattest.somelib.ntv.*; | ||
|
||
|
||
import java.lang.foreign.Arena; | ||
import java.lang.foreign.MemorySegment; | ||
import java.lang.foreign.SegmentAllocator; | ||
import java.lang.ref.Cleaner; | ||
import java.util.List; | ||
import static java.lang.foreign.ValueLayout.*; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.stream.Stream; | ||
|
||
public class Bar { | ||
|
||
MemorySegment internal; | ||
Cleaner.Cleanable cleanable; | ||
SegmentAllocator arena; | ||
|
||
List<Object> selfEdges = List.of(); | ||
List<Object> bEdges = List.of(); | ||
List<Object> aEdges = List.of(); | ||
|
||
|
||
static class BarCleaner implements Runnable { | ||
|
||
MemorySegment segment; | ||
BarCleaner(MemorySegment segment) { | ||
this.segment = segment; | ||
} | ||
|
||
public void run() { | ||
somelib_h.Bar_destroy(this.segment); | ||
} | ||
} | ||
|
||
Bar() {} | ||
Bar(MemorySegment handle, List<Object> selfEdges, List<Object> bEdges, List<Object> aEdges) { | ||
this.internal = handle; | ||
this.selfEdges = selfEdges; | ||
this.bEdges = bEdges; | ||
this.aEdges = aEdges; | ||
|
||
|
||
} | ||
|
||
|
||
public Foo foo() { | ||
|
||
|
||
var nativeVal = somelib_h.Bar_foo(internal); | ||
|
||
List<Object> selfEdges = List.of(this); | ||
|
||
|
||
|
||
List<Object> aEdges = List.of(this); | ||
var returnVal = new Foo(nativeVal, selfEdges, aEdges); | ||
return returnVal; | ||
|
||
} | ||
|
||
} |
96 changes: 96 additions & 0 deletions
96
feature/java/somelib/src/main/java/dev/diplomattest/somelib/BorrowedFields.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package dev.diplomattest.somelib; | ||
|
||
import dev.diplomattest.somelib.ntv.*; | ||
|
||
import java.lang.foreign.Arena; | ||
import java.lang.foreign.MemorySegment; | ||
import java.lang.ref.Cleaner; | ||
import java.lang.foreign.SegmentAllocator; | ||
import java.util.List; | ||
import static java.lang.foreign.ValueLayout.*; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.stream.Stream; | ||
|
||
public class BorrowedFields { | ||
String a; | ||
String b; | ||
String c; | ||
|
||
|
||
List<Object> selfEdges = List.of(); | ||
List<Object> aEdges = List.of(); | ||
|
||
|
||
private BorrowedFields() { | ||
} | ||
|
||
BorrowedFields(MemorySegment structSegment, List<Object> aEdges) { | ||
this.selfEdges = selfEdges; | ||
this.aEdges = aEdges; | ||
|
||
|
||
var aNative = dev.diplomattest.somelib.ntv.BorrowedFields.a(structSegment); | ||
var aVal = SliceUtils.readUtf16(aNative); | ||
this.a = aVal; | ||
var bNative = dev.diplomattest.somelib.ntv.BorrowedFields.b(structSegment); | ||
var bVal = SliceUtils.readUtf8(bNative); | ||
this.b = bVal; | ||
var cNative = dev.diplomattest.somelib.ntv.BorrowedFields.c(structSegment); | ||
var cVal = SliceUtils.readUtf8(cNative); | ||
this.c = cVal; | ||
|
||
|
||
} | ||
|
||
MemorySegment toNative(SegmentAllocator arena) { | ||
var returnVal = dev.diplomattest.somelib.ntv.BorrowedFields.allocate(arena); | ||
|
||
var aData = arena.allocateFrom(a, StandardCharsets.UTF_16); | ||
var aLen = aData.byteSize() - 1; // allocated strings are null terminated | ||
var aView = DiplomatString16View.allocate(arena); | ||
DiplomatString16View.len(aView, aLen); | ||
DiplomatString16View.data(aView, aData); | ||
dev.diplomattest.somelib.ntv.BorrowedFields.a(returnVal, aView); | ||
var bData= arena.allocateFrom(b, StandardCharsets.UTF_8); | ||
var bLen = bData.byteSize() - 1; // allocated strings are null terminated | ||
var bView = DiplomatStringView.allocate(arena); | ||
DiplomatStringView.len(bView, bLen); | ||
DiplomatStringView.data(bView, bData); | ||
dev.diplomattest.somelib.ntv.BorrowedFields.b(returnVal, bView); | ||
var cData= arena.allocateFrom(c, StandardCharsets.UTF_8); | ||
var cLen = cData.byteSize() - 1; // allocated strings are null terminated | ||
var cView = DiplomatStringView.allocate(arena); | ||
DiplomatStringView.len(cView, cLen); | ||
DiplomatStringView.data(cView, cData); | ||
dev.diplomattest.somelib.ntv.BorrowedFields.c(returnVal, cView); | ||
|
||
|
||
return returnVal; | ||
|
||
} | ||
|
||
public static BorrowedFields fromBarAndStrings(Bar bar,String dstr16,String utf8Str) { | ||
|
||
try (var arena = Arena.ofConfined()) { | ||
|
||
var barNative = bar.internal; | ||
var dstr16Data = Arena.ofAuto().allocateFrom(dstr16, StandardCharsets.UTF_16); | ||
var dstr16Len = dstr16Data.byteSize() - 1; // allocated strings are null terminated | ||
var dstr16View = DiplomatString16View.allocate(Arena.ofAuto()); | ||
DiplomatString16View.len(dstr16View, dstr16Len); | ||
DiplomatString16View.data(dstr16View, dstr16Data); | ||
var utf8StrData= Arena.ofAuto().allocateFrom(utf8Str, StandardCharsets.UTF_8); | ||
var utf8StrLen = utf8StrData.byteSize() - 1; // allocated strings are null terminated | ||
var utf8StrView = DiplomatStringView.allocate(Arena.ofAuto()); | ||
DiplomatStringView.len(utf8StrView, utf8StrLen); | ||
DiplomatStringView.data(utf8StrView, utf8StrData); | ||
var nativeVal = somelib_h.BorrowedFields_from_bar_and_strings(arena, barNative, dstr16View, utf8StrView); | ||
|
||
var returnVal = new BorrowedFields(nativeVal, List.of(bar, dstr16, utf8Str)); | ||
return returnVal; | ||
|
||
} | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.