Skip to content

Commit 7994e2c

Browse files
committed
PyPy doesn't have pyo3::ffi::PyObject_CallOneArg
1 parent 6ff1c65 commit 7994e2c

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ socket2 = "=0.5"
3939
[target.'cfg(unix)'.dependencies]
4040
libc = "0.2.159"
4141

42+
[build-dependencies]
43+
pyo3-build-config = "=0.23"
44+
4245
[profile.release]
4346
codegen-units = 1
4447
debug = false

build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
pyo3_build_config::use_pyo3_cfgs();
3+
}

src/handles.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ use std::sync::{atomic, Arc};
44
use crate::{
55
event_loop::{EventLoop, EventLoopRunState},
66
log::LogExc,
7-
py::{run_in_ctx, run_in_ctx0, run_in_ctx1},
7+
py::{run_in_ctx, run_in_ctx0},
88
};
99

10+
#[cfg(not(PyPy))]
11+
use crate::py::run_in_ctx1;
12+
1013
pub(crate) trait Handle {
1114
fn run(self: Arc<Self>, py: Python, event_loop: &EventLoop, state: &mut EventLoopRunState);
1215
fn cancel(&self) {}
@@ -119,6 +122,7 @@ impl Handle for CBHandleNoArgs {
119122
impl Handle for CBHandleOneArg {
120123
handle_cancel_impl!();
121124

125+
#[cfg(not(PyPy))]
122126
fn run(self: Arc<Self>, py: Python, event_loop: &EventLoop, _state: &mut EventLoopRunState) {
123127
let ctx = self.context.as_ptr();
124128
let cb = self.callback.as_ptr();
@@ -133,6 +137,22 @@ impl Handle for CBHandleOneArg {
133137
_ = event_loop.log_exception(py, err_ctx);
134138
}
135139
}
140+
141+
#[cfg(PyPy)]
142+
fn run(self: Arc<Self>, py: Python, event_loop: &EventLoop, _state: &mut EventLoopRunState) {
143+
let ctx = self.context.as_ptr();
144+
let cb = self.callback.as_ptr();
145+
let args = (self.arg.clone_ref(py),).into_pyobject(py).unwrap().into_ptr();
146+
147+
if let Err(err) = run_in_ctx!(py, ctx, cb, args) {
148+
let err_ctx = LogExc::cb_handle(
149+
err,
150+
format!("Exception in callback {:?}", self.callback.bind(py)),
151+
PyHandle { handle: self }.into_py_any(py).unwrap(),
152+
);
153+
_ = event_loop.log_exception(py, err_ctx);
154+
}
155+
}
136156
}
137157

138158
#[pyclass(frozen, name = "CBHandle", module = "rloop._rloop")]

src/py.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ macro_rules! run_in_ctx0 {
6464
};
6565
}
6666

67+
#[cfg(not(PyPy))]
6768
macro_rules! run_in_ctx1 {
6869
($py:expr, $ctx:expr, $cb:expr, $arg:expr) => {
6970
unsafe {
@@ -88,4 +89,6 @@ macro_rules! run_in_ctx {
8889

8990
pub(crate) use run_in_ctx;
9091
pub(crate) use run_in_ctx0;
92+
93+
#[cfg(not(PyPy))]
9194
pub(crate) use run_in_ctx1;

0 commit comments

Comments
 (0)