98
98
import com .oracle .graal .python .builtins .objects .type .ManagedPythonClass ;
99
99
import com .oracle .graal .python .builtins .objects .type .PythonBuiltinClass ;
100
100
import com .oracle .graal .python .builtins .objects .type .PythonClass ;
101
+ import com .oracle .graal .python .builtins .objects .type .TypeBuiltins ;
101
102
import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
102
103
import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetMroNode ;
103
104
import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetNameNode ;
108
109
import com .oracle .graal .python .nodes .PNodeWithContext ;
109
110
import com .oracle .graal .python .nodes .SpecialAttributeNames ;
110
111
import com .oracle .graal .python .nodes .SpecialMethodNames ;
112
+ import com .oracle .graal .python .nodes .attributes .GetAttributeNode .GetFixedAttributeNode ;
111
113
import com .oracle .graal .python .nodes .attributes .LookupAttributeInMRONode ;
112
114
import com .oracle .graal .python .nodes .attributes .ReadAttributeFromObjectNode ;
113
115
import com .oracle .graal .python .nodes .attributes .WriteAttributeToObjectNode ;
@@ -501,14 +503,14 @@ Object doTpHash(ManagedPythonClass object, @SuppressWarnings("unused") String ke
501
503
502
504
@ Specialization (guards = "eq(TP_BASICSIZE, key)" )
503
505
Object doTpBasicsize (ManagedPythonClass object , @ SuppressWarnings ("unused" ) String key ,
504
- @ Cached ("create(__BASICSIZE__)" ) LookupAttributeInMRONode getAttrNode ) {
505
- return getAttrNode .execute (object );
506
+ @ Cached ("create(__BASICSIZE__)" ) GetFixedAttributeNode getAttrNode ) {
507
+ return getAttrNode .executeObject (object );
506
508
}
507
509
508
510
@ Specialization (guards = "eq(TP_ITEMSIZE, key)" )
509
511
Object doTpItemsize (ManagedPythonClass object , @ SuppressWarnings ("unused" ) String key ,
510
- @ Cached ("create(__ITEMSIZE__)" ) LookupAttributeInMRONode getAttrNode ) {
511
- Object val = getAttrNode .execute (object );
512
+ @ Cached ("create(__ITEMSIZE__)" ) GetFixedAttributeNode getAttrNode ) {
513
+ Object val = getAttrNode .executeObject (object );
512
514
// If the attribute does not exist, this means that we take 'tp_itemsize' from the base
513
515
// object which is by default 0 (see typeobject.c:PyBaseObject_Type).
514
516
if (val == PNone .NO_VALUE ) {
@@ -520,12 +522,12 @@ Object doTpItemsize(ManagedPythonClass object, @SuppressWarnings("unused") Strin
520
522
@ Specialization (guards = "eq(TP_DICTOFFSET, key)" )
521
523
Object doTpDictoffset (ManagedPythonClass object , @ SuppressWarnings ("unused" ) String key ,
522
524
@ Cached ("create()" ) CastToIndexNode castToIntNode ,
523
- @ Cached ("create(__DICTOFFSET__)" ) LookupAttributeInMRONode getAttrNode ) {
525
+ @ Cached ("create(__DICTOFFSET__)" ) GetFixedAttributeNode getAttrNode ) {
524
526
// TODO properly implement 'tp_dictoffset' for builtin classes
525
527
if (object instanceof PythonBuiltinClass ) {
526
528
return 0L ;
527
529
}
528
- Object dictoffset = getAttrNode .execute (object );
530
+ Object dictoffset = getAttrNode .executeObject (object );
529
531
return castToIntNode .execute (dictoffset );
530
532
}
531
533
@@ -876,7 +878,7 @@ public Object access(PythonNativeWrapper object, String key, Object value) {
876
878
}
877
879
}
878
880
879
- @ ImportStatic ({NativeMemberNames .class , PGuards .class , SpecialMethodNames .class })
881
+ @ ImportStatic ({NativeMemberNames .class , PGuards .class , SpecialMethodNames .class , SpecialAttributeNames . class })
880
882
abstract static class WriteNativeMemberNode extends PNodeWithContext {
881
883
@ Child private HashingStorageNodes .SetItemNode setItemNode ;
882
884
@@ -896,20 +898,14 @@ long doTpFlags(ManagedPythonClass object, @SuppressWarnings("unused") String key
896
898
}
897
899
898
900
@ Specialization (guards = "eq(TP_BASICSIZE, key)" )
899
- @ TruffleBoundary
900
- long doTpBasicsize (PythonBuiltinClass object , @ SuppressWarnings ("unused" ) String key , long basicsize ) {
901
- // We have to use the 'setAttributeUnsafe' because this properly cannot be modified by
902
- // the user and we need to initialize it.
903
- object .setAttributeUnsafe (SpecialAttributeNames .__BASICSIZE__ , basicsize );
904
- return basicsize ;
905
- }
906
-
907
- @ Specialization (guards = "eq(TP_BASICSIZE, key)" )
908
- @ TruffleBoundary
909
- long doTpBasicsize (PythonClass object , @ SuppressWarnings ("unused" ) String key , long basicsize ) {
910
- // Do deliberately not use "SetAttributeNode" because we want to directly set the
911
- // attribute an bypass any user code.
912
- object .setAttribute (SpecialAttributeNames .__BASICSIZE__ , basicsize );
901
+ long doTpBasicsize (AbstractPythonClass object , @ SuppressWarnings ("unused" ) String key , long basicsize ,
902
+ @ Cached ("create()" ) WriteAttributeToObjectNode writeAttrNode ,
903
+ @ Cached ("create()" ) IsBuiltinClassProfile profile ) {
904
+ if (profile .profileClass (object , PythonBuiltinClassType .PythonClass )) {
905
+ writeAttrNode .execute (object , TypeBuiltins .TYPE_BASICSIZE , basicsize );
906
+ } else {
907
+ writeAttrNode .execute (object , SpecialAttributeNames .__BASICSIZE__ , basicsize );
908
+ }
913
909
return basicsize ;
914
910
}
915
911
0 commit comments