Skip to content

Commit

Permalink
Use boolean type for gboolean in helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
lopcode committed Aug 20, 2024
1 parent b2664cb commit ec5f3ac
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,24 @@ To get set up to run samples (on macOS):
* Run `VipsFfm` in IntelliJ to run samples and validations

```
[main] INFO vipsffm.VipsFfm - clearing sample run directory at path "sample_run"
[main] INFO vipsffm.VipsFfm - running sample "RawGetVersionSample"...
[main] INFO vipsffm.SampleRunner - clearing sample run directory at path "sample_run"
[main] INFO vipsffm.SampleRunner - running sample "RawGetVersionSample"...
[main] INFO vipsffm.RawGetVersionSample - libvips version: "8.15.2"
[main] INFO vipsffm.VipsFfm - validation succeeded ✅
[main] INFO vipsffm.VipsFfm - running sample "HelperGetVersionSample"...
[main] INFO vipsffm.SampleRunner - validation succeeded ✅
[main] INFO vipsffm.SampleRunner - running sample "HelperGetVersionSample"...
[main] INFO vipsffm.HelperGetVersionSample - libvips version: "8.15.2"
[main] INFO vipsffm.VipsFfm - validation succeeded ✅
[main] INFO vipsffm.VipsFfm - running sample "RawCreateThumbnailSample"...
[main] INFO vipsffm.SampleRunner - validation succeeded ✅
[main] INFO vipsffm.SampleRunner - running sample "RawCreateThumbnailSample"...
[main] INFO vipsffm.RawGetVersionSample - source image size: 2490 x 3084
[main] INFO vipsffm.RawGetVersionSample - output image size: 323 x 400
[main] INFO vipsffm.VipsFfm - validation succeeded ✅
[main] INFO vipsffm.VipsFfm - running sample "HelperCreateThumbnailSample"...
[main] INFO vipsffm.SampleRunner - validation succeeded ✅
[main] INFO vipsffm.SampleRunner - running sample "HelperCreateThumbnailSample"...
[main] INFO vipsffm.RawGetVersionSample - source image size: 2490 x 3084
[main] INFO vipsffm.RawGetVersionSample - thumbnail image size: 323 x 400
[main] INFO vipsffm.VipsFfm - validation succeeded ✅
[main] INFO vipsffm.VipsFfm - all samples ran successfully 🎉
[main] INFO vipsffm.SampleRunner - validation succeeded ✅
[main] INFO vipsffm.SampleRunner - shutting down vips to check for memory leaks...
memory: high-water mark 36.55 MB
[main] INFO vipsffm.SampleRunner - all samples ran successfully 🎉
```

### Thumbnail sample
Expand Down
21 changes: 14 additions & 7 deletions helper-generator/src/main/kotlin/vipsffm/GenerateHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,18 @@ object GenerateHelpers {
vipsFunctionArgs.removeLast()
vipsFunctionArgs += ParameterSpec.builder(vipsOptionArrayType, "invokerArgs").build()
}
val vipsFunctionArgsJoined = vipsFunctionArgs.joinToString {
if (it.type == stringType) {
it.name.removeSuffix("String")
} else if (it.name == "out") {
"${it.name}Pointer"
val vipsFunctionArgsJoined = vipsFunctionArgs.mapIndexed { index, parameterSpec ->
val externArgMetadata = externMetadata.arguments.getOrNull(index)
if (parameterSpec.type == stringType) {
parameterSpec.name.removeSuffix("String")
} else if (parameterSpec.name == "out") {
"${parameterSpec.name}Pointer"
} else if (externArgMetadata?.type == "gboolean" && externArgMetadata.pointerDepth == 0) {
parameterSpec.name.removeSuffix("Boolean")
} else {
it.name
parameterSpec.name
}
}
}.joinToString()

var returnPoetType = defaultReturnPoetType
val methodBuilder = MethodSpec.methodBuilder(newName)
Expand All @@ -168,6 +171,8 @@ object GenerateHelpers {
val externArgMetadata = externMetadata.arguments[index]
if (externArgMetadata.name == "out") {
methodBuilder.addStatement("var outPointer = out.pointerOrNull\$\$internal()")
} else if(externArgMetadata.type == "gboolean" && parameter.type == TypeName.BOOLEAN) {
methodBuilder.addStatement("var ${parameter.name.removeSuffix("Boolean")} = ${parameter.name} ? 1 : 0")
} else if (externArgMetadata.pointerDepth == 1) {
if (parameter.type == stringType) {
val newName = parameter.name.removeSuffix("String")
Expand Down Expand Up @@ -282,6 +287,8 @@ object GenerateHelpers {
externArgMetadata.pointerDepth == 1
) {
ParameterSpec.builder(stringType, "${externArgMetadata.name}String").build()
} else if (externArgMetadata.type == "gboolean" && externArgMetadata.pointerDepth == 0) {
ParameterSpec.builder(TypeName.BOOLEAN, "${externArgMetadata.name}Boolean").build()
} else {
val typeName = classDescToPoetType(parameter, parameter.displayName())
ParameterSpec.builder(typeName, externArgMetadata.name).build()
Expand Down
6 changes: 4 additions & 2 deletions helper/src/main/java/app/photofox/vipsffm/generated/Vips.java
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,8 @@ public void addOptionEntries(MemorySegment option_group) throws VipsError {
* void vips_leak_set(gboolean leak)
* }
*/
public void leakSet(int leak) throws VipsError {
public void leakSet(boolean leakBoolean) throws VipsError {
var leak = leakBoolean ? 1 : 0;
VipsRaw.vips_leak_set(leak);
}

Expand All @@ -739,7 +740,8 @@ public void leakSet(int leak) throws VipsError {
* void vips_block_untrusted_set(gboolean state)
* }
*/
public void blockUntrustedSet(int state) throws VipsError {
public void blockUntrustedSet(boolean stateBoolean) throws VipsError {
var state = stateBoolean ? 1 : 0;
VipsRaw.vips_block_untrusted_set(state);
}

Expand Down
4 changes: 2 additions & 2 deletions sample/src/main/kotlin/vipsffm/SampleRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlin.system.exitProcess

object SampleRunner {

val logger = LoggerFactory.getLogger(SampleRunner::class.java)
private val logger = LoggerFactory.getLogger(SampleRunner::class.java)

@JvmStatic
fun main(args: Array<String>) {
Expand All @@ -31,7 +31,7 @@ object SampleRunner {

Arena.ofConfined().use { arena ->
val vips = Vips(arena)
vips.leakSet(1)
vips.leakSet(true)

samples.forEach { sample ->
val sampleName = sample::class.simpleName!!
Expand Down

0 comments on commit ec5f3ac

Please sign in to comment.