Skip to content

Commit 76d4966

Browse files
OracleLabsAutomationelkorchi
authored andcommitted
[GR-64327] Backport to 24.2: Add support for ormsgpack and prepare upstreaming some changes
PullRequest: graalpython/3765
2 parents eba1d9b + c6e5e39 commit 76d4966

File tree

9 files changed

+425
-17
lines changed

9 files changed

+425
-17
lines changed

graalpython/com.oracle.graal.python.cext/include/cpython/tupleobject.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2020, 2024, Oracle and/or its affiliates.
1+
/* Copyright (c) 2020, 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
@@ -39,14 +39,9 @@ PyAPI_FUNC(PyObject *) _PyTuple_GET_ITEM(PyObject *, Py_ssize_t);
3939
// GraalPy-specific
4040
PyAPI_FUNC(PyObject **) PyTruffleTuple_GetItems(PyObject *op);
4141

42-
/* Function *only* to be used to fill in brand new tuples */
43-
static inline void
44-
PyTuple_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) {
45-
PyTruffleTuple_GetItems(op)[index] = value;
46-
}
47-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
42+
// GraalPy change: Export PyTuple_SET_ITEM as regular API function to use in PyO3 and others
43+
PyAPI_FUNC(void) PyTuple_SET_ITEM(PyObject*, Py_ssize_t, PyObject*);
4844
#define PyTuple_SET_ITEM(op, index, value) \
49-
PyTuple_SET_ITEM(_PyObject_CAST(op), index, _PyObject_CAST(value))
50-
#endif
45+
PyTuple_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
5146

5247
PyAPI_FUNC(void) _PyTuple_DebugMallocStats(FILE *out);

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: 6 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-2022 Python Software Foundation
33
*
44
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -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.cext/src/tupleobject.c

Lines changed: 7 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-2022 Python Software Foundation
33
*
44
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -1424,3 +1424,9 @@ _PyTuple_GET_ITEM(PyObject* a, Py_ssize_t b) {
14241424
}
14251425
return NULL; // an exception has happend during transtion
14261426
}
1427+
1428+
#undef PyTuple_SET_ITEM
1429+
// Export PyTuple_SET_ITEM as regular API function to use in PyO3 and others
1430+
void PyTuple_SET_ITEM(PyObject* op, Py_ssize_t index, PyObject* value) {
1431+
PyTruffleTuple_GetItems(op)[index] = value;
1432+
}

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2025, 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
@@ -151,14 +151,15 @@ class TestPyTuple(CPyExtTestCase):
151151
((1, 2, 3), -1, []),
152152
((1, 2, 3), 3, str),
153153
),
154-
code="""PyObject* wrap_PyTuple_SetItem(PyObject* original, Py_ssize_t index, PyObject* value) {
154+
code="""
155+
PyObject* wrap_PyTuple_SetItem(PyObject* original, Py_ssize_t index, PyObject* value) {
155156
Py_ssize_t size = PyTuple_Size(original);
156157
if (size < 0)
157158
return NULL;
158159
PyObject* tuple = PyTuple_New(size);
159160
if (!tuple)
160161
return NULL;
161-
for (int i = 0; i < size; i++) {
162+
for (int i = 0; i < size / 2; i++) {
162163
PyObject* item = PyTuple_GetItem(original, i);
163164
if (!item) {
164165
Py_DECREF(tuple);
@@ -167,6 +168,22 @@ class TestPyTuple(CPyExtTestCase):
167168
Py_INCREF(item);
168169
PyTuple_SET_ITEM(tuple, i, item);
169170
}
171+
172+
#ifdef GRAALVM_PYTHON
173+
// test that we also have it as API function on GraalPy
174+
#undef PyTuple_SET_ITEM
175+
#endif
176+
177+
for (int i = size / 2; i < size; i++) {
178+
PyObject* item = PyTuple_GetItem(original, i);
179+
if (!item) {
180+
Py_DECREF(tuple);
181+
return NULL;
182+
}
183+
Py_INCREF(item);
184+
PyTuple_SET_ITEM(tuple, i, item);
185+
}
186+
170187
Py_INCREF(value);
171188
if (PyTuple_SetItem(tuple, index, value) < 0) {
172189
Py_DECREF(tuple);

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, 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
@@ -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
}

graalpython/lib-graalpython/patches/metadata.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ version = '== 3.10.5'
337337
patch = 'orjson-3.10.5.patch'
338338
license = 'Apache-2.0 OR MIT'
339339

340+
[[ormsgpack.rules]]
341+
version = '>= 1.8.0, <= 1.9.1'
342+
patch = 'ormsgpack-1.8.0-1.9.1.patch'
343+
license = 'Apache-2.0 OR MIT'
344+
340345
[[overrides.rules]]
341346
version = '== 7.4.0'
342347
# Important: This patch esentially breaks the package, it's not upstreamable. The package relies on bytecode parsing

0 commit comments

Comments
 (0)