Skip to content
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

Fix: Compilation error when using CTFType::String{,NoWrite} #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

skoudmar
Copy link

@skoudmar skoudmar commented Oct 1, 2024

Previously the rust type was std::ffi::CStr which is similar to str and does not have known size at compile-time and cannot be used as a function argument. Use reference &CStr instead.

Tracepoint definition

provider
        .create_class("class")
        .add_field("c_string", CTFType::String)
        .instantiate("tracepoint");

The compile error

   Compiling lttng-test v0.1.0
error[E0277]: the size for values of type `[i8]` cannot be known at compilation time
   --> REDACTED/out/tracepoints.rs:8:46
    |
8   |         pub(in super::super) fn tracepoint<>(a0: ::std::ffi::CStr) {
    |                                              ^^ doesn't have a size known at compile-time
    |
    = help: within `CStr`, the trait `Sized` is not implemented for `[i8]`, which is required by `CStr: Sized`
note: required because it appears within the type `CStr`
   --> HOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ffi/c_str.rs:108:12
    |
108 | pub struct CStr {
    |            ^^^^
help: function arguments must have a statically known size, borrowed types always have a known size
    |
8   |         pub(in super::super) fn tracepoint<>(a0: &::std::ffi::CStr) {
    |                                                  +

error[E0308]: mismatched types
  --> REDACTED/out/tracepoints.rs:10:61
   |
10 |                 super::detail::provider_class_tracepoint_tp(a0)
   |                 ------------------------------------------- ^^ expected `*const i8`, found `CStr`
   |                 |
   |                 arguments to this function are incorrect
   |
   = note: expected raw pointer `*const i8`
                   found struct `CStr`
note: function defined here
  --> REDACTED/out/lttng-tracepoints/tracepoint_library_link_name/tracepoints.rs:4:12
   |
4  |     pub fn provider_class_tracepoint_tp(c_string_arg: *const ::std::os::raw::c_char);
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `lttng-test` (bin "lttng-test") due to 2 previous errors

Previously the rust type was `std::ffi::CStr` which is similar to `str`
and does not have known size at compile-time and cannot be used as a
function argument. Use reference `&CStr` instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant