Skip to content

Commit

Permalink
Don't register DLL finaliser for packages that don't have DLLs
Browse files Browse the repository at this point in the history
Closes #176
  • Loading branch information
lionel- committed May 27, 2022
1 parent 9153a1a commit 72f7691
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# pkgload (development version)

* `.dynLibs()` is no longer emptied when package with no DLL is
unloaded (#176).

* The `?` shim no longer interprets `?"/"` as a path (#198).

* rstudioapi is no longer a hard dependency of pkgload (#187).
Expand Down
8 changes: 7 additions & 1 deletion R/load-dll.r
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ onload_assign("load_dll", {

# Delete the temporary SO when the namespace gets garbage collected
dll_path <- dlls[[package]][["path"]]
new_weakref(env, finalizer = ns_finalizer(dll_path))
if (!is_null(dll_path)) {
new_weakref(env, finalizer = ns_finalizer(dll_path))
}

invisible(dlls)
}
Expand All @@ -51,6 +53,10 @@ onload_assign("load_dll", {
ns_finalizer <- function(path) {
force(path)
function(...) {
if (!is_string(path)) {
return(NULL)
}

# Clean up the temporary .so file.
unlink(path)

Expand Down
2 changes: 1 addition & 1 deletion R/namespace-env.r
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ unregister_namespace <- function(name = NULL) {
eapply(ns_env(name), force, all.names = TRUE)

# Remove the item from the registry
do.call(rm, args = list(name, envir = ns_registry()))
env_unbind(ns_registry(), name)
invisible()
}

Expand Down
18 changes: 18 additions & 0 deletions tests/empty/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Package: empty
Version: 1.0.0
Title: title
Description: desc
Authors@R: c(
person("Gábor", "Csárdi", email = "[email protected]", role = c("aut", "cre"))
)
License: GPL-3
Encoding: UTF-8
LazyData: true
ByteCompile: true
RoxygenNote: 7.1.2
Roxygen: list(markdown = TRUE)
Depends:
R (>= 3.2)
Imports:
tools,
utils
2 changes: 2 additions & 0 deletions tests/empty/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by roxygen2: do not edit by hand

Empty file added tests/empty/R/foo.R
Empty file.
9 changes: 9 additions & 0 deletions tests/wipe.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
stopifnot(length(.dynLibs()) > 0)
pkgload::load_all("empty")
stopifnot(length(.dynLibs()) > 0)
gc()
stopifnot(length(.dynLibs()) > 0)
pkgload::load_all("empty")
stopifnot(length(.dynLibs()) > 0)
gc()
stopifnot(length(.dynLibs()) > 0)

0 comments on commit 72f7691

Please sign in to comment.