Skip to content

Commit cec3b68

Browse files
committed
[GR-21159] 'Is' operation should threat hosted null object as None in Jython emulation mode.
1 parent dc03c36 commit cec3b68

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_interop.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -449,3 +449,44 @@ def test_java_import_star():
449449
exec("from java.util.logging.Logger import *", globals=d, locals=d)
450450
assert "getGlobal" in d
451451
assert d["getGlobal"]().getName() == d["GLOBAL_LOGGER_NAME"]
452+
453+
def test_java_null_is_none():
454+
import java.lang.Integer as Integer
455+
x = Integer.getInteger("something_what_does_not_exists")
456+
y = Integer.getInteger("something_what_does_not_exists2")
457+
z = None
458+
459+
if sys.graal_python_jython_emulation_enabled:
460+
461+
assert x == None
462+
assert (x != None) == False
463+
assert x is None
464+
assert (x is not None) == False
465+
466+
assert x == y
467+
assert (x != y) == False
468+
assert x is y
469+
assert (x is not y) == False
470+
471+
assert x == z
472+
assert (x != z) == False
473+
assert x is z
474+
assert (x is not z) == False
475+
476+
else:
477+
478+
assert x == None
479+
assert (x != None) == False
480+
assert (x is None) == False
481+
assert x is not None
482+
483+
assert (x == y) == False
484+
assert x != y
485+
assert x is y
486+
assert (x is not y) == False
487+
488+
assert x == z
489+
assert (x != z) == False
490+
assert (x is z) == False
491+
assert x is not z
492+

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/IsExpressionNode.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -40,18 +40,25 @@
4040
*/
4141
package com.oracle.graal.python.nodes.expression;
4242

43+
import com.oracle.graal.python.PythonLanguage;
4344
import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
4445

4546
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
47+
import com.oracle.graal.python.builtins.objects.PNone;
4648
import com.oracle.graal.python.builtins.objects.cext.CExtNodes;
4749
import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
4850
import com.oracle.graal.python.builtins.objects.code.PCode;
4951
import com.oracle.graal.python.builtins.objects.ints.PInt;
5052
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
53+
import com.oracle.graal.python.nodes.PGuards;
54+
import com.oracle.graal.python.runtime.PythonContext;
55+
import com.oracle.graal.python.runtime.PythonOptions;
5156
import com.oracle.truffle.api.RootCallTarget;
5257
import com.oracle.truffle.api.dsl.Cached;
58+
import com.oracle.truffle.api.dsl.CachedContext;
5359
import com.oracle.truffle.api.dsl.Fallback;
5460
import com.oracle.truffle.api.dsl.GenerateUncached;
61+
import com.oracle.truffle.api.dsl.ImportStatic;
5562
import com.oracle.truffle.api.dsl.Specialization;
5663
import com.oracle.truffle.api.nodes.Node;
5764

@@ -67,6 +74,7 @@ boolean doIt(Object left, Object right,
6774
}
6875

6976
@GenerateUncached
77+
@ImportStatic({PGuards.class})
7078
public abstract static class IsNode extends Node {
7179

7280
public abstract boolean execute(Object left, Object right);
@@ -210,6 +218,22 @@ boolean doCode(PCode left, PCode right) {
210218
return left == right;
211219
}
212220

221+
@Specialization
222+
boolean doObjectPNone(Object left, PNone right,
223+
@CachedContext(PythonLanguage.class) PythonContext ctxt) {
224+
if (PythonOptions.getFlag(ctxt, PythonOptions.EmulateJython) && ctxt.getEnv().isHostObject(left) && ctxt.getEnv().asHostObject(left) == null &&
225+
right == PNone.NONE) {
226+
return true;
227+
}
228+
return doGeneric(left, right);
229+
}
230+
231+
@Specialization
232+
boolean doPNoneObject(PNone left, Object right,
233+
@CachedContext(PythonLanguage.class) PythonContext ctxt) {
234+
return doObjectPNone(right, left, ctxt);
235+
}
236+
213237
@Fallback
214238
boolean doGeneric(Object left, Object right) {
215239
return left == right;

0 commit comments

Comments
 (0)