-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor prompt detection #51
Changes from all commits
06fee84
3c81fbc
9cc7658
956a120
9692567
91612f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// session.rs | ||
// | ||
// Copyright (C) 2023 Posit Software, PBC. All rights reserved. | ||
// | ||
// | ||
|
||
use std::sync::Once; | ||
|
||
use libR_sys::*; | ||
|
||
use crate::utils::r_try_eval_silent; | ||
use crate::vector::integer_vector::IntegerVector; | ||
use crate::vector::Vector; | ||
|
||
// Globals | ||
static SESSION_INIT: Once = Once::new(); | ||
static mut NFRAME_CALL: usize = 0; | ||
|
||
pub fn r_n_frame() -> crate::error::Result<i32> { | ||
SESSION_INIT.call_once(init_interface); | ||
|
||
unsafe { | ||
let ffi = r_try_eval_silent(NFRAME_CALL as SEXP, R_BaseEnv)?; | ||
let n_frame = IntegerVector::new(ffi)?; | ||
Ok(n_frame.get_unchecked_elt(0)) | ||
} | ||
} | ||
|
||
fn init_interface() { | ||
unsafe { | ||
let nframe_call = crate::r_lang!(crate::r_symbol!("sys.nframe")); | ||
R_PreserveObject(nframe_call); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we can preserve these using our own internal mechanism (to avoid accumulating a potentially large "bag" of preserved objects)? Is that worth doing? That is, have an internal "precious list" that we append / remove these from, which is itself preserved? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the main advantage of preserving in local storage instead of the global precious list is that it makes it easier to analyse the source of leaks using r-lib/memtools. |
||
NFRAME_CALL = nframe_call as usize; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth considering putting together tools for interacting with
R_GlobalContext
to learn these sorts of things about the call stack? (I think that might be necessary in the future, for certain intermediate frames that R doesn't include in the user-facing R functions?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a possibility. Probably best to avoid if we can though?