mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
tree-wide: Introduce sd-forward.h and shared-forward.h headers
Let's not leak details from src/shared and src/libsystemd into src/basic, even though you can't actually do anything useful with just forward declarations from src/shared. The sd-forward.h header is put in src/libsystemd/sd-common as we don't have a directory for shared internal headers for libsystemd yet. Let's also rename forward.h to basic-forward.h to keep things self-explanatory.
This commit is contained in:
@@ -250,9 +250,9 @@ SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
inline functions that require the full definition of a struct into the
|
||||
implementation file so that only a forward declaration of the struct is
|
||||
required and not the full definition.
|
||||
- `src/basic/forward.h` contains forward declarations for common types. If
|
||||
possible, only include `forward.h` in header files which makes circular
|
||||
header dependencies a non-issue.
|
||||
- `src/basic/basic-forward.h` contains forward declarations for common types.
|
||||
If possible, only include `basic-forward.h` in header files which makes
|
||||
circular header dependencies a non-issue.
|
||||
|
||||
Bad:
|
||||
|
||||
@@ -319,13 +319,21 @@ SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
incremental builds as much as possible.
|
||||
|
||||
To avoid having to include other headers in header files, always include
|
||||
`forward.h` in each header file and then add other required includes as
|
||||
needed. `forward.h` already includes generic headers and contains forward
|
||||
declarations for common types which should be sufficient for most header
|
||||
files. For each extra include you add on top of `forward.h`, check if it can
|
||||
be replaced by adding another forward declaration to `forward.h`. Depending on
|
||||
the daemon, there might be a specific forward header to include (e.g.
|
||||
`resolved-forward.h` for systemd-resolved header files).
|
||||
the corresponding forward declaration header in each header file and then add
|
||||
other required includes as needed. The forward declaration header already
|
||||
includes generic headers and contains forward declarations for common types
|
||||
which should be sufficient for most header files. For each extra include you
|
||||
add on top of, check if it can be replaced by adding another forward
|
||||
declaration to the forward declaration header. Depending on the daemon, there
|
||||
might be a specific forward header to include (e.g. `resolved-forward.h` for
|
||||
systemd-resolved header files).
|
||||
|
||||
For common code, there are three different forward declaration headers:
|
||||
|
||||
- `src/basic`: `basic-forward.h`
|
||||
- `src/libsystemd`: `sd-forward.h`
|
||||
- `src/libsystemd-network`: `sd-forward.h`
|
||||
- `src/shared`: `shared-forward.h`
|
||||
|
||||
Header files that extend other header files can include the original header
|
||||
file. For example, `iovec-util.h` includes `iovec-fundamental.h` and
|
||||
@@ -352,7 +360,7 @@ SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
```c
|
||||
// source.h
|
||||
|
||||
#include "forward.h"
|
||||
#include "basic-forward.h"
|
||||
|
||||
void my_function_that_logs(size_t sz);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user