common: replace container_of with a C++ safe implementation
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 10 Jun 2022 19:10:32 +0000 (15:10 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 13 Jun 2022 20:34:47 +0000 (16:34 -0400)
commit0114db0ec2407029052eb61a0189c9b1cd64d520
treef93ba82c9e93fe1ad959fde84628694b6b8ac012
parent3691d312bcf4dc2cc15f0ecb1f0e2fd2f34315b8
common: replace container_of with a C++ safe implementation

As more code moves to a more idiomatic C++ style, structures like
typically end up becoming classes that use different access controls,
virtual functions, etc. This, in turn, makes them adopt a non standard
layout and causes GCC and clang to emit the following warning when
container_of is used:

error: 'offsetof' within non-standard-layout type 'foo' is conditionally-supported [-Werror=invalid-offsetof]

This new implementation of container_of makes use of a pointer to a data
member to find the parent's address.

The use of ptr_to_member against the null dummy_parent makes me uneasy
as it seems equivalent to performing arithmetic on a null pointer, which
I understand is undefined behavior (C++11 Standard 5.7.5).

However, Boost.Instrusive uses an approach that seems roughly equivalent
to lttng::utils::container_of() [1].

It seems like a reasonable compromise that works on all mainstream
compilers.

[1] https://github.com/boostorg/intrusive/blob/3c5c8cec3f0356a028a4b56ba6cac2256340dab1/include/boost/intrusive/detail/parent_from_member.hpp#L92

Change-Id: Ia6287e1648bce85dfe6de936f17ec5df46ea648d
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
68 files changed:
src/bin/lttng-relayd/connection.cpp
src/bin/lttng-relayd/ctf-trace.cpp
src/bin/lttng-relayd/index.cpp
src/bin/lttng-relayd/live.cpp
src/bin/lttng-relayd/main.cpp
src/bin/lttng-relayd/session.cpp
src/bin/lttng-relayd/sessiond-trace-chunks.cpp
src/bin/lttng-relayd/stream.cpp
src/bin/lttng-relayd/viewer-stream.cpp
src/bin/lttng-sessiond/agent.cpp
src/bin/lttng-sessiond/buffer-registry.cpp
src/bin/lttng-sessiond/condition-internal.cpp
src/bin/lttng-sessiond/consumer.cpp
src/bin/lttng-sessiond/dispatch.cpp
src/bin/lttng-sessiond/event-notifier-error-accounting.cpp
src/bin/lttng-sessiond/event.cpp
src/bin/lttng-sessiond/lttng-syscall.cpp
src/bin/lttng-sessiond/notification-thread-events.cpp
src/bin/lttng-sessiond/save.cpp
src/bin/lttng-sessiond/session.cpp
src/bin/lttng-sessiond/snapshot.cpp
src/bin/lttng-sessiond/thread.cpp
src/bin/lttng-sessiond/trace-ust.cpp
src/bin/lttng-sessiond/tracker.cpp
src/bin/lttng-sessiond/ust-app.cpp
src/bin/lttng-sessiond/ust-registry-session.cpp
src/bin/lttng-sessiond/ust-registry.cpp
src/common/actions/action.cpp
src/common/actions/list.cpp
src/common/actions/notify.cpp
src/common/actions/rate-policy.cpp
src/common/actions/rotate-session.cpp
src/common/actions/snapshot-session.cpp
src/common/actions/start-session.cpp
src/common/actions/stop-session.cpp
src/common/compat/directory-handle.cpp
src/common/conditions/buffer-usage.cpp
src/common/conditions/condition.cpp
src/common/conditions/event-rule-matches.cpp
src/common/conditions/session-consumed-size.cpp
src/common/conditions/session-rotation.cpp
src/common/consumer/consumer-stream.cpp
src/common/consumer/consumer.cpp
src/common/error-query.cpp
src/common/evaluation.cpp
src/common/event-expr/event-expr.cpp
src/common/event-field-value.cpp
src/common/event-rule/event-rule.cpp
src/common/event-rule/jul-logging.cpp
src/common/event-rule/kernel-kprobe.cpp
src/common/event-rule/kernel-syscall.cpp
src/common/event-rule/kernel-tracepoint.cpp
src/common/event-rule/kernel-uprobe.cpp
src/common/event-rule/log4j-logging.cpp
src/common/event-rule/python-logging.cpp
src/common/event-rule/user-tracepoint.cpp
src/common/fd-handle.cpp
src/common/fd-tracker/fd-tracker.cpp
src/common/fd-tracker/inode.cpp
src/common/hashtable/hashtable.cpp
src/common/kernel-probe.cpp
src/common/location.cpp
src/common/macros.hpp
src/common/session-descriptor.cpp
src/common/trace-chunk.cpp
src/common/trigger.cpp
src/common/userspace-probe.cpp
src/lib/lttng-ctl/rotate.cpp
This page took 0.032783 seconds and 4 git commands to generate.