Skip to content

Commit 3feb62d

Browse files
committed
* Let Generator use the third element of @Cast(value) on return values passed to adapters (issue tensorflow/java#345)
1 parent 7f70eb9 commit 3feb62d

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
* Let `Generator` use the third element of `@Cast(value)` on return values passed to adapters ([issue tensorflow/java#345](https://github.com/tensorflow/java/issues/345))
23
* Prevent `Generator` from swallowing exceptions caught on `Buffer.array()` ([pull #504](https://github.com/bytedeco/javacpp/pull/504))
34
* Add `enum` classes missing from config files required by GraalVM Native Image
45
* Let `Parser` annotate `&&` parameters with new `@ByRef(true)` value used by `Generator` to call `std::move()`

src/main/java/org/bytedeco/javacpp/annotation/Cast.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Indicates a type cast required on the argument to satisfy the native compiler.
1212
* When used with {@link Adapter} a second cast can also be specified making it
1313
* possible to apply a cast to both the argument and the adapter, in this order.
14+
* A third "precast" can also be specified, which gets applied before the second one.
1415
* <p>
1516
* At the moment, {@link Generator} makes use of the simple C-style cast. If one
1617
* requires a different kind of type conversion, such as the {@code dynamic_cast}
@@ -25,4 +26,4 @@
2526
@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE})
2627
public @interface Cast {
2728
String[] value();
28-
}
29+
}

src/main/java/org/bytedeco/javacpp/tools/Generator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2394,7 +2394,11 @@ String returnBefore(MethodInformation methodInfo) {
23942394

23952395
if (adapterInfo != null) {
23962396
usesAdapters = true;
2397-
returnPrefix = adapterInfo.name + " radapter(";
2397+
String cast2 = adapterInfo.cast2.trim();
2398+
if (cast2.length() > 0 && !cast2.startsWith("(") && !cast2.endsWith(")")) {
2399+
cast2 = "(" + cast2 + ")";
2400+
}
2401+
returnPrefix = adapterInfo.name + " radapter(" + cast2;
23982402
}
23992403
}
24002404
}

0 commit comments

Comments
 (0)