Use PyO3 main & enable c-api tests (#8000) · RustPython/RustPython@52e13a9 · GitHub
Skip to content

Commit 52e13a9

Browse files
Use PyO3 main & enable c-api tests (#8000)
Enable `abi3t` support in PyO3 Add left over c-api functions Fix PyLong_AsUnsignedLongLongMask Update pyo3 to `0.29` Add `PyInt::as_u64_mask` Fix `PyInt::as_u32_mask`
1 parent f196dc4 commit 52e13a9

38 files changed

Lines changed: 449 additions & 59 deletions

.cspell.dict/cpython.txt

Lines changed: 1 addition & 0 deletions

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ jobs:
343343
with:
344344
openssl: true
345345

346+
# Keep features in sync with update-caches.yml CARGO_ARGS.
346347
- name: build rustpython
347348
run: cargo build --release --verbose --features=threading,jit ${{ env.CARGO_ARGS }}
348349

.github/workflows/update-caches.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ env:
1919
CARGO_PROFILE_TEST_DEBUG: 0
2020
CARGO_PROFILE_DEV_DEBUG: 0
2121
CARGO_PROFILE_RELEASE_DEBUG: 0
22+
# Keep feature list in sync with CI's release build in .github/workflows/ci.yaml.
2223
CARGO_ARGS: --workspace --no-default-features --features stdlib,importlib,stdio,encodings,sqlite,ssl-rustls-aws-lc,host_env,threading,jit --exclude rustpython_wasm --exclude rustpython-compiler-source --exclude rustpython-venvlauncher
2324

2425
jobs:

crates/capi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ rustpython-stdlib = {workspace = true, features = ["threading"] }
2222
rustpython-pylib = { workspace = true }
2323

2424
[dev-dependencies]
25-
pyo3 = { workspace = true, features = ["auto-initialize", "abi3"] }
25+
pyo3 = { workspace = true, features = ["auto-initialize", "abi3t"] }
2626

2727
[lints]
2828
workspace = true

crates/capi/pyo3-rustpython.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
implementation=CPython
2-
version=3.14
1+
implementation=RustPython
2+
version=3.15
33
shared=true
4-
abi3=true
4+
target_abi=RustPython-abi3t-3.15
55
suppress_build_script_link_lines=true

crates/capi/src/abstract_.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,40 @@ pub unsafe extern "C" fn PyObject_Size(obj: *mut PyObject) -> isize {
178178
obj.length(vm)
179179
})
180180
}
181+
182+
#[cfg(test)]
183+
mod tests {
184+
use pyo3::prelude::*;
185+
use pyo3::types::{PyDict, PyString};
186+
187+
#[test]
188+
fn call_method1() {
189+
Python::attach(|py| {
190+
let string = PyString::new(py, "Hello, World!");
191+
assert!(
192+
string
193+
.call_method1("endswith", ("!",))
194+
.unwrap()
195+
.is_truthy()
196+
.unwrap()
197+
);
198+
})
199+
}
200+
201+
#[test]
202+
fn object_set_get_del_item() {
203+
Python::attach(|py| {
204+
let obj = PyDict::new(py).into_any();
205+
obj.set_item("key", "value").unwrap();
206+
assert_eq!(
207+
obj.get_item("key")
208+
.unwrap()
209+
.cast_into::<PyString>()
210+
.unwrap(),
211+
"value"
212+
);
213+
obj.del_item("key").unwrap();
214+
assert!(obj.get_item("key").is_err());
215+
})
216+
}
217+
}

crates/capi/src/abstract_/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub unsafe extern "C" fn PyIter_Send(
8989
})
9090
}
9191

92-
#[cfg(false)]
92+
#[cfg(test)]
9393
mod tests {
9494
use pyo3::prelude::*;
9595
use pyo3::types::{PyAnyMethods, PyIterator, PyList, PySendResult};

crates/capi/src/abstract_/mapping.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ pub unsafe extern "C" fn PyMapping_SetItemString(
194194
})
195195
}
196196

197-
#[cfg(false)]
197+
#[cfg(test)]
198198
mod tests {
199199
use pyo3::prelude::*;
200200
use pyo3::types::{PyDict, PyMapping, PyMappingMethods, PyTuple};

crates/capi/src/abstract_/number.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ pub unsafe extern "C" fn PyNumber_Subtract(o1: *mut PyObject, o2: *mut PyObject)
232232
with_vm(|vm| vm._sub(unsafe { &*o1 }, unsafe { &*o2 }))
233233
}
234234

235-
#[cfg(false)]
235+
#[cfg(test)]
236236
mod tests {
237237
use pyo3::prelude::*;
238238

crates/capi/src/abstract_/sequence.rs

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)