Skip to content

Preserve namespaces as much as possible on reloads - #133

Merged
jimhester merged 10 commits into
r-lib:masterfrom
lionel-:fix-dangling
Jan 19, 2021
Merged

jimhester merged 10 commits into
r-lib:masterfrom
lionel-:fix-dangling

Conversation

@lionel-

@lionel- lionel- commented Nov 10, 2020

Copy link
Copy Markdown
Member

The current reloading mechanism unloads previously loaded namespaces, including the SO / DLL. This is a source of crash in case of lingering references to the namespace environments as the native routines from unloaded SOs are no longer in memory. To work around this, pkgload updates all imports in reverse dependencies of the reloaded package. However, this workaround is not exhaustive. For instance, using devtools::test() with the ellipsis package causes a crash because of an ellipsis function is called from on.exit() after a load_all().

With this PR, load_all() now preserves existing namespaces as much as possible. In particular, it doesn't unload the package's shared library and keeps it loaded instead. When reloading, a copy of the SO for the new namespace is loaded from a temporary location. These temporary SOs are only unloaded on GC and deleted from their temporary location via a weak reference attached to the namespace.

This mechanism ensures that lingering references to the namespace keep working as expected. Consequently the namespace propagation routine that was added to pkgload as a workaround (see #59) has been removed.

Note that .Call() invokations that pass a string symbol rather than a structured symbol may keep crashing, because R will look into the most recently loaded SO of a given name. Since symbol registration is now the norm, I don't expect this to cause much trouble.

Comment thread R/imports-env.r Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants