Skip to content

Commit d978606

Browse files
committed
Make r_safely() a function rather than a macro
1 parent 3f251a2 commit d978606

File tree

7 files changed

+8
-28
lines changed

7 files changed

+8
-28
lines changed

crates/ark/src/interface.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ use crossbeam::channel::Receiver;
4646
use crossbeam::channel::Sender;
4747
use crossbeam::channel::TryRecvError;
4848
use crossbeam::select;
49+
use harp::exec::r_safely;
4950
use harp::exec::r_source;
5051
use harp::exec::RFunction;
5152
use harp::exec::RFunctionExt;
5253
use harp::object::RObject;
53-
use harp::r_safely;
5454
use harp::r_symbol;
5555
use harp::routines::r_register_routines;
5656
use harp::session::r_poke_option_show_error_messages;
@@ -1045,7 +1045,7 @@ extern "C" fn r_read_console(
10451045
hist: c_int,
10461046
) -> i32 {
10471047
let main = unsafe { R_MAIN.as_mut().unwrap() };
1048-
let result = r_safely!(main.read_console(prompt, buf, buflen, hist));
1048+
let result = r_safely(|| main.read_console(prompt, buf, buflen, hist));
10491049

10501050
// NOTE: Keep this function a "Plain Old Frame" without any
10511051
// destructors. We're longjumping from here in case of interrupt.

crates/ark/src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@ pub use r_task::r_task;
2828
use serde::Deserialize;
2929
use serde::Serialize;
3030

31-
#[macro_export]
32-
macro_rules! r_safely {
33-
($($expr:tt)*) => {{
34-
#[allow(unused_unsafe)]
35-
ark::r_task::safely(|| {
36-
unsafe { $($expr)* } }
37-
)
38-
}}
39-
}
40-
4131
#[derive(Debug, Eq, PartialEq, Copy, Clone, Default, Deserialize, Serialize)]
4232
pub struct Position {
4333
row: usize,

crates/ark/src/r_task.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::sync::Mutex;
1010
use std::time::Duration;
1111

1212
use crossbeam::channel::bounded;
13-
use harp::exec::safely;
13+
use harp::exec::r_safely;
1414
use harp::test::R_TASK_BYPASS;
1515

1616
use crate::interface::RMain;
@@ -67,7 +67,7 @@ where
6767
{
6868
let result = Arc::clone(&result);
6969
let closure = move || {
70-
let res = safely(f);
70+
let res = r_safely(f);
7171
*result.lock().unwrap() = Some(res);
7272
};
7373

crates/harp/src/exec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ pub fn r_parse(code: &str) -> Result<RObject> {
429429
// This could be implemented with R interrupts but would require to
430430
// unsafely jump over the Rust stack, unless we wrapped all R API functions
431431
// to return an Option.
432-
pub fn safely<'env, F, T>(f: F) -> T
432+
pub fn r_safely<'env, F, T>(f: F) -> T
433433
where
434434
F: FnOnce() -> T,
435435
F: 'env,

crates/harp/src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@ pub use harp_macros::register;
2727

2828
pub fn initialize() {}
2929

30-
#[macro_export]
31-
macro_rules! r_safely {
32-
($($expr:tt)*) => {{
33-
#[allow(unused_unsafe)]
34-
$crate::exec::safely(|| {
35-
unsafe { $($expr)* } }
36-
)
37-
}}
38-
}
39-
4030
#[macro_export]
4131
macro_rules! with_vector_impl {
4232
($x:expr, $class:ident, $variable:ident, $($code:tt)*) => {{

crates/harp/src/session.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::exec::r_parse;
1515
use crate::object::RObject;
1616
use crate::protect::RProtect;
1717
use crate::r_lang;
18-
use crate::r_safely;
1918
use crate::r_symbol;
2019
use crate::utils::r_normalize_path;
2120
use crate::utils::r_try_eval_silent;

crates/harp/src/test.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::sync::Once;
2020
use libR_sys::*;
2121
use stdext::cargs;
2222

23-
use crate::r_safely;
23+
use crate::exec::r_safely;
2424

2525
// Escape hatch for unit tests
2626
pub static mut R_TASK_BYPASS: bool = false;
@@ -62,9 +62,10 @@ pub fn start_r() {
6262
});
6363
}
6464

65+
// FIXME: Actually run `f` and fix thread safety in tests
6566
pub fn r_test_impl<F: FnMut()>(f: F) {
6667
start_r();
67-
r_safely!(f);
68+
r_safely(|| f);
6869
}
6970

7071
#[macro_export]

0 commit comments

Comments
 (0)