Skip to content

Commit 3a6b887

Browse files
committed
Add test so that heap_frame can be safely compared with memcmp
1 parent 7d0acaa commit 3a6b887

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Diff for: ext/datadog_profiling_native_extension/heap_recorder.c

+7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ typedef struct {
4141
int32_t line;
4242
} heap_frame;
4343

44+
// We use memcmp/st_hash below to compare/hash an entire array of heap_frames, so want to make sure no padding is added
45+
// We could define the structure to be packed, but that seems even weirder across compilers, and this seems more portable?
46+
_Static_assert(
47+
sizeof(heap_frame) == sizeof(ddog_prof_ManagedStringId) * 2 + sizeof(int32_t),
48+
"Size of heap_frame does not match the sum of its members. Padding detected."
49+
);
50+
4451
// A compact representation of a stacktrace for a heap allocation.
4552
// Used to dedup heap allocation stacktraces across multiple objects sharing the same allocation location.
4653
typedef struct {

0 commit comments

Comments
 (0)