Skip to content

Commit 27c9571

Browse files
committed
Add weaklistoffset to builtin types
1 parent 61355a5 commit 27c9571

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
import java.util.HashSet;
100100

101101
import com.oracle.graal.python.PythonLanguage;
102+
import com.oracle.graal.python.builtins.modules.WeakRefModuleBuiltins;
102103
import com.oracle.graal.python.builtins.objects.function.BuiltinMethodDescriptor;
103104
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
104105
import com.oracle.graal.python.runtime.PythonContext;
@@ -499,6 +500,7 @@ private static class Flags {
499500
// initialized in static constructor
500501
@CompilationFinal private PythonBuiltinClassType type;
501502
@CompilationFinal private PythonBuiltinClassType base;
503+
@CompilationFinal private int weaklistoffset;
502504

503505
/**
504506
* @see #redefinesSlot(SpecialMethodSlot)
@@ -540,6 +542,7 @@ private static class Flags {
540542
this.isBuiltinWithDict = flags.isBuiltinWithDict;
541543
this.isException = flags == Flags.EXCEPTION;
542544
this.methodsFlags = methodsFlags;
545+
this.weaklistoffset = -1;
543546
}
544547

545548
PythonBuiltinClassType(String name, String module) {
@@ -610,6 +613,10 @@ public long getMethodsFlags() {
610613
return methodsFlags;
611614
}
612615

616+
public int getWeaklistoffset() {
617+
return weaklistoffset;
618+
}
619+
613620
/**
614621
* Returns {@code true} if this method slot is redefined in Python code during initialization.
615622
* Values of such slots cannot be cached in {@link #specialMethodSlots}, because they are not
@@ -860,6 +867,8 @@ public final Shape getInstanceShape(PythonLanguage lang) {
860867
if (type.type == null && type.base != null) {
861868
type.type = type.base.type;
862869
}
870+
871+
type.weaklistoffset = WeakRefModuleBuiltins.getBuiltinTypeWeaklistoffset(type);
863872
}
864873

865874
// Finally, we set all remaining types to PythonClass.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WeakRefModuleBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
105105
return WeakRefModuleBuiltinsFactory.getFactories();
106106
}
107107

108-
private static long getBuiltinTypeWeaklistoffset(PythonBuiltinClassType cls) {
108+
public static int getBuiltinTypeWeaklistoffset(PythonBuiltinClassType cls) {
109109
// @formatter:off
110110
return switch (cls) {
111111
case PythonObject, // object
@@ -393,7 +393,7 @@ public PReferenceType refType(Object cls, Object object, @SuppressWarnings("unus
393393
Object clazz = getClassNode.execute(this, obj);
394394
boolean allowed = true;
395395
if (clazz instanceof PythonBuiltinClassType type) {
396-
allowed = getBuiltinTypeWeaklistoffset(type) != 0;
396+
allowed = type.getWeaklistoffset() != 0;
397397
}
398398
if (!allowed) {
399399
throw raise(TypeError, ErrorMessages.CANNOT_CREATE_WEAK_REFERENCE_TO, obj);

0 commit comments

Comments
 (0)