Skip to content

Commit bee8a2c

Browse files
Use PyO3 main & enable c-api tests
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 870ad2d commit bee8a2c

40 files changed

Lines changed: 498 additions & 63 deletions

.cspell.dict/cpython.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ nvars
169169
opname
170170
opnames
171171
orelse
172+
osmodule
172173
outparam
173174
outparm
174175
paramfunc

.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
@@ -20,7 +20,7 @@ rustpython-stdlib = {workspace = true, features = ["threading"] }
2020
rustpython-pylib = { workspace = true }
2121

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

2525
[lints]
2626
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
@@ -37,7 +37,7 @@ pub unsafe extern "C" fn PyMapping_Items(obj: *mut PyObject) -> *mut PyObject {
3737
})
3838
}
3939

40-
#[cfg(false)]
40+
#[cfg(test)]
4141
mod tests {
4242
use pyo3::prelude::*;
4343
use pyo3::types::{PyDict, PyMapping, PyMappingMethods, PyTuple};

crates/capi/src/abstract_/number.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ pub unsafe extern "C" fn PyNumber_Index(obj: *mut PyObject) -> *mut PyObject {
1010
with_vm(|vm| unsafe { &*obj }.try_index(vm))
1111
}
1212

13+
#[unsafe(no_mangle)]
14+
pub unsafe extern "C" fn PyNumber_Long(obj: *mut PyObject) -> *mut PyObject {
15+
with_vm(|vm| unsafe { &*obj }.try_int(vm))
16+
}
17+
1318
#[unsafe(no_mangle)]
1419
pub unsafe extern "C" fn PyNumber_Lshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject {
1520
with_vm(|vm| vm._lshift(unsafe { &*o1 }, unsafe { &*o2 }))
@@ -30,7 +35,7 @@ pub unsafe extern "C" fn PyNumber_Subtract(o1: *mut PyObject, o2: *mut PyObject)
3035
with_vm(|vm| vm._sub(unsafe { &*o1 }, unsafe { &*o2 }))
3136
}
3237

33-
#[cfg(false)]
38+
#[cfg(test)]
3439
mod tests {
3540
use pyo3::prelude::*;
3641

crates/capi/src/abstract_/sequence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ pub unsafe extern "C" fn PySequence_In(obj: *mut PyObject, value: *mut PyObject)
177177
unsafe { PySequence_Contains(obj, value) }
178178
}
179179

180-
#[cfg(false)]
180+
#[cfg(test)]
181181
mod tests {
182182
use pyo3::prelude::*;
183183
use pyo3::types::{PyAnyMethods, PyDict, PyList, PySequence, PySequenceMethods, PyTuple};

0 commit comments

Comments
 (0)