Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Add helper for creating CharSlice from a string literal #36

Merged
merged 4 commits into from
Mar 21, 2022

Commits on Mar 17, 2022

  1. Add helper for creating CharSlice from a string literal

    It looks like everyone that uses libddprof has a variant of this
    macro, so I think it makes sense to just have it in `ffi.h`.
    
    This specific implementation is built to only work with string
    literals, aka there's no accidental/unexpected  `strlen` going on.
    ivoanjo committed Mar 17, 2022
    Configuration menu
    Copy the full SHA
    8d1a8ef View commit details
    Browse the repository at this point in the history

Commits on Mar 18, 2022

  1. Improve error message when using ddprof_ffi_CharSlice_from_literal

    This macro relies on a weird trick to fail compilation when you pass
    in a char* and not a literal (the trick is that
    `char *foo = "" "foo";` is valid but `char *bar; char *foo = "" bar;`
    is not), but the error message would be kinda cryptic.
    
    Since most compilers show the macro when the compilation fails,
    I've added a nice comment which gets shown by compilers:
    
    ```
    foo.c: In function 'endpoint_from':
    foo.c:133:27: error: expected '}' before 's'
       byte_slice_from_literal(s);
                               ^
    foo.c:15:113: note: in definition of macro 'byte_slice_from_literal'
       /* NOTE: Compilation fails if you pass in a char* instead of a literal */ ((ddprof_ffi_CharSlice) {.ptr = "" string, .len = sizeof(string) - 1})
                                                                                                                    ^~~~~~
    foo.c:15:91: note: to match this '{'
       /* NOTE: Compilation fails if you pass in a char* instead of a literal */ ((ddprof_ffi_CharSlice) {.ptr = "" string, .len = sizeof(string) - 1})
    ```
    ivoanjo committed Mar 18, 2022
    Configuration menu
    Copy the full SHA
    d20aff4 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    9672ea7 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    04f75dd View commit details
    Browse the repository at this point in the history