Skip to content

Commit 87b17da

Browse files
committed
fix reading non-string from dynamic object storages
1 parent e747ad6 commit 87b17da

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,18 +1100,21 @@ Object doEmptyStorage(VirtualFrame frame, EmptyStorage storage, Object key) {
11001100
return null;
11011101
}
11021102

1103+
// this is just a minor performance optimization
11031104
@Specialization
11041105
static Object doPythonObjectString(PythonObjectDictStorage storage, String key,
11051106
@Shared("readKey") @Cached ReadAttributeFromDynamicObjectNode readKey) {
11061107
return doDynamicObjectString(storage, key, readKey);
11071108
}
11081109

1110+
// this is just a minor performance optimization
11091111
@Specialization
11101112
static Object doPythonObjectPString(PythonObjectDictStorage storage, PString key,
11111113
@Shared("readKey") @Cached ReadAttributeFromDynamicObjectNode readKey) {
11121114
return doDynamicObjectPString(storage, key, readKey);
11131115
}
11141116

1117+
// this will read from the dynamic object
11151118
@Specialization
11161119
static Object doDynamicObjectString(DynamicObjectStorage storage, String key,
11171120
@Shared("readKey") @Cached ReadAttributeFromDynamicObjectNode readKey) {
@@ -1126,10 +1129,22 @@ static Object doDynamicObjectPString(DynamicObjectStorage storage, PString key,
11261129
return result == PNone.NO_VALUE ? null : result;
11271130
}
11281131

1129-
@Specialization(guards = {"!isString(key)", "isHashable(frame, key)", "s.getClass() == cachedClass"}, limit = "MAX_DYNAMIC_STORAGES")
1130-
Object doDynamicStorage(@SuppressWarnings("unused") VirtualFrame frame, DynamicObjectStorage s, Object key,
1131-
@Cached("s.getClass()") Class<? extends DynamicObjectStorage> cachedClass) {
1132-
return cachedClass.cast(s).getItem(key, getEquivalence());
1132+
// this must read from the non-dynamic object storage
1133+
@Specialization(guards = {"!isString(key)", "isHashable(frame, key)"})
1134+
Object doDynamicStorage(@SuppressWarnings("unused") VirtualFrame frame, PythonObjectHybridDictStorage s, Object key) {
1135+
return s.getItem(key, getEquivalence());
1136+
}
1137+
1138+
protected static boolean isPythonObjectHybridStorage(DynamicObjectStorage s) {
1139+
return s instanceof PythonObjectHybridDictStorage;
1140+
}
1141+
1142+
// any dynamic object storage that isn't hybridized cannot store
1143+
// non-string keys
1144+
@Specialization(guards = {"!isString(key)", "isHashable(frame, key)", "!isPythonObjectHybridStorage(s)"})
1145+
@SuppressWarnings("unused")
1146+
Object doDynamicStorage(VirtualFrame frame, DynamicObjectStorage s, Object key) {
1147+
return null;
11331148
}
11341149

11351150
@Specialization

0 commit comments

Comments
 (0)