-
Notifications
You must be signed in to change notification settings - Fork 9
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
POC for r_lock!
enforcement on the R API
#26
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,17 +229,19 @@ impl Kernel { | |
let mut data = serde_json::Map::new(); | ||
data.insert("text/plain".to_string(), json!("")); | ||
|
||
// Include HTML representation of data.frame | ||
// TODO: Do we need to hold the R lock here? | ||
let value = unsafe { Rf_findVarInFrame(R_GlobalEnv, r_symbol!(".Last.value")) }; | ||
if r_is_data_frame(value) { | ||
match Kernel::to_html(value) { | ||
Ok(html) => data.insert("text/html".to_string(), json!(html)), | ||
Err(error) => { | ||
error!("{:?}", error); | ||
None | ||
}, | ||
}; | ||
r_lock! { | ||
let value = Rf_findVarInFrame(R_GlobalEnv, r_symbol!(".Last.value")); | ||
|
||
// Include HTML representation of data.frame | ||
if r_is_data_frame(value) { | ||
match Kernel::to_html(value) { | ||
Ok(html) => data.insert("text/html".to_string(), json!(html)), | ||
Err(error) => { | ||
error!("{:?}", error); | ||
None | ||
}, | ||
}; | ||
} | ||
} | ||
Comment on lines
-232
to
245
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. Missing lock when finishing a code execution request |
||
|
||
if let Err(err) = self | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// r_api.rs | ||
// | ||
// Copyright (C) 2023 Posit Software, PBC. All rights reserved. | ||
// | ||
// | ||
|
||
#![allow(non_snake_case)] | ||
|
||
pub use libR_sys::SEXP; | ||
|
||
#[harp_macros::lock] | ||
pub fn Rf_xlength(x: SEXP) -> isize { | ||
unsafe { libR_sys::Rf_xlength(x) } | ||
} | ||
|
||
#[harp_macros::lock] | ||
pub fn TYPEOF(x: SEXP) -> std::os::raw::c_int { | ||
unsafe { libR_sys::TYPEOF(x) } | ||
} | ||
|
||
#[harp_macros::lock] | ||
pub fn Rf_protect(x: SEXP) -> SEXP { | ||
unsafe { libR_sys::Rf_protect(x) } | ||
} | ||
|
||
#[harp_macros::lock] | ||
pub fn Rf_unprotect(count: i32) { | ||
unsafe { libR_sys::Rf_unprotect(count) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,9 @@ use crate::exec::RFunction; | |
use crate::exec::RFunctionExt; | ||
use crate::object::RObject; | ||
use crate::protect::RProtect; | ||
use crate::r_api::Rf_xlength; | ||
use crate::r_api::SEXP; | ||
use crate::r_api::TYPEOF; | ||
use crate::r_symbol; | ||
use crate::symbol::RSymbol; | ||
use crate::vector::CharacterVector; | ||
|
@@ -87,6 +90,14 @@ impl Sxpinfo { | |
} | ||
} | ||
|
||
pub fn r_length(x: SEXP) -> isize { | ||
Rf_xlength(x) | ||
} | ||
|
||
pub fn r_typeof(x: SEXP) -> u32 { | ||
TYPEOF(x) as u32 | ||
} | ||
|
||
pub fn r_assert_type(object: SEXP, expected: &[u32]) -> Result<u32> { | ||
let actual = r_typeof(object); | ||
|
||
|
@@ -107,7 +118,7 @@ pub unsafe fn r_assert_capacity(object: SEXP, required: usize) -> Result<usize> | |
} | ||
|
||
pub fn r_assert_length(object: SEXP, expected: usize) -> Result<usize> { | ||
let actual = unsafe { Rf_xlength(object) as usize }; | ||
let actual = r_length(object) as usize; | ||
Comment on lines
-110
to
+121
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. Should allow us to remove some |
||
if actual != expected { | ||
return Err(Error::UnexpectedLength(actual, expected)); | ||
} | ||
|
@@ -207,7 +218,7 @@ pub fn r_vec_shape(value: SEXP) -> String { | |
let dim = RObject::new(Rf_getAttrib(value, R_DimSymbol)); | ||
|
||
if r_is_null(*dim) { | ||
format!("{}", Rf_xlength(value)) | ||
format!("{}", r_length(value)) | ||
} else { | ||
let dim = IntegerVector::new_unchecked(*dim); | ||
dim.iter().map(|d| d.unwrap()).join(", ") | ||
|
@@ -224,13 +235,6 @@ pub fn r_altrep_class(object: SEXP) -> String { | |
format!("{}::{}", pkg, klass) | ||
} | ||
|
||
pub fn r_typeof(object: SEXP) -> u32 { | ||
// SAFETY: The type of an R object is typically considered constant, | ||
// and TYPEOF merely queries the R type directly from the SEXPREC struct. | ||
let object = object.into(); | ||
unsafe { TYPEOF(object) as u32 } | ||
} | ||
|
||
pub unsafe fn r_type2char<T: Into<u32>>(kind: T) -> String { | ||
let kind = Rf_type2char(kind.into()); | ||
let cstr = CStr::from_ptr(kind); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Missing lock when accessing the prompt global options