Skip to content

Commit 26e7584

Browse files
committed
Make more list and tuple functions public
1 parent 3f5cb28 commit 26e7584

File tree

10 files changed

+39
-48
lines changed

10 files changed

+39
-48
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -755,13 +755,12 @@ PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m);
755755
#define PySequence_Fast_GET_ITEM(o, i)\
756756
(PyList_Check(o) ? PyList_GET_ITEM((o), (i)) : PyTuple_GET_ITEM((o), (i)))
757757

758-
// GraalPy-specific
759-
PyAPI_FUNC(PyObject **) GraalPyPrivate_Sequence_Fast_ITEMS(PyObject *o);
760-
761758
/* Return a pointer to the underlying item array for
762759
an object returned by PySequence_Fast */
763760
// GraalPy change
764-
#define PySequence_Fast_ITEMS(sf) GraalPyPrivate_Sequence_Fast_ITEMS(sf)
761+
#define PySequence_Fast_ITEMS(sf) \
762+
(PyList_Check(sf) ? GraalPyList_ITEMS(_PyObject_CAST((sf))) \
763+
: GraalPyTuple_ITEMS(_PyObject_CAST((sf))))
765764

766765
/* Return the number of occurrences on value on 'o', that is, return
767766
the number of keys for which o[key] == value.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ static inline Py_ssize_t PyList_GET_SIZE(PyObject *op) {
4343

4444
#define PyList_GET_ITEM(op, index) (PyList_GetItem((PyObject*)(op), (index)))
4545

46-
// GraalPy-specific
47-
PyAPI_FUNC(PyObject **) GraalPyPrivate_List_GetItems(PyObject *op);
46+
// GraalPy public API to replace direct access to ob_item
47+
PyAPI_FUNC(PyObject **) GraalPyList_ITEMS(PyObject *op);
48+
PyAPI_FUNC(void) GraalPyList_SET_ITEM(PyObject* a, Py_ssize_t b, PyObject* c);
4849

4950
static inline void
5051
PyList_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) {
51-
GraalPyPrivate_List_GetItems(op)[index] = value;
52+
GraalPyList_SET_ITEM(op, index, value);
5253
}
5354
#define PyList_SET_ITEM(op, index, value) \
5455
PyList_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,19 @@ static inline Py_ssize_t PyTuple_GET_SIZE(PyObject *op) {
3131
}
3232
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
3333

34-
PyAPI_FUNC(PyObject *) _PyTuple_GET_ITEM(PyObject *, Py_ssize_t);
35-
#define PyTuple_GET_ITEM(op, index) _PyTuple_GET_ITEM(_PyObject_CAST(op), (index))
34+
#define PyTuple_GET_ITEM(op, index) GraalPyTuple_GET_ITEM(_PyObject_CAST(op), (index))
3635

37-
// GraalPy-specific
38-
PyAPI_FUNC(PyObject **) GraalPyPrivate_Tuple_GetItems(PyObject *op);
36+
// GraalPy public API to avoid direct access to ob_item
37+
PyAPI_FUNC(PyObject **) GraalPyTuple_ITEMS(PyObject *op);
38+
PyAPI_FUNC(PyObject *) GraalPyTuple_GET_ITEM(PyObject *, Py_ssize_t);
39+
PyAPI_FUNC(void) GraalPyTuple_SET_ITEM(PyObject*, Py_ssize_t, PyObject*);
3940

40-
// GraalPy change: Export PyTuple_SET_ITEM as regular API function to use in PyO3 and others
41-
PyAPI_FUNC(void) PyTuple_SET_ITEM(PyObject*, Py_ssize_t, PyObject*);
42-
43-
/* Inline function to be used in the PyTuple_SET_ITEM macro. */
44-
static inline void graalpy_tuple_set_item(PyObject *op, Py_ssize_t index, PyObject *value) {
45-
GraalPyPrivate_Tuple_GetItems(op)[index] = value;
41+
/* Function *only* to be used to fill in brand new tuples */
42+
static inline void
43+
PyTuple_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) {
44+
GraalPyTuple_SET_ITEM(op, index, value);
4645
}
4746
#define PyTuple_SET_ITEM(op, index, value) \
48-
graalpy_tuple_set_item(_PyObject_CAST(op), (index), _PyObject_CAST(value))
47+
PyTuple_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
4948

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

graalpython/com.oracle.graal.python.cext/include/internal/pycore_tuple.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2022, 2024, Oracle and/or its affiliates.
1+
/* Copyright (c) 2022, 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
@@ -66,7 +66,7 @@ struct _Py_tuple_state {
6666
#endif
6767
};
6868

69-
#define _PyTuple_ITEMS(op) (PySequence_Fast_ITEMS(op))
69+
#define _PyTuple_ITEMS(op) (GraalPyTuple_ITEMS(op))
7070

7171
extern PyObject *_PyTuple_FromArray(PyObject *const *, Py_ssize_t);
7272
extern PyObject *_PyTuple_FromArraySteal(PyObject *const *, Py_ssize_t);

graalpython/com.oracle.graal.python.cext/modules/_sqlite/clinic/connection.c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
6060
int uri = 0;
6161
enum autocommit_mode autocommit = LEGACY_TRANSACTION_CONTROL;
6262

63-
fastargs = _PyArg_UnpackKeywords(PySequence_Fast_ITEMS(args), nargs, kwargs, NULL, &_parser, 1, 8, 0, argsbuf);
63+
fastargs = _PyArg_UnpackKeywords(GraalPyTuple_ITEMS(args), nargs, kwargs, NULL, &_parser, 1, 8, 0, argsbuf);
6464
if (!fastargs) {
6565
goto exit;
6666
}

graalpython/com.oracle.graal.python.cext/modules/clinic/sha3module.c.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2024, Oracle and/or its affiliates.
1+
/* Copyright (c) 2024, 2025, Oracle and/or its affiliates.
22
* Copyright (C) 1996-2024 Python Software Foundation
33
*
44
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -59,7 +59,7 @@ py_sha3_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
5959
PyObject *data = NULL;
6060
int usedforsecurity = 1;
6161

62-
fastargs = _PyArg_UnpackKeywords(PySequence_Fast_ITEMS(args), nargs, kwargs, NULL, &_parser, 0, 1, 0, argsbuf);
62+
fastargs = _PyArg_UnpackKeywords(GraalPyTuple_ITEMS(args), nargs, kwargs, NULL, &_parser, 0, 1, 0, argsbuf);
6363
if (!fastargs) {
6464
goto exit;
6565
}

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3044,15 +3044,6 @@ _Py_FreeCharPArray(char *const array[])
30443044
#endif // GraalPy change
30453045

30463046
// GraalPy additions
3047-
PyObject **
3048-
GraalPyPrivate_Sequence_Fast_ITEMS(PyObject *o)
3049-
{
3050-
if (PyTuple_Check(o)) {
3051-
return GraalPyPrivate_Tuple_GetItems(o);
3052-
} else {
3053-
return GraalPyPrivate_List_GetItems(o);
3054-
}
3055-
}
30563047

30573048
PyObject*
30583049
GraalPyPrivate_Sequence_ITEM(PyObject* obj, Py_ssize_t index)

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,13 @@ PyTypeObject PyList_Type = {
131131
.tp_vectorcall = 0, // GraalPy change: nulled
132132
};
133133

134-
// alias for internal function, currently used in PyO3
134+
void GraalPyList_SET_ITEM(PyObject* op, Py_ssize_t index, PyObject* value) {
135+
GraalPyList_ITEMS(op)[index] = value;
136+
}
137+
138+
// deprecated alias for internal function, currently used in PyO3
135139
PyAPI_FUNC(void) _PyList_SET_ITEM(PyObject* a, Py_ssize_t b, PyObject* c) {
136-
PyList_SET_ITEM(a, b, c);
140+
GraalPyList_SET_ITEM(a, b, c);
137141
}
138142

139143
static inline int
@@ -166,14 +170,14 @@ PyList_SetItem(PyObject *op, Py_ssize_t i,
166170
return -1;
167171
}
168172
// GraalPy change: avoid direct struct access
169-
p = GraalPyPrivate_List_GetItems(op) + i;
173+
p = GraalPyList_ITEMS(op) + i;
170174
Py_XSETREF(*p, newitem);
171175
return 0;
172176
}
173177

174178
// GraalPy-additions
175179
PyObject **
176-
GraalPyPrivate_List_GetItems(PyObject *op)
180+
GraalPyList_ITEMS(PyObject *op)
177181
{
178182
return GraalPyPrivate_GET_PyListObject_ob_item(op);
179183
}

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ PyTuple_SetItem(PyObject *op, Py_ssize_t i, PyObject *newitem)
152152
return -1;
153153
}
154154
// GraalPy change: avoid direct struct access
155-
p = GraalPyPrivate_Tuple_GetItems(op) + i;
155+
p = GraalPyTuple_ITEMS(op) + i;
156156
Py_XSETREF(*p, newitem);
157157
return 0;
158158
}
@@ -1367,7 +1367,7 @@ void GraalPyPrivate_Tuple_Dealloc(PyTupleObject* self) {
13671367
}
13681368

13691369
PyObject **
1370-
GraalPyPrivate_Tuple_GetItems(PyObject *op)
1370+
GraalPyTuple_ITEMS(PyObject *op)
13711371
{
13721372
PyObject **ob_item;
13731373
if (points_to_py_handle_space(op)) {
@@ -1391,16 +1391,14 @@ GraalPyPrivate_Tuple_GetItems(PyObject *op)
13911391
* PyTuple_GET_ITEM.
13921392
*/
13931393
PyObject*
1394-
_PyTuple_GET_ITEM(PyObject* a, Py_ssize_t b) {
1395-
PyObject **ob_item = GraalPyPrivate_Tuple_GetItems(a);
1394+
GraalPyTuple_GET_ITEM(PyObject* a, Py_ssize_t b) {
1395+
PyObject **ob_item = GraalPyTuple_ITEMS(a);
13961396
if (ob_item) {
13971397
return ob_item[b];
13981398
}
13991399
return NULL; // an exception has happend during transtion
14001400
}
14011401

1402-
#undef PyTuple_SET_ITEM
1403-
// Export PyTuple_SET_ITEM as regular API function to use in PyO3 and others
1404-
void PyTuple_SET_ITEM(PyObject* op, Py_ssize_t index, PyObject* value) {
1405-
graalpy_tuple_set_item(op, index, value);
1402+
void GraalPyTuple_SET_ITEM(PyObject* op, Py_ssize_t index, PyObject* value) {
1403+
GraalPyTuple_ITEMS(op)[index] = value;
14061404
}

graalpython/lib-graalpython/patches/nanobind.patch

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -905,11 +905,10 @@ index 0000000..b61486b
905905
+-U __Py_SwappedOp
906906
+-U __Py_TrueStruct
907907
+-U __Py_VaBuildValue_SizeT
908-
+-U GraalPyPrivate_List_GetItems
909-
+-U GraalPyPrivate_Sequence_Fast_ITEMS
910-
+-U GraalPyPrivate_Tuple_GetItems
908+
+-U GraalPyList_ITEMS
909+
+-U GraalPyTuple_ITEMS
911910
+-U GraalPyPrivate_SIZE
912-
+-U __PyTuple_GET_ITEM
911+
+-U GraalPyTuple_GET_ITEM
913912
+-U __Py_EllipsisObjectReference
914913
+-U __Py_FalseStructReference
915914
+-U __Py_NoneStructReference

0 commit comments

Comments
 (0)