Skip to content
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

Run init function of client lib #250

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: callr
Title: Call R from R
Version: 3.7.3.9000
Version: 3.7.3.9001
Authors@R: c(
person("Gábor", "Csárdi", , "csardi.gabor@gmail.com", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0001-7098-9676")),
Expand Down
1 change: 1 addition & 0 deletions R/load-client.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ load_client_lib <- function(sofile = NULL, pxdir = NULL) {

env <- new.env(parent = emptyenv())
env$.path <- sofile
env$.lib <- lib

mycall <- .Call

Expand Down
20 changes: 12 additions & 8 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ env_file <- NULL
prepare_client_files <- function() {
for (aa in names(client_env$`__callr_data__`$sofile)) {
fn <- client_env$`__callr_data__`$sofile[[aa]]
if (!file.exists(fn)) writeBin(clients[[aa]]$bytes, fn)
if (!file.exists(fn)) {
dir.create(dirname(fn), recursive = TRUE)
writeBin(clients[[aa]]$bytes, fn)
}
}

if (!file.exists(env_file)) {
Expand All @@ -31,15 +34,16 @@ prepare_client_files <- function() {
get_client_files <- function() {
archs <- ls(clients)
vapply(archs, function(aa) {
hash <- substr(clients[[aa]]$md5, 1, 7)

# Filename must be `client.ext` so that `dyn.load()` can find
# the init function
file.path(
tempdir(),
paste0(
"callr-client-",
sub("arch-", "", aa),
"-",
substr(clients[[aa]]$md5, 1, 7),
.Platform$dynlib.ext
)
"callr",
sub("arch-", "", aa), # Might be empty
hash,
paste0("client", .Platform$dynlib.ext)
)
}, character(1))
}
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-load-client.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,20 @@ test_that("set_stdout_file, set_setderr_file", {
ret <- callr::r(do)
expect_equal(ret, c("this is output", "this is error"))
})

test_that("init function of client lib is run", {
pxlib <- r(function() {
as.environment("tools:callr")$`__callr_data__`$pxlib
})

# File name should be `client.SOEXT` so that R can match the init
# function from the name
expect_true(grepl("^client\\.", basename(pxlib$.path)))

# In case R removes the `dynamicLookup` field
skip_on_cran()

# Should be `FALSE` since processx disables dynamic lookup in the
# init function
expect_false(unclass(pxlib$.lib)$dynamicLookup)
})