Skip to content

Commit b6a4f4d

Browse files
committed
Add tests for pointer equality of primitives.
1 parent c3185e5 commit b6a4f4d

File tree

1 file changed

+36
-0
lines changed
  • graalpython/com.oracle.graal.python.test/src/tests/cpyext

1 file changed

+36
-0
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_misc.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,39 @@ def compile_module(self, name):
174174
arguments=["PyObject* arg0", "PyObject* arg1"],
175175
cmpfunc=unhandled_error_compare
176176
)
177+
178+
test_PointerEquality_Primitive = CPyExtFunction(
179+
lambda args: True,
180+
lambda: (
181+
(True, lambda arg0, *args: arg0),
182+
(False, lambda arg0, *args: arg0),
183+
(10, lambda arg0, *args: arg0),
184+
(10.0, lambda arg0, *args: arg0),
185+
("ten", lambda arg0, *args: arg0),
186+
),
187+
code="""PyObject* PointerEquality_Primitive(PyObject* pyVal, PyObject* fun) {
188+
PyObject** dummyArray = (PyObject**) malloc(sizeof(PyObject*));
189+
Py_INCREF(pyVal);
190+
Py_INCREF(fun);
191+
dummyArray[0] = pyVal;
192+
193+
PyObject* arg = PyTuple_New(1);
194+
PyTuple_SET_ITEM(arg, 0, dummyArray[0]);
195+
Py_INCREF(arg);
196+
PyObject* result0 = PyObject_Call(fun, arg, NULL);
197+
if (pyVal != result0) {
198+
PyErr_Format(PyExc_ValueError, "%s is not pointer equal: 0x%lx vs. 0x%lx", PyUnicode_AsUTF8(PyObject_Repr(pyVal)), (void*)pyVal, (void*)result0);
199+
return NULL;
200+
}
201+
202+
free(dummyArray);
203+
Py_DECREF(pyVal);
204+
Py_DECREF(fun);
205+
return Py_True;
206+
}
207+
""",
208+
resultspec="O",
209+
argspec="OO",
210+
arguments=["PyObject* pyVal", "PyObject* fun"],
211+
cmpfunc=unhandled_error_compare
212+
)

0 commit comments

Comments
 (0)