forked from irungentoo/toxcore
-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup: Ensure we limit the system headers included in .h files.
Most system headers contain functions (e.g. `memcpy` in `string.h`) which aren't needed in our own header files. For the most part, our own headers should only include types needed to declare our own types and functions. We now enforce this so we think twice about which headers we really need in the .h files.
- Loading branch information
Showing
7 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
.DS_Store | ||
.DS_Store? | ||
._* | ||
.mypy_cache | ||
.Spotlight-V100 | ||
.Trash* | ||
Icon? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python3 | ||
import subprocess | ||
import sys | ||
from typing import Tuple | ||
|
||
ALLOWLIST: Tuple[str, ...] = ( | ||
# system headers | ||
"pthread.h", | ||
"stdarg.h", | ||
"stdbool.h", | ||
"stddef.h", | ||
"stdint.h", | ||
# toxav stuff, maybe not worth abstracting away | ||
"opus.h", | ||
"vpx/vp8cx.h", | ||
"vpx/vp8dx.h", | ||
"vpx/vpx_decoder.h", | ||
"vpx/vpx_encoder.h", | ||
"vpx/vpx_image.h", | ||
) | ||
|
||
out = (subprocess.run( | ||
[ | ||
"grep", "-R", "^#include <.*>", "other", "toxav", "toxcore", | ||
"toxencryptsave" | ||
], | ||
check=True, | ||
capture_output=True, | ||
).stdout.decode("utf-8").rstrip()) | ||
|
||
errors = 0 | ||
for line in out.split("\n"): | ||
# other/fun can do what it wants. | ||
if "/fun/" in line: | ||
continue | ||
filename, include = line.split(":", 1) | ||
# We only check headers. | ||
if not filename.endswith(".h"): | ||
continue | ||
# ccompat.h can include some things we don't really want elsewhere. | ||
allowlist = ALLOWLIST | ||
if filename == "toxcore/ccompat.h": | ||
allowlist += ("alloca.h", "malloc.h", "stdlib.h") | ||
header = include[include.index("<") + 1:include.index(">")] | ||
if header not in allowlist: | ||
source = filename[:-2] + ".c" | ||
print( | ||
f"{filename}: includes system header <{header}>, which is not allowed in .h files" | ||
) | ||
print( | ||
" " * len(filename) + | ||
f" consider including it in {source} and exporting an abstraction, instead" | ||
) | ||
errors += 1 | ||
|
||
if errors: | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
*/ | ||
#include "audio.h" | ||
|
||
#include <assert.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
*/ | ||
#include "onion_client.h" | ||
|
||
#include <assert.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
|