-
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.
Add an output pointer helper, reconcile method generators (#24)
- Loading branch information
Showing
10 changed files
with
2,560 additions
and
972 deletions.
There are no files selected for viewing
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
41 changes: 41 additions & 0 deletions
41
core/src/main/java/app/photofox/vipsffm/helper/VipsOutputPointer.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,41 @@ | ||
package app.photofox.vipsffm.helper; | ||
|
||
import java.lang.foreign.Arena; | ||
import java.lang.foreign.MemorySegment; | ||
import java.lang.foreign.ValueLayout; | ||
|
||
// models output pointers in vips functions (eg VipsImage **out) | ||
public class VipsOutputPointer { | ||
|
||
private final MemorySegment outPointer; | ||
private MemorySegment dereferencedPointer; | ||
|
||
public VipsOutputPointer(Arena arena) { | ||
this.outPointer = arena.allocate(ValueLayout.ADDRESS); | ||
} | ||
|
||
// internal - do not use | ||
public MemorySegment pointerOrNull$internal() { | ||
return this.outPointer; | ||
} | ||
|
||
// internal - do not use | ||
public void setReinterpretedPointer$internal(MemorySegment reinterpretedPointer) { | ||
this.dereferencedPointer = reinterpretedPointer; | ||
} | ||
|
||
public MemorySegment dereferencedOrNull() { | ||
if (!VipsValidation.isValidPointer(this.dereferencedPointer)) { | ||
return null; | ||
} | ||
return this.dereferencedPointer; | ||
} | ||
|
||
public MemorySegment dereferencedOrThrow() throws VipsError { | ||
var dereferencedPointer = this.dereferencedOrNull(); | ||
if (dereferencedPointer == null) { | ||
throw new VipsError("dereferenced output pointer unexpectedly null"); | ||
} | ||
return dereferencedPointer; | ||
} | ||
} |
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
Oops, something went wrong.