78
78
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
79
79
import com .oracle .graal .python .builtins .modules .BuiltinFunctions ;
80
80
import com .oracle .graal .python .builtins .modules .MathGuards ;
81
+ import com .oracle .graal .python .builtins .modules .WarningsModuleBuiltins .WarnNode ;
81
82
import com .oracle .graal .python .builtins .objects .bytes .PBytes ;
82
83
import com .oracle .graal .python .builtins .objects .cext .capi .CApiGuards ;
83
84
import com .oracle .graal .python .builtins .objects .cext .capi .DynamicObjectNativeWrapper ;
@@ -238,7 +239,7 @@ public void writeMember(String key, Object value,
238
239
@ Exclusive @ Cached KeyForAttributeAccess getAttributeKey ,
239
240
@ Exclusive @ Cached KeyForItemAccess getItemKey ,
240
241
@ Cached PInteropSetAttributeNode writeNode ,
241
- @ Exclusive @ Cached IsBuiltinClassProfile attrErrorProfile ) throws UnsupportedMessageException , UnknownIdentifierException {
242
+ @ Shared ( "attributeErrorProfile" ) @ Cached IsBuiltinClassProfile attrErrorProfile ) throws UnsupportedMessageException , UnknownIdentifierException {
242
243
try {
243
244
String attrKey = getAttributeKey .execute (key );
244
245
if (attrKey != null ) {
@@ -490,7 +491,7 @@ public Object invokeMember(String member, Object[] arguments,
490
491
@ Exclusive @ Cached PExecuteNode executeNode ,
491
492
@ Exclusive @ Cached ConditionProfile profileGetattribute ,
492
493
@ Exclusive @ Cached ConditionProfile profileMember ,
493
- @ Exclusive @ Cached IsBuiltinClassProfile attributeErrorProfile ) throws UnknownIdentifierException , UnsupportedMessageException {
494
+ @ Shared ( "attributeErrorProfile" ) @ Cached IsBuiltinClassProfile attributeErrorProfile ) throws UnknownIdentifierException , UnsupportedMessageException {
494
495
Object memberObj ;
495
496
try {
496
497
Object attrGetattribute = lookupGetattributeNode .execute (this , __GETATTRIBUTE__ );
@@ -569,7 +570,7 @@ public void removeMember(String member,
569
570
@ Exclusive @ Cached LookupInheritedAttributeNode .Dynamic getDelItemNode ,
570
571
@ Cached PInteropDeleteAttributeNode deleteAttributeNode ,
571
572
@ Exclusive @ Cached PInteropDeleteItemNode delItemNode ,
572
- @ Exclusive @ Cached IsBuiltinClassProfile attrErrorProfile ) throws UnsupportedMessageException , UnknownIdentifierException {
573
+ @ Shared ( "attributeErrorProfile" ) @ Cached IsBuiltinClassProfile attrErrorProfile ) throws UnsupportedMessageException , UnknownIdentifierException {
573
574
try {
574
575
String attrKey = getAttributeKey .execute (member );
575
576
if (attrKey != null ) {
@@ -825,7 +826,10 @@ public Object asIndexWithState(ThreadState state,
825
826
@ Shared ("raise" ) @ Cached PRaiseNode raise ,
826
827
@ Shared ("isSubtypeNode" ) @ Cached IsSubtypeNode isSubtype ,
827
828
@ Exclusive @ Cached ConditionProfile noIndex ,
828
- @ Exclusive @ Cached ConditionProfile resultProfile ) {
829
+ @ Exclusive @ Cached ConditionProfile resultProfile ,
830
+ @ Shared ("gotState" ) @ Cached ConditionProfile gotState ,
831
+ @ Shared ("intProfile" ) @ Cached IsBuiltinClassProfile isInt ,
832
+ @ Cached WarnNode warnNode ) {
829
833
// n.b.: the CPython shortcut "if (PyLong_Check(item)) return item;" is
830
834
// implemented in the specific Java classes PInt, PythonNativeVoidPtr,
831
835
// and PythonAbstractNativeObject and dispatched polymorphically
@@ -835,10 +839,18 @@ public Object asIndexWithState(ThreadState state,
835
839
}
836
840
837
841
Object result = methodLib .callUnboundMethodWithState (indexMethod , state , this );
838
-
839
842
if (resultProfile .profile (!isSubtype .execute (resultLib .getLazyPythonClass (result ), PythonBuiltinClassType .PInt ))) {
840
843
throw raise .raise (PythonBuiltinClassType .TypeError , ErrorMessages .INDEX_RETURNED_NON_INT , result );
841
844
}
845
+ if (!isInt .profileObject (result , PythonBuiltinClassType .PInt )){
846
+ VirtualFrame frame = null ;
847
+ if (gotState .profile (state != null )) {
848
+ frame = PArguments .frameForCall (state );
849
+ }
850
+ warnNode .warnFormat (frame , null , PythonBuiltinClassType .DeprecationWarning , 1 ,
851
+ ErrorMessages .P_RETURNED_NON_P ,
852
+ this , "__index__" , "int" , result , "int" );
853
+ }
842
854
return result ;
843
855
}
844
856
@@ -884,10 +896,9 @@ public static Object asPString(PythonObjectLibrary lib, Object receiver, ThreadS
884
896
public int asFileDescriptorWithState (ThreadState state ,
885
897
@ CachedLibrary ("this" ) PythonObjectLibrary lib ,
886
898
@ Shared ("methodLib" ) @ CachedLibrary (limit = "2" ) PythonObjectLibrary methodLib ,
887
- @ CachedLibrary (limit = "1" ) PythonObjectLibrary libResult ,
888
899
@ Shared ("raise" ) @ Cached PRaiseNode raiseNode ,
889
900
@ Exclusive @ Cached BranchProfile noFilenoMethodProfile ,
890
- @ Exclusive @ Cached IsBuiltinClassProfile isIntProfile ,
901
+ @ Shared ( "intProfile" ) @ Cached IsBuiltinClassProfile isIntProfile ,
891
902
@ Exclusive @ Cached CastToJavaIntExactNode castToJavaIntNode ,
892
903
@ Exclusive @ Cached IsBuiltinClassProfile isAttrError ) {
893
904
@@ -898,7 +909,7 @@ public int asFileDescriptorWithState(ThreadState state,
898
909
}
899
910
900
911
Object result = methodLib .callObjectWithState (filenoFunc , state );
901
- if (isIntProfile .profileClass ( libResult . getLazyPythonClass ( result ) , PythonBuiltinClassType .PInt )) {
912
+ if (isIntProfile .profileObject ( result , PythonBuiltinClassType .PInt )) {
902
913
try {
903
914
return castToJavaIntNode .execute (result );
904
915
} catch (PException e ) {
0 commit comments