-
Notifications
You must be signed in to change notification settings - Fork 184
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
Rename Weak
to LazyPtr
and move it to lazy.rs
#427
Conversation
I think we should have a plan for #285 first. It may be that we start using Also, I think we should sort out what we're doing for Windows, as we're basically implementing |
Agreed with @briansmith here, lets figure out if we need Weak on other targets first. |
Weak
to the NetBSD backendWeak
into a separate module
I have changed this PR and now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a few nits.
@josephlr |
It would be good for somebody to actually test this and any future refactorings of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this implementation. One final question, should this now live in lazy.rs as its now quite similar to LazyUsize
. If we do decide to move it, we should probably rename to LazyPtr
.
Regarding @briansmith's comment:
It would be good for somebody to actually test this and any future refactorings of
Weak
on a NetBSD machine.
Could we add a test that invokes this on Linux? Might be better than nothing. Could look like a tests/linux_dlsym.rs
// Only test on Linux/Android
#![cfg(any(target_os = "linux", target_os = "android"))]
#[path = "../src/lazy.rs"]
mod lazy;
use lazy::LazyPtr;
static GETRANDOM: LazyPtr = LazyPtr::new();
fn dlsym_getrandom() -> *mut c_void {
static NAME: &[u8] = b"getrandom\0";
let name_ptr = NAME.as_ptr() as *const libc::c_char;
unsafe { libc::dlsym(libc::RTLD_DEFAULT, name_ptr) }
}
fn getrandom_impl(dest: &mut [u8]) -> Result<(), Error> {
let fptr = GETRANDOM.get(dlsym_getrandom).unwrap();
...
}
mod common;
No need to add it if you don't think the test is maintainable or its too much work.
Weak
into a separate moduleWeak
to LazyPtr
and move it to lazy.rs
Good observation! Although there is a certain difference between |
I do think having the test run on --linux-gnu (where we know dlsym makes sense) is a good idea.
Note that we should actually call the function through |
It seems like for both of those, we're close to deciding now to use |
The result is cleaner and this approach does not need the
I would prefer to have a proper VM-based testing implemented in a separate PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to have a proper VM-based testing implemented in a separate PR.
Sounds good to me.
Currently the
Weak
type is used only by the NetBSD backend, but in future it may be used by other backends. To simplify code a bit and prepare for potential use on Windows,Weak
now accepts a "pointer initialization function" instead of a function name, i.e. it now works similarly toLazyUsize
andLazyBool
.