Skip to content

Commit

Permalink
Introduce DDOG_CHARSLICE_C_BARE and undo change to `DDOG_CHARSLICE_…
Browse files Browse the repository at this point in the history
…C` helper

**What does this PR do?**

This PR introduces a new `DDOG_CHARSLICE_C_BARE` helper, as well
as undoes the change to `DDOG_CHARSLICE_C` from
https://github.com/DataDog/libdatadog/pull/305/files#diff-5c00b9c49c81bf0d0a754e0bcc6e0add4fe849bf0ea4a4d1ebfac8f698150f0b

There are now two helpers: `DDOG_CHARSLICE_C` that includes the
`(ddog_CharSlice)` cast and `DDOG_CHARSLICE_C_BARE` which doesn't.

**Motivation:**

In a nutshell @bwoebi explained to me that on Windows there's times
where you need to use `(ddog_CharSlice) {.ptr = ..., .len = ...}` and
others where you need to use `{.ptr = ..., .len = ...}` and cannot
include the cast.

Thus in #305 we tweaked the helper to never have `(ddog_CharSlice)`,
with the intention of using `(ddog_CharSlice) DDOG_CHARSLICE_C(...)`
some times, and `DDOG_CHARSLICE_C(...)` the other times.

But... this had the downside of making some of our Ruby Profiler code
really ugly, as we'd need to move from `DDOG_CHARSLICE_C` to
`(CharSlice) DDOG_CHARSLICE_C` in a lot of cases.

Thus, this PR introduces one helper for each variant, so that
we always have a nice user-friendly option for each case, and avoid
needing to sprinkle casts.

**Additional Notes:**

Arghhh C/C++ you always manage to be weird and annoying.

**How to test the change?**

I've tested this change by compiling the Ruby profiler to use this
branch of libdatadog, and validating that it compiles successfully
on Linux.
  • Loading branch information
ivoanjo committed Mar 11, 2024
1 parent 9f0725f commit 68cf7eb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ddcommon-ffi/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ sys_includes = ["stdbool.h", "stddef.h", "stdint.h"]
after_includes = """
#define DDOG_CHARSLICE_C(string) \\
/* NOTE: Compilation fails if you pass in a char* instead of a literal */ {.ptr = "" string, .len = sizeof(string) - 1}
/* NOTE: Compilation fails if you pass in a char* instead of a literal */ ((ddog_CharSlice){ .ptr = "" string, .len = sizeof(string) - 1 })
#define DDOG_CHARSLICE_C_BARE(string) \\
/* NOTE: Compilation fails if you pass in a char* instead of a literal */ { .ptr = "" string, .len = sizeof(string) - 1 }
#if defined __GNUC__
# define DDOG_GNUC_VERSION(major) __GNUC__ >= major
Expand Down

0 comments on commit 68cf7eb

Please sign in to comment.