Skip to content

Commit

Permalink
Fix the misuse of Rf_mkCharLenCE() (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
yutannihilation authored Jan 20, 2024
1 parent 0330a34 commit bb38ad2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
Expand Down Expand Up @@ -62,3 +60,16 @@ jobs:
uses: yutannihilation/r-wasm-actions/build-rwasm@main
with:
packages: "local::./R-package"

# check at least it can build
build-arm64:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-unknown-linux-gnu

- name: Build
run: cargo build --target aarch64-unknown-linux-gnu
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<!-- next-header -->
## [Unreleased] (ReleaseDate)

### Fixed bugs

* Fix misuses of `Rf_mkCharLenCE()` which caused compilation error on ARM64
Linux.

## [v0.2.5] (2024-01-20)

### Breaking changes
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub mod protect;
pub mod sexp;
pub mod unwind_protect;

use std::os::raw::c_char;

pub use error::{Error, Result};
pub use sexp::integer::{IntegerSexp, OwnedIntegerSexp};
pub use sexp::list::{ListSexp, OwnedListSexp};
Expand Down Expand Up @@ -47,7 +49,7 @@ pub fn handle_error(e: crate::error::Error) -> SEXP {
e => unsafe {
let msg = e.to_string();
let r_error = Rf_mkCharLenCE(
msg.as_ptr() as *const i8,
msg.as_ptr() as *const c_char,
msg.len() as i32,
cetype_t_CE_UTF8,
);
Expand Down
7 changes: 6 additions & 1 deletion src/sexp/string.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::ffi::CStr;
use std::os::raw::c_char;

use savvy_ffi::{
cetype_t_CE_UTF8, Rf_mkCharLenCE, Rf_xlength, R_CHAR, SET_STRING_ELT, SEXP, STRING_ELT, STRSXP,
Expand Down Expand Up @@ -96,7 +97,11 @@ unsafe fn str_to_charsxp(v: &str) -> crate::error::Result<SEXP> {
Ok(savvy_ffi::R_NaString)
} else {
crate::unwind_protect(|| {
Rf_mkCharLenCE(v.as_ptr() as *const i8, v.len() as i32, cetype_t_CE_UTF8)
Rf_mkCharLenCE(
v.as_ptr() as *const c_char,
v.len() as i32,
cetype_t_CE_UTF8,
)
})
}
}
Expand Down

0 comments on commit bb38ad2

Please sign in to comment.