41
41
package com .oracle .graal .python .builtins .objects .cext .capi ;
42
42
43
43
import static com .oracle .graal .python .builtins .objects .PNone .NO_VALUE ;
44
+ import static com .oracle .graal .python .builtins .objects .cext .capi .NativeCAPISymbol .FUN_NO_OP_CLEAR ;
44
45
import static com .oracle .graal .python .builtins .objects .cext .capi .NativeCAPISymbol .FUN_PTR_ADD ;
45
46
import static com .oracle .graal .python .builtins .objects .cext .capi .NativeCAPISymbol .FUN_PTR_COMPARE ;
46
47
import static com .oracle .graal .python .builtins .objects .cext .capi .NativeCAPISymbol .FUN_PY_DEALLOC ;
136
137
import com .oracle .graal .python .builtins .objects .type .PythonBuiltinClass ;
137
138
import com .oracle .graal .python .builtins .objects .type .PythonClass ;
138
139
import com .oracle .graal .python .builtins .objects .type .PythonManagedClass ;
140
+ import com .oracle .graal .python .builtins .objects .type .TypeFlags ;
139
141
import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
140
142
import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetBaseClassNode ;
141
143
import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetMroStorageNode ;
@@ -890,19 +892,24 @@ public static PCallCapiFunction getUncached() {
890
892
*/
891
893
@ TruffleBoundary
892
894
public static Object lookupNativeMemberInMRO (PythonManagedClass cls , @ SuppressWarnings ("unused" ) CFields nativeMemberName , HiddenAttr managedMemberName ) {
893
- if (cls instanceof PythonClass && (managedMemberName == HiddenAttr .ALLOC || managedMemberName == HiddenAttr .FREE )) {
894
- Object func = HiddenAttr .ReadNode .executeUncached (cls , managedMemberName , null );
895
- if (func != null ) {
896
- return func ;
897
- }
895
+ if (cls instanceof PythonClass ) {
896
+ NativeCAPISymbol symbol = null ;
898
897
// We need to point to PyType_GenericAlloc or PyObject_GC_Del
899
- NativeCAPISymbol symbol ;
900
898
if (managedMemberName == HiddenAttr .ALLOC ) {
901
899
symbol = FUN_PY_TYPE_GENERIC_ALLOC ;
902
- } else {
900
+ } else if ( managedMemberName == HiddenAttr . FREE ) {
903
901
symbol = FUN_PY_OBJECT_GC_DEL ;
902
+ } else if (managedMemberName == HiddenAttr .CLEAR ) {
903
+ // This will need to be subtype_clear when we implement native GC
904
+ symbol = FUN_NO_OP_CLEAR ;
905
+ }
906
+ if (symbol != null ) {
907
+ Object func = HiddenAttr .ReadNode .executeUncached (cls , managedMemberName , null );
908
+ if (func != null ) {
909
+ return func ;
910
+ }
911
+ return CApiContext .getNativeSymbol (null , symbol );
904
912
}
905
- return CApiContext .getNativeSymbol (null , symbol );
906
913
}
907
914
MroSequenceStorage mroStorage = GetMroStorageNode .executeUncached (cls );
908
915
int n = mroStorage .length ();
@@ -921,6 +928,9 @@ public static Object lookupNativeMemberInMRO(PythonManagedClass cls, @SuppressWa
921
928
}
922
929
}
923
930
}
931
+ if (managedMemberName == HiddenAttr .CLEAR && (TypeNodes .GetTypeFlagsNode .executeUncached (cls ) & TypeFlags .HAVE_GC ) != 0 ) {
932
+ return CApiContext .getNativeSymbol (null , FUN_NO_OP_CLEAR );
933
+ }
924
934
return HiddenAttr .ReadNode .executeUncached (PythonContext .get (null ).lookupType (PythonBuiltinClassType .PythonObject ), managedMemberName , NO_VALUE );
925
935
}
926
936
0 commit comments