Skip to content

Commit e8822f3

Browse files
committed
Add missing interop-to-python value conversions
1 parent 7cc8271 commit e8822f3

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,16 @@ private boolean isAbstractMapping(PythonObjectLibrary thisLib) {
235235

236236
@ExportMessage
237237
public void writeMember(String key, Object value,
238-
@Exclusive @Cached PInteropSubscriptAssignNode setItemNode,
238+
@Shared("setItemNode") @Cached PInteropSubscriptAssignNode setItemNode,
239239
@CachedLibrary("this") PythonObjectLibrary dataModelLibrary,
240240
@Exclusive @Cached KeyForAttributeAccess getAttributeKey,
241241
@Exclusive @Cached KeyForItemAccess getItemKey,
242-
@Cached PInteropSetAttributeNode writeNode,
242+
@Cached PInteropSetAttributeNode setAttributeNode,
243243
@Shared("attributeErrorProfile") @Cached IsBuiltinClassProfile attrErrorProfile) throws UnsupportedMessageException, UnknownIdentifierException {
244244
try {
245245
String attrKey = getAttributeKey.execute(key);
246246
if (attrKey != null) {
247-
writeNode.execute(this, attrKey, value);
247+
setAttributeNode.execute(this, attrKey, value);
248248
return;
249249
}
250250

@@ -256,14 +256,14 @@ public void writeMember(String key, Object value,
256256

257257
if (this instanceof PythonObject) {
258258
if (objectHasAttribute(this, key)) {
259-
writeNode.execute(this, key, value);
259+
setAttributeNode.execute(this, key, value);
260260
return;
261261
}
262262
}
263263
if (isAbstractMapping(dataModelLibrary)) {
264264
setItemNode.execute(this, key, value);
265265
} else {
266-
writeNode.execute(this, key, value);
266+
setAttributeNode.execute(this, key, value);
267267
}
268268
} catch (PException e) {
269269
e.expectAttributeError(attrErrorProfile);
@@ -347,7 +347,7 @@ public Object readArrayElement(long key,
347347
@ExportMessage
348348
public void writeArrayElement(long key, Object value,
349349
@CachedLibrary("this") PythonObjectLibrary dataModelLibrary,
350-
@Exclusive @Cached PInteropSubscriptAssignNode setItemNode) throws UnsupportedMessageException, InvalidArrayIndexException {
350+
@Shared("setItemNode") @Cached PInteropSubscriptAssignNode setItemNode) throws UnsupportedMessageException, InvalidArrayIndexException {
351351
if (dataModelLibrary.isSequence(this)) {
352352
try {
353353
setItemNode.execute(this, key, value);
@@ -1867,13 +1867,14 @@ public abstract static class PInteropSubscriptAssignNode extends Node {
18671867

18681868
@Specialization
18691869
static void doSpecialObject(PythonAbstractObject primary, Object key, Object value,
1870+
@Cached PForeignToPTypeNode convert,
18701871
@Cached PInteropGetAttributeNode getAttributeNode,
18711872
@Cached CallBinaryMethodNode callSetItemNode,
18721873
@Cached ConditionProfile profile) throws UnsupportedMessageException {
18731874

18741875
Object attrSetitem = getAttributeNode.execute(primary, __SETITEM__);
18751876
if (profile.profile(attrSetitem != PNone.NO_VALUE)) {
1876-
callSetItemNode.executeObject(attrSetitem, key, value);
1877+
callSetItemNode.executeObject(attrSetitem, key, convert.executeConvert(value));
18771878
} else {
18781879
throw UnsupportedMessageException.create();
18791880
}
@@ -1890,15 +1891,16 @@ public abstract static class PInteropSetAttributeNode extends Node {
18901891
public abstract void execute(Object primary, String attrName, Object value) throws UnsupportedMessageException, UnknownIdentifierException;
18911892

18921893
@Specialization
1893-
public void doSpecialObject(PythonAbstractObject primary, String attrName, Object value,
1894+
public static void doSpecialObject(PythonAbstractObject primary, String attrName, Object value,
1895+
@Cached PForeignToPTypeNode convert,
18941896
@Cached LookupInheritedAttributeNode.Dynamic lookupSetAttrNode,
18951897
@Cached CallTernaryMethodNode callSetAttrNode,
18961898
@Cached ConditionProfile profile,
18971899
@Cached IsBuiltinClassProfile attrErrorProfile) throws UnsupportedMessageException, UnknownIdentifierException {
1898-
Object attrGetattribute = lookupSetAttrNode.execute(primary, SpecialMethodNames.__SETATTR__);
1899-
if (profile.profile(attrGetattribute != PNone.NO_VALUE)) {
1900+
Object attrSetattr = lookupSetAttrNode.execute(primary, SpecialMethodNames.__SETATTR__);
1901+
if (profile.profile(attrSetattr != PNone.NO_VALUE)) {
19001902
try {
1901-
callSetAttrNode.execute(null, attrGetattribute, primary, attrName, value);
1903+
callSetAttrNode.execute(null, attrSetattr, primary, attrName, convert.executeConvert(value));
19021904
} catch (PException e) {
19031905
e.expectAttributeError(attrErrorProfile);
19041906
// TODO(fa) not accurate; distinguish between read-only and non-existing
@@ -2086,9 +2088,11 @@ public static int systemHashCode(Object value) {
20862088
}
20872089

20882090
@ExportMessage
2089-
public TriState isIdenticalOrUndefined(Object other,
2091+
public TriState isIdenticalOrUndefined(Object otherInterop,
2092+
@Cached PForeignToPTypeNode convert,
20902093
@CachedLibrary(limit = "3") InteropLibrary otherLib,
20912094
@CachedLibrary("this") PythonObjectLibrary objectLib) {
2095+
Object other = convert.executeConvert(otherInterop);
20922096
if (this == other) {
20932097
return TriState.TRUE;
20942098
} else if (otherLib.hasIdentity(other)) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/PList.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
3030
import com.oracle.graal.python.builtins.objects.ints.PInt;
3131
import com.oracle.graal.python.nodes.ErrorMessages;
32+
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
3233
import com.oracle.graal.python.nodes.literal.ListLiteralNode;
3334
import com.oracle.graal.python.runtime.exception.PException;
3435
import com.oracle.graal.python.runtime.sequence.PSequence;
@@ -187,9 +188,10 @@ public boolean isArrayElementRemovable(long index,
187188

188189
@ExportMessage
189190
public void writeArrayElement(long index, Object value,
191+
@Cached PForeignToPTypeNode convert,
190192
@Cached.Exclusive @Cached SequenceStorageNodes.SetItemScalarNode setItem) throws InvalidArrayIndexException {
191193
try {
192-
setItem.execute(store, PInt.intValueExact(index), value);
194+
setItem.execute(store, PInt.intValueExact(index), convert.executeConvert(value));
193195
} catch (OverflowException e) {
194196
CompilerDirectives.transferToInterpreterAndInvalidate();
195197
throw InvalidArrayIndexException.create(index);

0 commit comments

Comments
 (0)