Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell.dict/cpython.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ nvars
opname
opnames
orelse
osmodule
outparam
outparm
paramfunc
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ jobs:
with:
openssl: true

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

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/update-caches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ env:
CARGO_PROFILE_TEST_DEBUG: 0
CARGO_PROFILE_DEV_DEBUG: 0
CARGO_PROFILE_RELEASE_DEBUG: 0
# Keep feature list in sync with CI's release build in .github/workflows/ci.yaml.
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

jobs:
Expand Down
16 changes: 5 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
flamescope = { version = "0.1.2", optional = true }

rustls = { workspace = true, optional = true }
rustls-graviola = { workspace = true, optional = true }

Check warning on line 52 in Cargo.toml

View workflow job for this annotation

GitHub Actions / cargo shear

shear/misplaced_optional_dependency

misplaced optional dependency `rustls-graviola` (remove the `optional` flag and move to `[dev-dependencies]`)

[target.'cfg(windows)'.dependencies]
libc = { workspace = true }
Expand Down Expand Up @@ -127,6 +127,7 @@

[patch.crates-io]
parking_lot_core = { git = "https://github.com/youknowone/parking_lot", branch = "rustpython" }
pyo3-ffi = { git = "https://github.com/PyO3/pyo3" }
# REDOX START, Uncomment when you want to compile/check with redoxer
# REDOX END

Expand Down Expand Up @@ -278,7 +279,7 @@
proc-macro2 = "1.0.105"
psm = "0.1"
pymath = { version = "0.2.0", features = ["mul_add", "malachite-bigint", "complex"] }
pyo3 = "0.28"
pyo3 = { git = "https://github.com/PyO3/pyo3" }
quote = "1.0.45"
radium = "1.1.1"
rand = "0.10"
Expand Down
2 changes: 1 addition & 1 deletion crates/capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ rustpython-vm = { workspace = true, features = ["threading", "compiler"] }
rustpython-stdlib = {workspace = true, features = ["threading"] }

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

[lints]
workspace = true
Expand Down
6 changes: 3 additions & 3 deletions crates/capi/pyo3-rustpython.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
implementation=CPython
version=3.14
implementation=RustPython
version=3.15
shared=true
abi3=true
target_abi=RustPython-abi3t-3.15
suppress_build_script_link_lines=true
37 changes: 37 additions & 0 deletions crates/capi/src/abstract_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,40 @@ pub unsafe extern "C" fn PyObject_Size(obj: *mut PyObject) -> isize {
obj.length(vm)
})
}

#[cfg(test)]
mod tests {
use pyo3::prelude::*;
use pyo3::types::{PyDict, PyString};

#[test]
fn call_method1() {
Python::attach(|py| {
let string = PyString::new(py, "Hello, World!");
assert!(
string
.call_method1("endswith", ("!",))
.unwrap()
.is_truthy()
.unwrap()
);
})
}

#[test]
fn object_set_get_del_item() {
Python::attach(|py| {
let obj = PyDict::new(py).into_any();
obj.set_item("key", "value").unwrap();
assert_eq!(
obj.get_item("key")
.unwrap()
.cast_into::<PyString>()
.unwrap(),
"value"
);
obj.del_item("key").unwrap();
assert!(obj.get_item("key").is_err());
})
}
}
2 changes: 1 addition & 1 deletion crates/capi/src/abstract_/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub unsafe extern "C" fn PyIter_Send(
})
}

#[cfg(false)]
#[cfg(test)]
mod tests {
use pyo3::prelude::*;
use pyo3::types::{PyAnyMethods, PyIterator, PyList, PySendResult};
Expand Down
2 changes: 1 addition & 1 deletion crates/capi/src/abstract_/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub unsafe extern "C" fn PyMapping_Items(obj: *mut PyObject) -> *mut PyObject {
})
}

#[cfg(false)]
#[cfg(test)]
mod tests {
use pyo3::prelude::*;
use pyo3::types::{PyDict, PyMapping, PyMappingMethods, PyTuple};
Expand Down
2 changes: 1 addition & 1 deletion crates/capi/src/abstract_/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub unsafe extern "C" fn PyNumber_Subtract(o1: *mut PyObject, o2: *mut PyObject)
with_vm(|vm| vm._sub(unsafe { &*o1 }, unsafe { &*o2 }))
}

#[cfg(false)]
#[cfg(test)]
mod tests {
use pyo3::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion crates/capi/src/abstract_/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub unsafe extern "C" fn PySequence_In(obj: *mut PyObject, value: *mut PyObject)
unsafe { PySequence_Contains(obj, value) }
}

#[cfg(false)]
#[cfg(test)]
mod tests {
use pyo3::prelude::*;
use pyo3::types::{PyAnyMethods, PyDict, PyList, PySequence, PySequenceMethods, PyTuple};
Expand Down
2 changes: 1 addition & 1 deletion crates/capi/src/bytearrayobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub unsafe extern "C" fn PyByteArray_Resize(bytearray: *mut PyObject, len: isize
})
}

#[cfg(false)]
#[cfg(test)]
mod tests {
use pyo3::prelude::*;
use pyo3::types::{PyByteArray, PyBytes};
Expand Down
9 changes: 4 additions & 5 deletions crates/capi/src/bytesobject.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::PyObject;
use crate::object::define_py_check;
use crate::pystate::with_vm;
use crate::{PyObject, pystate::with_vm};
use core::ffi::c_char;
use rustpython_vm::builtins::PyBytes;

Expand Down Expand Up @@ -46,21 +45,21 @@ pub unsafe extern "C" fn PyBytes_AsString(bytes: *mut PyObject) -> *mut c_char {
})
}

#[cfg(false)]
#[cfg(test)]
mod tests {
use pyo3::prelude::*;
use pyo3::types::PyBytes;

#[test]
fn test_bytes() {
fn bytes() {
Python::attach(|py| {
let bytes = PyBytes::new(py, b"Hello, World!");
assert_eq!(bytes.as_bytes(), b"Hello, World!");
})
}

#[test]
fn test_bytes_uninit() {
fn bytes_uninit() {
Python::attach(|py| {
let bytes = PyBytes::new_with(py, 13, |data| {
data.copy_from_slice(b"Hello, World!");
Expand Down
6 changes: 3 additions & 3 deletions crates/capi/src/ceval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ pub extern "C" fn PyEval_GetBuiltins() -> *mut PyObject {
})
}

#[cfg(false)]
#[cfg(test)]
mod tests {
use pyo3::exceptions::PyException;
use pyo3::prelude::*;

#[test]
fn test_code_eval() {
fn code_eval() {
Python::attach(|py| {
let result = py.eval(c"1 + 1", None, None).unwrap();
assert_eq!(result.extract::<u32>().unwrap(), 2);
})
}

#[test]
fn test_code_run_exception() {
fn code_run_exception() {
Python::attach(|py| {
let err = py.run(c"raise Exception()", None, None).unwrap_err();
assert!(err.is_instance_of::<PyException>(py));
Expand Down
4 changes: 2 additions & 2 deletions crates/capi/src/complexobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ pub unsafe extern "C" fn PyComplex_ImagAsDouble(obj: *mut PyObject) -> c_double
with_vm(|vm| try_to_complex(vm, unsafe { &*obj }).map(|complex| complex.im))
}

#[cfg(false)]
#[cfg(test)]
mod tests {
use pyo3::prelude::*;
use pyo3::types::PyComplex;

#[test]
fn test_py_int() {
fn py_int() {
Python::attach(|py| {
let number = PyComplex::from_doubles(py, 1.0, 2.0);
assert_eq!(number.real(), 1.0);
Expand Down
31 changes: 31 additions & 0 deletions crates/capi/src/critical_section.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::PyObject;

#[repr(C)]
pub struct PyCriticalSection;

#[repr(C)]
pub struct PyCriticalSection2;

#[unsafe(no_mangle)]
pub extern "C" fn PyCriticalSection_Begin(c: *mut PyCriticalSection, op: *mut PyObject) {
let _ = (c, op);
}

#[unsafe(no_mangle)]
pub extern "C" fn PyCriticalSection_End(c: *mut PyCriticalSection) {
let _ = c;
}

#[unsafe(no_mangle)]
pub extern "C" fn PyCriticalSection2_Begin(
c: *mut PyCriticalSection2,
a: *mut PyObject,
b: *mut PyObject,
) {
let _ = (c, a, b);
}

#[unsafe(no_mangle)]
pub extern "C" fn PyCriticalSection2_End(c: *mut PyCriticalSection2) {
let _ = c;
}
4 changes: 2 additions & 2 deletions crates/capi/src/descrobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub unsafe extern "C" fn PyDictProxy_New(mapping: *mut PyObject) -> *mut PyObjec
})
}

#[cfg(false)]
#[cfg(test)]
mod tests {
use pyo3::prelude::*;
use pyo3::types::{PyDict, PyInt, PyMappingProxy};
Expand All @@ -23,7 +23,7 @@ mod tests {
dict.set_item("x", 7).unwrap();

let mapping = dict.as_mapping();
let proxy = PyMappingProxy::new(py, &mapping);
let proxy = PyMappingProxy::new(py, mapping);
let value = proxy.get_item("x").unwrap().cast_into::<PyInt>().unwrap();
assert_eq!(value, 7);
})
Expand Down
Loading
Loading