-
Notifications
You must be signed in to change notification settings - Fork 434
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
rust: error: consider naming for fn
s that parse C bindings' return values
#342
Comments
I don't think parse is a good name; for me parsing should only be used when the source form is textual, binary or some other serialized data. I think it's okay to use |
That is fair -- the meaning I was going for with Actually,
I was referring to
I do not mind shortening |
We can have a live poll in the meeting! :) |
Agreed 100% that we need better naming. Part of the problem here is that these C "result mechanisms" are not named or differentiated explicitly in the kernel itself. In a lot of cases. the error return behaviour isn't even documented in the function docs or signature. I often find myself grepping through a function's existing call sites to figure out how to handle its error return. I think there are three main C "result mechanisms" that need a good name:
|
Agreed! It is a mess. :-/ Which is why I am a quite scared of using So I think either 1) we use safe calls by default (unless we have performance numbers to tell us otherwise), or 2) we document the C side if it is not documented (including adding an explicit
These three are the ones I mention in the OP, taken from another comment of yours. I will edit with the "maps to" to the post. |
Interesting discussion, Miguel 💯 I can see why you'd want to be paranoid about these. But it's certainly not a good demonstration of "The Power of Rust" for the upstream community, rather the opposite! We'd basically be runtime-checking something that should really be a build time check. It could be perceived as going backwards rather than forwards. That said, if we do end up enforcing these invariants with a runtime check (and/or warning), we should still mark these functions as |
Suggestions: Could replace |
Well, for this case, we could do in a semi-automated way :) i.e. we could propose upstream to have these marked somehow in the C side, e.g. int * my_c_function(void) __ret(err_ptr) { ... }
int my_c_function(void) __ret(zero_only) { ... }
int my_c_function(void) __ret(value) { ... } which then would be parsed by a script or perhaps Then a Rust lint (e.g. in |
We could suggest something along these lines upstream, but I'm not holding my breath. If we decide to go that way, I believe it's worth talking to the author of Coccinelle (Julia Lawall) first. She shares our interest in making sure that return values are handled correctly. Perhaps there are Coccinelle scripts that already verify this, which we may piggy-back onto somehow? |
Indeed, talking to Julia would be great, since she probably knows what is already there etc. I can drop her an email. Since we are raising this tomorrow, perhaps somebody else knows too. In any case, given there are already annotations for other things/tools (e.g. for locks, for |
Please do! This is of great interest to me as well. Feel free to put me in CC. |
Yeah, I will Cc you! Actually, I think having a technical meeting on this would be great. We can ask Julia Lawall to join, plus Luc Van Oostenryck ( |
👍 Not sure if a technical meeting is "a thing" in the kernel world. It may have to take the form of an LKML thread. I guess it depends on who is backing you, and how big they are :) |
At the risk of being more magic it could also be something like: __err_ptr(int) my_c_function(void) { ... }
__err_void my_c_function(void) { ... }
__err_int my_c_function(void) { ... } Where |
It isn't; but Rust, GitHub, Zulip, etc. aren't either; and I don't mind being a bit unorthodox ;) More seriously: the discussion in the LKML definitely would happen, but that would come after we have an implementation working, and for that, in turn, I think it is best to ask some folks first to see what they think about it etc. |
That has some advantages indeed; but the downside is it may annoy people that do not care about the annotation, specially if only used for the benefit of Rust :( Ideally it could be used for some C tooling too, but we will see... |
fn
s that parse C bindings' return valuesfn
s that parse C bindings' return values
Closing -- it was more of a discussion-starter rather than an issue (we typically have those in Zulip nowadays), and it is very old anyway. |
Related: #324, #335.
Orthogonal: whether we need the safe version of these, see #283.
Thinking about the
pub(crate)
helpers that help us "parse" return values from C functions, I think we can also improve the names for all these helpers:from_*
does not fit too well (i.e. do not confuse with theError
constructors)._kernel_
does not add information -- we are also the kernel! Nothing instead (or perhaps_c_
or_bindings_
) would be better. I think nothing is OK because these functions are internal torust/kernel/
and will be relatively well-known, since they will be used by most abstractions, so smaller names are better.We need names for at least 3 functions:
decode_ret_ptr() -> Result<*mut T>
: Decodes the return value of C functions that return a pointer or an error value (i.e. the C side usesIS_ERR()
/ERR_PTR()
etc.).decode_ret() -> Result
: Decodes the return value of C functions that only return0
on success, but otherwise do not use the positive side.decode_ret_value() -> Result<c_uint>
: Decodes the return value of C functions that return a positive value on success.File
, so we could instead haveparse_result_fd()
orparse_result_file()
etc.).Possible prefixes:
parse
interpret
transform
to_result
decode
Possible middle nouns:
ret
result
return
c_return
creturn
retval
cretval
Opinions, suggestions, etc. welcome!
The text was updated successfully, but these errors were encountered: