-
Notifications
You must be signed in to change notification settings - Fork 187
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
Entry::new returns Err when entry point isn't found #390
Conversation
Unfortunately docs are not explicitly (build-)tested as part of `--all-targets` allowing broken code to slip in as shown by ash-rs#390. Also remove the `rust` listing type which is the default, leaving only `no_run` (until the CI has a loadable Vulkan library).
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.
Cool, thanks! Not as easy as it seems, one of the changes is in a generated file and will get lost on the next regeneration attempt. I think the CI lost its ability to run the generator and error if that results in a diff, or am I misremembering?
CI now spots missed code regeneration in #393. |
I reworked it a bit so only |
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.
Have you tested this change for your use-case? As it stands a failure to load any symbol is only handled after new_custom
completes, meaning get_instance_proc_addr
is inevitably called leading to the original panic. In other words, in its current form this PR makes no difference to the original issue you attempt to solve.
As stated before just move load
to entry.rs
and return a Result
there, that can subsequently be forwarded in new_custom
. Then you can also use a &'static str
again, though holding on to the original libloading::Error
(and pairing it with the symbol name) is even better.
Did you mean move |
Only the |
Unfortunately, it's proving impossible to create a |
Since the name is hardcoded (and where possible autogenerated may you want to extend this error to other places in the future) I'm not opposed to |
Ok, another attempt... |
Should be good now, thanks :) |
* ci: Test docs in addition to `cargo t --all-targets` Unfortunately docs are not explicitly (build-)tested as part of `--all-targets` allowing broken code to slip in as shown by #390. Also remove the `rust` listing type which is the default, leaving only `no_run` (until the CI has a loadable Vulkan library). * ash: Fix errors and warnings in (now tested) documentation comments
Does anything else need to be done here? |
Sorry I forgot about it, looks good. LGTM |
// TODO: Make this a &'static CStr once CStr::from_bytes_with_nul_unchecked is const | ||
static ENTRY_POINT: &[u8] = b"vkGetInstanceProcAddr\0"; | ||
|
||
Ok(vk::StaticFn { | ||
get_instance_proc_addr: unsafe { | ||
let cname = CStr::from_bytes_with_nul_unchecked(ENTRY_POINT); |
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.
Unfortunately, it's proving impossible to create a
&'static CStr
because the functions needed for this aren'tconst
. To do this would requirelazy_static
as an additional dependency. I can either makeMissingEntryPoint
contain a&'static [u8]
, or go back to ownedCString
.
2 years later I'm rather curious why I didn't notice the TODO (and static
vs const
), as the ENTRY_POINT
string literal could be inlined in the CStr::from_bytes_with_nul_unchecked()
call as I had done myself in #379 just a week before this PR was opened 😬
At this point I'm assuming it doesn't matter whether to assign to a let
binding or change this to const
(will be more verbose with forced const CNAME: &CStr
type), as the function call is hopefully inlined either way? (this does matter for public symbols though, but that's a different beast)
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'd expect all of the above to compile down the same, yeah. Might as well favor clarity.
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.
@Ralith What would you consider more clear for these one-off inline named bindings, const
or let
?
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 think it's best practice to favor let
when it's applicable.
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.
Fair enough, I can't imagine the compiler treating a fully-const
path any different no matter whether it's via a let
binding, inlined completely, or assigned to a const
.
Fixes #387. The error is returned by
StaticFn::load
and then propagated byEntryCustom::new_custom
andEntry::new
.