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

Preserve namespaces as much as possible on reloads #133

Merged
merged 10 commits into from
Jan 19, 2021

Conversation

lionel-
Copy link
Member

@lionel- lionel- commented Nov 10, 2020

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.

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