@@ -592,7 +592,8 @@ public abstract static class ToJavaNode extends CExtBaseNode {
592
592
@ Child private PCallNativeNode callNativeNode ;
593
593
@ Child private AsPythonObjectNode toJavaNode = AsPythonObjectNode .create ();
594
594
595
- @ CompilationFinal TruffleObject nativeToJavaFunction ;
595
+ @ CompilationFinal private TruffleObject nativeToJavaFunction ;
596
+ @ CompilationFinal private TruffleObject nativePointerToJavaFunction ;
596
597
597
598
public abstract Object execute (Object value );
598
599
@@ -626,25 +627,48 @@ boolean doBoolean(boolean b) {
626
627
return b ;
627
628
}
628
629
630
+ @ Specialization
631
+ Object doInt (int i ) {
632
+ // Unfortunately, an int could be a native pointer and therefore a handle. So, we must
633
+ // try resolving it. At least we know that it's not a native type.
634
+ return native_pointer_to_java (i );
635
+ }
636
+
637
+ @ Specialization
638
+ Object doLong (long l ) {
639
+ // Unfortunately, a long could be a native pointer and therefore a handle. So, we must
640
+ // try resolving it. At least we know that it's not a native type.
641
+ return native_pointer_to_java (l );
642
+ }
643
+
629
644
@ Specialization
630
645
byte doLong (byte b ) {
631
646
return b ;
632
647
}
633
648
634
649
@ Fallback
635
650
Object doForeign (Object value ) {
636
- if (callNativeNode == null ) {
651
+ if (nativeToJavaFunction == null ) {
637
652
CompilerDirectives .transferToInterpreterAndInvalidate ();
638
- callNativeNode = insert ( PCallNativeNode . create () );
653
+ nativeToJavaFunction = importCAPISymbol ( NativeCAPISymbols . FUN_NATIVE_TO_JAVA );
639
654
}
640
- if (callNativeNode == null ) {
655
+ return call_native_conversion (nativeToJavaFunction , value );
656
+ }
657
+
658
+ private Object native_pointer_to_java (Object value ) {
659
+ if (nativePointerToJavaFunction == null ) {
641
660
CompilerDirectives .transferToInterpreterAndInvalidate ();
661
+ nativePointerToJavaFunction = importCAPISymbol (NativeCAPISymbols .FUN_NATIVE_POINTER_TO_JAVA );
642
662
}
643
- if (nativeToJavaFunction == null ) {
663
+ return call_native_conversion (nativePointerToJavaFunction , value );
664
+ }
665
+
666
+ private Object call_native_conversion (TruffleObject target , Object value ) {
667
+ if (callNativeNode == null ) {
644
668
CompilerDirectives .transferToInterpreterAndInvalidate ();
645
- nativeToJavaFunction = importCAPISymbol ( NativeCAPISymbols . FUN_NATIVE_TO_JAVA );
669
+ callNativeNode = insert ( PCallNativeNode . create () );
646
670
}
647
- return toJavaNode .execute (callNativeNode .execute (nativeToJavaFunction , new Object []{value }));
671
+ return toJavaNode .execute (callNativeNode .execute (target , new Object []{value }));
648
672
}
649
673
650
674
public static ToJavaNode create () {
0 commit comments