138
138
import com .oracle .graal .python .nodes .expression .ExpressionNode ;
139
139
import com .oracle .graal .python .nodes .frame .GetCurrentFrameRef ;
140
140
import com .oracle .graal .python .nodes .object .GetClassNode ;
141
- import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
141
+ import com .oracle .graal .python .nodes .object .IsForeignObjectNode ;
142
142
import com .oracle .graal .python .nodes .truffle .PythonTypes ;
143
143
import com .oracle .graal .python .nodes .util .CannotCastException ;
144
144
import com .oracle .graal .python .nodes .util .CastToJavaLongLossyNode ;
@@ -500,15 +500,16 @@ static Object runAbstractObject(@SuppressWarnings("unused") CExtContext cextCont
500
500
return PythonObjectNativeWrapper .wrap (object , noWrapperProfile );
501
501
}
502
502
503
- @ Specialization (guards = {"lib.isForeignObject (object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" })
503
+ @ Specialization (guards = {"isForeignObjectNode.execute (object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" })
504
504
static Object doForeignObject (@ SuppressWarnings ("unused" ) CExtContext cextContext , TruffleObject object ,
505
- @ SuppressWarnings ("unused" ) @ CachedLibrary ( limit = "3" ) PythonObjectLibrary lib ) {
505
+ @ SuppressWarnings ("unused" ) @ Cached IsForeignObjectNode isForeignObjectNode ) {
506
506
return TruffleObjectNativeWrapper .wrap (object );
507
507
}
508
508
509
- @ Specialization (guards = "isFallback(object, lib )" )
509
+ @ Specialization (guards = "isFallback(object, isForeignObjectNode )" )
510
510
static Object run (@ SuppressWarnings ("unused" ) CExtContext cextContext , Object object ,
511
- @ SuppressWarnings ("unused" ) @ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ) {
511
+ @ SuppressWarnings ("unused" ) @ Cached IsForeignObjectNode isForeignObjectNode ,
512
+ @ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ) {
512
513
assert object != null : "Java 'null' cannot be a Sulong value" ;
513
514
Object o = lib .getDelegatedValue (object );
514
515
assert CApiGuards .isNativeWrapper (o ) : "unknown object cannot be a Sulong value" ;
@@ -523,10 +524,10 @@ protected static PythonClassNativeWrapper wrapNativeClass(PythonContext ctx, Pyt
523
524
return PythonClassNativeWrapper .wrap (ctx .getCore ().lookupType (object ), GetNameNode .doSlowPath (object ));
524
525
}
525
526
526
- static boolean isFallback (Object object , PythonObjectLibrary lib ) {
527
+ static boolean isFallback (Object object , IsForeignObjectNode isForeignObjectNode ) {
527
528
return !(object instanceof String || object instanceof Boolean || object instanceof Integer || object instanceof Long || object instanceof Double ||
528
529
object instanceof PythonBuiltinClassType || object instanceof PythonNativeNull || object == DescriptorDeleteMarker .INSTANCE ||
529
- object instanceof PythonAbstractObject ) && !(lib . isForeignObject (object ) && !CApiGuards .isNativeWrapper (object ));
530
+ object instanceof PythonAbstractObject ) && !(isForeignObjectNode . execute (object ) && !CApiGuards .isNativeWrapper (object ));
530
531
}
531
532
532
533
protected static boolean isNaN (double d ) {
@@ -757,17 +758,18 @@ static Object runAbstractObject(@SuppressWarnings("unused") CExtContext cextCont
757
758
return PythonObjectNativeWrapper .wrapNewRef (object , noWrapperProfile );
758
759
}
759
760
760
- @ Specialization (guards = {"lib.isForeignObject (object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" })
761
+ @ Specialization (guards = {"isForeignObjectNode.execute (object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" })
761
762
static Object doForeignObject (CExtContext cextContext , TruffleObject object ,
762
- @ CachedLibrary ( limit = "3" ) PythonObjectLibrary lib ) {
763
+ @ Cached IsForeignObjectNode isForeignObjectNode ) {
763
764
// this will always be a new wrapper; it's implicitly always a new reference in any case
764
- return ToSulongNode .doForeignObject (cextContext , object , lib );
765
+ return ToSulongNode .doForeignObject (cextContext , object , isForeignObjectNode );
765
766
}
766
767
767
- @ Specialization (guards = "isFallback(object, lib )" )
768
+ @ Specialization (guards = "isFallback(object, isForeignObjectNode )" )
768
769
static Object run (CExtContext cextContext , Object object ,
770
+ @ Cached IsForeignObjectNode isForeignObjectNode ,
769
771
@ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ) {
770
- return ToSulongNode .run (cextContext , object , lib );
772
+ return ToSulongNode .run (cextContext , object , isForeignObjectNode , lib );
771
773
}
772
774
773
775
protected static PythonClassNativeWrapper wrapNativeClass (PythonManagedClass object ) {
@@ -778,8 +780,8 @@ protected static PythonClassNativeWrapper wrapNativeClass(PythonContext ctx, Pyt
778
780
return PythonClassNativeWrapper .wrap (ctx .getCore ().lookupType (object ), GetNameNode .doSlowPath (object ));
779
781
}
780
782
781
- static boolean isFallback (Object object , PythonObjectLibrary lib ) {
782
- return ToSulongNode .isFallback (object , lib );
783
+ static boolean isFallback (Object object , IsForeignObjectNode isForeignObjectNode ) {
784
+ return ToSulongNode .isFallback (object , isForeignObjectNode );
783
785
}
784
786
785
787
protected static boolean isNaN (double d ) {
@@ -940,17 +942,18 @@ static Object runAbstractObject(@SuppressWarnings("unused") CExtContext cextCont
940
942
return PythonObjectNativeWrapper .wrapNewRef (object , noWrapperProfile );
941
943
}
942
944
943
- @ Specialization (guards = {"lib.isForeignObject (object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" })
945
+ @ Specialization (guards = {"isForeignObjectNode.execute (object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" })
944
946
static Object doForeignObject (CExtContext cextContext , TruffleObject object ,
945
- @ CachedLibrary ( limit = "3" ) PythonObjectLibrary lib ) {
947
+ @ Cached IsForeignObjectNode isForeignObjectNode ) {
946
948
// this will always be a new wrapper; it's implicitly always a new reference in any case
947
- return ToSulongNode .doForeignObject (cextContext , object , lib );
949
+ return ToSulongNode .doForeignObject (cextContext , object , isForeignObjectNode );
948
950
}
949
951
950
- @ Specialization (guards = "isFallback(object, lib )" )
952
+ @ Specialization (guards = "isFallback(object, isForeignObjectNode )" )
951
953
static Object run (CExtContext cextContext , Object object ,
954
+ @ Cached IsForeignObjectNode isForeignObjectNode ,
952
955
@ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ) {
953
- return ToSulongNode .run (cextContext , object , lib );
956
+ return ToSulongNode .run (cextContext , object , isForeignObjectNode , lib );
954
957
}
955
958
956
959
protected static PythonClassNativeWrapper wrapNativeClass (PythonManagedClass object ) {
@@ -961,8 +964,8 @@ protected static PythonClassNativeWrapper wrapNativeClass(PythonContext ctx, Pyt
961
964
return PythonClassNativeWrapper .wrap (ctx .getCore ().lookupType (object ), GetNameNode .doSlowPath (object ));
962
965
}
963
966
964
- static boolean isFallback (Object object , PythonObjectLibrary lib ) {
965
- return ToSulongNode .isFallback (object , lib );
967
+ static boolean isFallback (Object object , IsForeignObjectNode isForeignObjectNode ) {
968
+ return ToSulongNode .isFallback (object , isForeignObjectNode );
966
969
}
967
970
968
971
protected static boolean isNaN (double d ) {
@@ -1063,15 +1066,14 @@ static double doDouble(@SuppressWarnings("unused") CExtContext cextContext, doub
1063
1066
return d ;
1064
1067
}
1065
1068
1066
- @ Specialization (guards = "isFallback(obj, lib )" , limit = "3 " )
1069
+ @ Specialization (guards = "isFallback(obj, isForeignObjectNode )" , limit = "1 " )
1067
1070
static Object run (@ SuppressWarnings ("unused" ) CExtContext cextContext , Object obj ,
1068
- @ SuppressWarnings ("unused" ) @ CachedLibrary ("obj" ) PythonObjectLibrary lib ,
1069
- @ Cached @ SuppressWarnings ("unused" ) IsBuiltinClassProfile isForeignClassProfile ,
1071
+ @ SuppressWarnings ("unused" ) @ Cached IsForeignObjectNode isForeignObjectNode ,
1070
1072
@ Cached PRaiseNode raiseNode ) {
1071
1073
throw raiseNode .raise (PythonErrorType .SystemError , ErrorMessages .INVALID_OBJ_FROM_NATIVE , obj );
1072
1074
}
1073
1075
1074
- protected static boolean isFallback (Object obj , PythonObjectLibrary lib ) {
1076
+ protected static boolean isFallback (Object obj , IsForeignObjectNode isForeignObjectNode ) {
1075
1077
if (CApiGuards .isNativeWrapper (obj )) {
1076
1078
return false ;
1077
1079
}
@@ -1084,7 +1086,7 @@ protected static boolean isFallback(Object obj, PythonObjectLibrary lib) {
1084
1086
if (PGuards .isAnyPythonObject (obj )) {
1085
1087
return false ;
1086
1088
}
1087
- if (lib . isForeignObject (obj )) {
1089
+ if (isForeignObjectNode . execute (obj )) {
1088
1090
return false ;
1089
1091
}
1090
1092
if (PGuards .isString (obj )) {
@@ -1118,10 +1120,9 @@ protected static boolean isPrimitiveNativeWrapper(PythonNativeWrapper object) {
1118
1120
@ ImportStatic ({PGuards .class , CApiGuards .class })
1119
1121
public abstract static class AsPythonObjectNode extends AsPythonObjectBaseNode {
1120
1122
1121
- @ Specialization (guards = {"plib.isForeignObject (object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" }, limit = "2" )
1123
+ @ Specialization (guards = {"isForeignObjectNode.execute (object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" }, limit = "2" )
1122
1124
static PythonAbstractObject doNativeObject (@ SuppressWarnings ("unused" ) CExtContext cextContext , TruffleObject object ,
1123
- @ SuppressWarnings ("unused" ) @ CachedLibrary ("object" ) PythonObjectLibrary plib ,
1124
- @ Cached @ SuppressWarnings ("unused" ) IsBuiltinClassProfile isForeignClassProfile ,
1125
+ @ SuppressWarnings ("unused" ) @ Cached IsForeignObjectNode isForeignObjectNode ,
1125
1126
@ CachedContext (PythonLanguage .class ) PythonContext context ,
1126
1127
@ Cached ConditionProfile newRefProfile ,
1127
1128
@ Cached ConditionProfile validRefProfile ,
@@ -1146,10 +1147,9 @@ static PythonAbstractObject doNativeObject(@SuppressWarnings("unused") CExtConte
1146
1147
@ ImportStatic ({PGuards .class , CApiGuards .class })
1147
1148
public abstract static class AsPythonObjectStealingNode extends AsPythonObjectBaseNode {
1148
1149
1149
- @ Specialization (guards = {"plib.isForeignObject (object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" }, limit = "1" )
1150
+ @ Specialization (guards = {"isForeignObjectNode.execute (object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" }, limit = "1" )
1150
1151
static PythonAbstractObject doNativeObject (@ SuppressWarnings ("unused" ) CExtContext cextContext , TruffleObject object ,
1151
- @ SuppressWarnings ("unused" ) @ CachedLibrary ("object" ) PythonObjectLibrary plib ,
1152
- @ Cached @ SuppressWarnings ("unused" ) IsBuiltinClassProfile isForeignClassProfile ,
1152
+ @ SuppressWarnings ("unused" ) @ Cached IsForeignObjectNode isForeignObjectNode ,
1153
1153
@ Cached ConditionProfile newRefProfile ,
1154
1154
@ Cached ConditionProfile validRefProfile ,
1155
1155
@ Cached ConditionProfile resurrectProfile ,
@@ -1173,10 +1173,9 @@ static PythonAbstractObject doNativeObject(@SuppressWarnings("unused") CExtConte
1173
1173
@ ImportStatic ({PGuards .class , CApiGuards .class })
1174
1174
public abstract static class WrapVoidPtrNode extends AsPythonObjectBaseNode {
1175
1175
1176
- @ Specialization (guards = {"plib.isForeignObject (object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" }, limit = "1" )
1176
+ @ Specialization (guards = {"isForeignObjectNode.execute (object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" }, limit = "1" )
1177
1177
static Object doNativeObject (@ SuppressWarnings ("unused" ) CExtContext cextContext , TruffleObject object ,
1178
- @ SuppressWarnings ("unused" ) @ CachedLibrary ("object" ) PythonObjectLibrary plib ,
1179
- @ Cached @ SuppressWarnings ("unused" ) IsBuiltinClassProfile isForeignClassProfile ) {
1178
+ @ SuppressWarnings ("unused" ) @ Cached IsForeignObjectNode isForeignObjectNode ) {
1180
1179
// TODO(fa): should we use a different wrapper for non-'PyObject*' pointers; they cannot
1181
1180
// be used in the user value space but might be passed-through
1182
1181
@@ -1190,10 +1189,9 @@ static Object doNativeObject(@SuppressWarnings("unused") CExtContext cextContext
1190
1189
@ ImportStatic ({PGuards .class , CApiGuards .class })
1191
1190
public abstract static class WrapCharPtrNode extends AsPythonObjectBaseNode {
1192
1191
1193
- @ Specialization (guards = {"plib.isForeignObject (object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" }, limit = "1" )
1192
+ @ Specialization (guards = {"isForeignObjectNode.execute (object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" }, limit = "1" )
1194
1193
static Object doNativeObject (@ SuppressWarnings ("unused" ) CExtContext cextContext , TruffleObject object ,
1195
- @ SuppressWarnings ("unused" ) @ CachedLibrary ("object" ) PythonObjectLibrary plib ,
1196
- @ Cached @ SuppressWarnings ("unused" ) IsBuiltinClassProfile isForeignClassProfile ,
1194
+ @ SuppressWarnings ("unused" ) @ Cached IsForeignObjectNode isForeignObjectNode ,
1197
1195
@ Cached FromCharPointerNode fromCharPointerNode ) {
1198
1196
return fromCharPointerNode .execute (object );
1199
1197
}
0 commit comments