Skip to content

Commit 53baa0e

Browse files
committed
[GR-21159] 'Is' operation should threat hosted null object as None in Jython emulation mode.
PullRequest: graalpython/816
2 parents dc03c36 + f8b59eb commit 53baa0e

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-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: 22 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,16 +40,21 @@
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.runtime.PythonContext;
54+
import com.oracle.graal.python.runtime.PythonOptions;
5155
import com.oracle.truffle.api.RootCallTarget;
5256
import com.oracle.truffle.api.dsl.Cached;
57+
import com.oracle.truffle.api.dsl.CachedContext;
5358
import com.oracle.truffle.api.dsl.Fallback;
5459
import com.oracle.truffle.api.dsl.GenerateUncached;
5560
import com.oracle.truffle.api.dsl.Specialization;
@@ -210,6 +215,22 @@ boolean doCode(PCode left, PCode right) {
210215
return left == right;
211216
}
212217

218+
@Specialization
219+
boolean doObjectPNone(Object left, PNone right,
220+
@Cached.Shared("ctxt") @CachedContext(PythonLanguage.class) PythonContext ctxt) {
221+
if (PythonOptions.getFlag(ctxt, PythonOptions.EmulateJython) && ctxt.getEnv().isHostObject(left) && ctxt.getEnv().asHostObject(left) == null &&
222+
right == PNone.NONE) {
223+
return true;
224+
}
225+
return doGeneric(left, right);
226+
}
227+
228+
@Specialization
229+
boolean doPNoneObject(PNone left, Object right,
230+
@CachedContext(PythonLanguage.class) PythonContext ctxt) {
231+
return doObjectPNone(right, left, ctxt);
232+
}
233+
213234
@Fallback
214235
boolean doGeneric(Object left, Object right) {
215236
return left == right;

0 commit comments

Comments
 (0)