Skip to content

Commit 4e02952

Browse files
timfelabdelberni
authored andcommitted
Fix our implementation of Py_Is
(cherry picked from commit 37cb91a)
1 parent 8e20788 commit 4e02952

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

graalpython/com.oracle.graal.python.cext/include/object.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018, 2024, Oracle and/or its affiliates.
1+
/* Copyright (c) 2018, 2025, Oracle and/or its affiliates.
22
* Copyright (C) 1996-2020 Python Software Foundation
33
*
44
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -124,7 +124,9 @@ typedef struct {
124124

125125
// Test if the 'x' object is the 'y' object, the same as "x is y" in Python.
126126
PyAPI_FUNC(int) Py_Is(PyObject *x, PyObject *y);
127+
#if 0 // GraalPy change
127128
#define Py_Is(x, y) ((x) == (y))
129+
#endif // GraalPy change
128130

129131

130132
PyAPI_FUNC(Py_ssize_t) PyTruffle_REFCNT(PyObject *ob);

graalpython/com.oracle.graal.python.cext/src/object.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,7 +2507,12 @@ Py_XNewRef(PyObject *obj)
25072507
// for the stable ABI.
25082508
int Py_Is(PyObject *x, PyObject *y)
25092509
{
2510+
#if 0 // GraalPy change
25102511
return (x == y);
2512+
#else
2513+
return (x == y) ||
2514+
(points_to_py_handle_space(x) && points_to_py_handle_space(y) && GraalPyTruffle_Is(x, y));
2515+
#endif
25112516
}
25122517

25132518
int Py_IsNone(PyObject *x)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
130130
import com.oracle.graal.python.nodes.object.GetClassNode;
131131
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
132+
import com.oracle.graal.python.nodes.object.IsNode;
132133
import com.oracle.graal.python.nodes.util.CannotCastException;
133134
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
134135
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
@@ -739,4 +740,13 @@ static Object getDict(Object object,
739740
return getDict.execute(inliningTarget, object);
740741
}
741742
}
743+
744+
@CApiBuiltin(ret = Int, args = {PyObject, PyObject}, call = Ignored)
745+
abstract static class PyTruffle_Is extends CApiBinaryBuiltinNode {
746+
@Specialization
747+
static int isTrue(Object a, Object b,
748+
@Cached IsNode isNode) {
749+
return isNode.execute(a, b) ? 1 : 0;
750+
}
751+
}
742752
}

0 commit comments

Comments
 (0)