Skip to content

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented Oct 14, 2025

Adds documentation for Libdl.LazyLibrary and related types.

Also extends the C calling manual with an expanded section on using LazyLibrary for lazy library loading, including practical examples of platform-specific libraries, dependency management, lazy path construction, and initialization callbacks. Remove a few oddly confusing or incorrect notes as well.

Also fix a copy oddly implemented as
convert(Vector{LazyLibrary}, convert(Vector{Any}, LazyLibrary[])) from #59233 to just call copy.

🤖 Generated with help by Claude Code.

@vtjnash vtjnash requested a review from staticfloat October 14, 2025 18:10
@vtjnash vtjnash added docs This change adds or pertains to documentation stdlib Julia's standard library labels Oct 14, 2025
Adds documentation for `Libdl.LazyLibrary` and related types.

Also extends the C calling manual with an expanded section on using
`LazyLibrary` for lazy library loading, including practical examples
of platform-specific libraries, dependency management, lazy path
construction, and initialization callbacks. Remove a few oddly confusing
or incorrect notes as well.

Also fix a `copy` oddly implemented as
`convert(Vector{LazyLibrary}, convert(Vector{Any}, LazyLibrary[]))`
from #59233 to just call `copy`.

🤖 Generated with help by Claude Code.
Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good to me!

The dlopen operation is thread-safe: only one thread loads the library, acquired after the
release store of the reference to each dependency from loading of each dependency. Other
tasks block until loading completes. The handle is then cached and reused for all subsequent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you say other tasks, you mean other dlopen() tasks, right? Not all tasks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I guess we should clarify that it is only of this specific library (e.g. so that doing dlopen in parallel is not UB for deadlocks)


#### Lazy Path Construction

For libraries whose paths are determined at runtime, use `LazyLibraryPath`:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make a small note as to why you didn't need to use LazyLibraryPath when doing the OS-specific paths above.

For more details, see the [`Libdl.LazyLibrary`](@ref) documentation.
### Overloading `dlopen` for Custom Types
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this section for? Are you trying to warn other people who might overload dlopen() (like we did for LazyLibrary) or are you saying there's some reason someone might want to overload dlopen() for LazyLibrary itself?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can write your own LazyLibrary-like types. This is documentation for those fools who write LazyLibrary types, like us.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice; maybe say that LazyLibrary is one such type, since I was a little confused at first, thinking this was further useful information under the LazyLibrary umbrella.

@staticfloat
Copy link
Member

Thanks for this Jameson, it's really nicely put together.

@oscardssmith oscardssmith merged commit 298f8ad into master Oct 17, 2025
7 checks passed
@oscardssmith oscardssmith deleted the jn/LazyLibrary-docs branch October 17, 2025 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs This change adds or pertains to documentation stdlib Julia's standard library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants