Skip to content

Commit 06f7cd7

Browse files
timfelabdelberni
authored andcommitted
Expose PyTuple_SET_ITEM also as API function on GraalPy
(cherry picked from commit 97fb792) fix conflicts
1 parent 30f2a29 commit 06f7cd7

File tree

6 files changed

+33
-17
lines changed

6 files changed

+33
-17
lines changed

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

Lines changed: 3 additions & 7 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,10 @@ 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-
}
4742
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
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))
45+
do { PyTruffleTuple_GetItems(op)[index] = value; } while (0)
5046
#endif
5147

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

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

Lines changed: 1 addition & 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

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: 1 addition & 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

scripts/wheelbuilder/build_wheels.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2023, 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
@@ -100,13 +100,10 @@ def create_venv():
100100
subprocess.check_call([binary, "-m", "venv", "graalpy"])
101101
print("Installing wheel with", pip, flush=True)
102102
subprocess.check_call([pip, "install", "wheel"])
103-
<<<<<<< HEAD
104-
=======
105103
print("Installing paatch to provide patch.exe", flush=True)
106104
p = subprocess.run([pip, "install", "paatch"])
107105
if p.returncode != 0:
108106
print("Installing paatch failed, assuming a GNU patch compatible binary is on PATH", flush=True)
109-
>>>>>>> 8ac74ecd42 (Use paatch to apply patches the same way across all platforms)
110107
return pip
111108

112109

0 commit comments

Comments
 (0)