Skip to content

Commit 35e456c

Browse files
committed
Initial Commit
Squashed of all existing changes for upload. wip wip Update gradle fix error wip tests Update bindings Use requireNonNull and custom bound checking.
0 parents  commit 35e456c

58 files changed

Lines changed: 9797 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.gradle
2+
build/
3+
!gradle/wrapper/gradle-wrapper.jar
4+
!**/src/main/**/build/
5+
!**/src/test/**/build/
6+
.kotlin
7+
8+
### IntelliJ IDEA ###
9+
.idea/
10+
*.iws
11+
*.iml
12+
*.ipr
13+
out/
14+
!**/src/main/**/out/
15+
!**/src/test/**/out/
16+
17+
### Eclipse ###
18+
.apt_generated
19+
.classpath
20+
.factorypath
21+
.project
22+
.settings
23+
.springBeans
24+
.sts4-cache
25+
bin/
26+
!**/src/main/**/bin/
27+
!**/src/test/**/bin/
28+
29+
### NetBeans ###
30+
/nbproject/private/
31+
/nbbuild/
32+
/dist/
33+
/nbdist/
34+
/.nb-gradle/
35+
36+
### VS Code ###
37+
.vscode/
38+
39+
### Mac OS ###
40+
.DS_Store

bindings/build.gradle.kts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
plugins {
2+
id("java-library")
3+
id("de.infolektuell.jextract") version "1.3.0"
4+
}
5+
6+
group = "dev.hallock.zstd"
7+
version = "0.1-SNAPSHOT"
8+
9+
repositories {
10+
mavenCentral()
11+
}
12+
13+
java {
14+
toolchain.languageVersion.set(JavaLanguageVersion.of(25))
15+
modularity.inferModulePath.set(true)
16+
}
17+
18+
dependencies {
19+
api("org.jspecify:jspecify:1.0.0")
20+
}
21+
22+
jextract.libraries {
23+
val zstd by registering {
24+
header = project.file("src/c/header.h")
25+
useSystemLoadLibrary = true
26+
//libraries.add("zstd")
27+
28+
targetPackage = "dev.hallock.zstd.bindings"
29+
headerClassName = "ZSTD_h"
30+
output = project.file("src/main/java")
31+
}
32+
// Don't use a lazy addLater, we don't want to declare it in a SourceSet
33+
jextract.libraries.add(zstd.get())
34+
}

bindings/src/c/header.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include <zstd.h>
2+
#include <zdict.h>
3+
#include <zstd_errors.h>
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
// Generated by jextract
2+
3+
package dev.hallock.zstd.bindings;
4+
5+
import java.lang.invoke.*;
6+
import java.lang.foreign.*;
7+
import java.nio.ByteOrder;
8+
import java.util.*;
9+
import java.util.function.*;
10+
import java.util.stream.*;
11+
12+
import static java.lang.foreign.ValueLayout.*;
13+
import static java.lang.foreign.MemoryLayout.PathElement.*;
14+
15+
/**
16+
* {@snippet lang=c :
17+
* struct {
18+
* int compressionLevel;
19+
* unsigned int notificationLevel;
20+
* unsigned int dictID;
21+
* }
22+
* }
23+
*/
24+
public class ZDICT_params_t {
25+
26+
ZDICT_params_t() {
27+
// Should not be called directly
28+
}
29+
30+
private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
31+
ZSTD_h.C_INT.withName("compressionLevel"),
32+
ZSTD_h.C_INT.withName("notificationLevel"),
33+
ZSTD_h.C_INT.withName("dictID")
34+
).withName("$anon$214:9");
35+
36+
/**
37+
* The layout of this struct
38+
*/
39+
public static final GroupLayout layout() {
40+
return $LAYOUT;
41+
}
42+
43+
private static final OfInt compressionLevel$LAYOUT = (OfInt)$LAYOUT.select(groupElement("compressionLevel"));
44+
45+
/**
46+
* Layout for field:
47+
* {@snippet lang=c :
48+
* int compressionLevel
49+
* }
50+
*/
51+
public static final OfInt compressionLevel$layout() {
52+
return compressionLevel$LAYOUT;
53+
}
54+
55+
private static final long compressionLevel$OFFSET = $LAYOUT.byteOffset(groupElement("compressionLevel"));
56+
57+
/**
58+
* Offset for field:
59+
* {@snippet lang=c :
60+
* int compressionLevel
61+
* }
62+
*/
63+
public static final long compressionLevel$offset() {
64+
return compressionLevel$OFFSET;
65+
}
66+
67+
/**
68+
* Getter for field:
69+
* {@snippet lang=c :
70+
* int compressionLevel
71+
* }
72+
*/
73+
public static int compressionLevel(MemorySegment struct) {
74+
return struct.get(compressionLevel$LAYOUT, compressionLevel$OFFSET);
75+
}
76+
77+
/**
78+
* Setter for field:
79+
* {@snippet lang=c :
80+
* int compressionLevel
81+
* }
82+
*/
83+
public static void compressionLevel(MemorySegment struct, int fieldValue) {
84+
struct.set(compressionLevel$LAYOUT, compressionLevel$OFFSET, fieldValue);
85+
}
86+
87+
private static final OfInt notificationLevel$LAYOUT = (OfInt)$LAYOUT.select(groupElement("notificationLevel"));
88+
89+
/**
90+
* Layout for field:
91+
* {@snippet lang=c :
92+
* unsigned int notificationLevel
93+
* }
94+
*/
95+
public static final OfInt notificationLevel$layout() {
96+
return notificationLevel$LAYOUT;
97+
}
98+
99+
private static final long notificationLevel$OFFSET = $LAYOUT.byteOffset(groupElement("notificationLevel"));
100+
101+
/**
102+
* Offset for field:
103+
* {@snippet lang=c :
104+
* unsigned int notificationLevel
105+
* }
106+
*/
107+
public static final long notificationLevel$offset() {
108+
return notificationLevel$OFFSET;
109+
}
110+
111+
/**
112+
* Getter for field:
113+
* {@snippet lang=c :
114+
* unsigned int notificationLevel
115+
* }
116+
*/
117+
public static int notificationLevel(MemorySegment struct) {
118+
return struct.get(notificationLevel$LAYOUT, notificationLevel$OFFSET);
119+
}
120+
121+
/**
122+
* Setter for field:
123+
* {@snippet lang=c :
124+
* unsigned int notificationLevel
125+
* }
126+
*/
127+
public static void notificationLevel(MemorySegment struct, int fieldValue) {
128+
struct.set(notificationLevel$LAYOUT, notificationLevel$OFFSET, fieldValue);
129+
}
130+
131+
private static final OfInt dictID$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dictID"));
132+
133+
/**
134+
* Layout for field:
135+
* {@snippet lang=c :
136+
* unsigned int dictID
137+
* }
138+
*/
139+
public static final OfInt dictID$layout() {
140+
return dictID$LAYOUT;
141+
}
142+
143+
private static final long dictID$OFFSET = $LAYOUT.byteOffset(groupElement("dictID"));
144+
145+
/**
146+
* Offset for field:
147+
* {@snippet lang=c :
148+
* unsigned int dictID
149+
* }
150+
*/
151+
public static final long dictID$offset() {
152+
return dictID$OFFSET;
153+
}
154+
155+
/**
156+
* Getter for field:
157+
* {@snippet lang=c :
158+
* unsigned int dictID
159+
* }
160+
*/
161+
public static int dictID(MemorySegment struct) {
162+
return struct.get(dictID$LAYOUT, dictID$OFFSET);
163+
}
164+
165+
/**
166+
* Setter for field:
167+
* {@snippet lang=c :
168+
* unsigned int dictID
169+
* }
170+
*/
171+
public static void dictID(MemorySegment struct, int fieldValue) {
172+
struct.set(dictID$LAYOUT, dictID$OFFSET, fieldValue);
173+
}
174+
175+
/**
176+
* Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
177+
* The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
178+
*/
179+
public static MemorySegment asSlice(MemorySegment array, long index) {
180+
return array.asSlice(layout().byteSize() * index);
181+
}
182+
183+
/**
184+
* The size (in bytes) of this struct
185+
*/
186+
public static long sizeof() { return layout().byteSize(); }
187+
188+
/**
189+
* Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
190+
*/
191+
public static MemorySegment allocate(SegmentAllocator allocator) {
192+
return allocator.allocate(layout());
193+
}
194+
195+
/**
196+
* Allocate an array of size {@code elementCount} using {@code allocator}.
197+
* The returned segment has size {@code elementCount * layout().byteSize()}.
198+
*/
199+
public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
200+
return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
201+
}
202+
203+
/**
204+
* Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
205+
* The returned segment has size {@code layout().byteSize()}
206+
*/
207+
public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer<MemorySegment> cleanup) {
208+
return reinterpret(addr, 1, arena, cleanup);
209+
}
210+
211+
/**
212+
* Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
213+
* The returned segment has size {@code elementCount * layout().byteSize()}
214+
*/
215+
public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer<MemorySegment> cleanup) {
216+
return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
217+
}
218+
}
219+

0 commit comments

Comments
 (0)