Skip to content

Commit 742980f

Browse files
committed
graalpy: add implementations for list macro functions
1 parent ff4c108 commit 742980f

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

pyo3-ffi/src/cpython/listobject.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::object::*;
22
#[cfg(not(PyPy))]
33
use crate::pyport::Py_ssize_t;
44

5-
#[cfg(not(PyPy))]
5+
#[cfg(not(any(PyPy, GraalPy)))]
66
#[repr(C)]
77
#[derive(Copy, Clone)]
88
pub struct PyListObject {
@@ -11,7 +11,7 @@ pub struct PyListObject {
1111
pub allocated: Py_ssize_t,
1212
}
1313

14-
#[cfg(PyPy)]
14+
#[cfg(any(PyPy, GraalPy))]
1515
pub struct PyListObject {
1616
pub ob_base: PyObject,
1717
}
@@ -22,20 +22,23 @@ pub struct PyListObject {
2222

2323
/// Macro, trading safety for speed
2424
#[inline]
25-
#[cfg(not(PyPy))]
25+
#[cfg(not(any(PyPy, GraalPy)))]
2626
pub unsafe fn PyList_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject {
2727
*(*(op as *mut PyListObject)).ob_item.offset(i)
2828
}
2929

3030
/// Macro, *only* to be used to fill in brand new lists
3131
#[inline]
32-
#[cfg(not(PyPy))]
32+
#[cfg(not(any(PyPy, GraalPy)))]
3333
pub unsafe fn PyList_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) {
3434
*(*(op as *mut PyListObject)).ob_item.offset(i) = v;
3535
}
3636

3737
#[inline]
3838
#[cfg(not(PyPy))]
3939
pub unsafe fn PyList_GET_SIZE(op: *mut PyObject) -> Py_ssize_t {
40-
Py_SIZE(op)
40+
#[cfg(not(GraalPy))]
41+
return Py_SIZE(op);
42+
#[cfg(GraalPy)]
43+
return _Py_SIZE(op as *mut PyVarObject);
4144
}

pyo3-ffi/src/listobject.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,16 @@ extern "C" {
5353
#[cfg_attr(PyPy, link_name = "PyPyList_AsTuple")]
5454
pub fn PyList_AsTuple(arg1: *mut PyObject) -> *mut PyObject;
5555

56-
// CPython macros exported as functions on PyPy
57-
#[cfg(PyPy)]
56+
// CPython macros exported as functions on PyPy or GraalPy
57+
#[cfg(any(PyPy, GraalPy))]
5858
#[cfg_attr(PyPy, link_name = "PyPyList_GET_ITEM")]
59+
#[cfg_attr(GraalPy, link_name = "PyList_GetItem")]
5960
pub fn PyList_GET_ITEM(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject;
6061
#[cfg(PyPy)]
6162
#[cfg_attr(PyPy, link_name = "PyPyList_GET_SIZE")]
6263
pub fn PyList_GET_SIZE(arg1: *mut PyObject) -> Py_ssize_t;
63-
#[cfg(PyPy)]
64+
#[cfg(any(PyPy, GraalPy))]
6465
#[cfg_attr(PyPy, link_name = "PyPyList_SET_ITEM")]
66+
#[cfg_attr(GraalPy, link_name = "_PyList_SET_ITEM")]
6567
pub fn PyList_SET_ITEM(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject);
6668
}

0 commit comments

Comments
 (0)