-
Notifications
You must be signed in to change notification settings - Fork 440
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
c_str!
NUL checks and CBounedStr
#258
base: rust
Are you sure you want to change the base?
Conversation
@ojeda I've seen a weird rustdoc triple error in https://github.com/Rust-for-Linux/linux/runs/2537235143?check_suite_focus=true. I then tried to add
Which doesn't make any sense to me since the same target json is specified but somehow rustc and rustdoc uses different hash. Do you have any clue? |
@nbdd0121, I'm having a hard time convincing myself the extra complexity is worth the benefits they're bringing. (I also think we should only resort in proc macros when no other reasonable alternatives exist.) Would you mind sharing more of your thoughts on this? |
A few reasons:
As for complexity, I am doing a refactoring to rename libmodule to libmacros and move c_str macros there, Hopefully after refactoring the structure will be less complex. |
Also note that the |
This is indeed nice, but I don't think it is essential, especially because it does not affect safety (even though it of course may affect correctness).
Also nice to have, but do we have a case where we'd like to use
Where do we need this? The descriptor table in devices? I'm still not convinced these niceties are worth the extra complexity. I'm especially concerned about when we're trying to push this upstream: I'd rather avoid turning reviewers off if they look at this and think "Woah, we need this much extra code to handle C strings?". (I would certainly feel this way, and do a little bit about modules too...) (Also, apologies for encouraging you to do the work before a discussion [that you rightfully sought in the meeting]. Next time we should discuss beforehand, perhaps on the mailing list or a Github issue before spending time on the implementation.) |
The restriction of
static DEVICE_ID: of_device_id = of_device_id {
compatible: c_bounded_str!("some string").expand_to_char_array()
/* ... */
} (or even define another macro that expand to this, say
It's actually just a few lines. I'ved pushed the refactored code (WIP), you can see it is just a few lines. Much of the code is the infrastructure. With these infrastructure we can actually simplify the |
Some additional justification for vendoring buffer and lit from syn:
|
Will split into multiple PRs. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I tested your PR by merging it into #276. Consider me as this PR's very first customer. Customer is king :) It allows me to eliminate the runtime check that verifies whether the string fits in 128 characters. Also, the unsafe call to A few comments:
let of_match_tbl = OfMatchTable::new(c_bounded_str!("brcm,bcm2835-rng").relax_bound())?; It would be more intuitive if there were no need for
|
I think so. It might make sense to allow using a custom name for the non-existent symbol that is referenced to cause the link error. If using a linker that accepts arbitrary symbol names, maybe even include the assertion itself.
Would the following work?
The |
The |
This comment has been minimized.
This comment has been minimized.
Rust can only use
This is indeed a bit cryptic, but at least it provides some info about the crate and function that fails the assertion. If you specify manually the bound in Perhaps in the future we can have a tool that extracts the callgraph from disassembly or debuginfo and gives you a static stack trace, but that's a large amount of work and probably wouldn't worth the effort until we're upstreamed :) |
Speaking purely from a user's POV, I would prefer to see
True! TBH I'm very happy that this works. Good build time checks are awesome! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
`CBoundedStr<N>` is a `CStr` with length known to be less than `N`. It can be used in cases where a known length limit exists. Signed-off-by: Gary Guo <[email protected]>
Review of
|
Implement
CBoundedStr<N>
.Depends on #257
Depends on #273