![]() |
Ansel 0.0
A darktable fork - bloat + design vision
|
Functions | |
| guard_name (path) | |
| headers () | |
| convert (text, guard) | |
| wrap_unguarded (text, guard) | |
| main () | |
Variables | |
| str | SRC = 'src' |
| dict | SKIP_DIRS = {'external'} |
| PRAGMA_RE = re.compile(r'^[ \t]*#[ \t]*pragma[ \t]+once[ \t]*\r?\n', re.M) | |
| GUARD_RE | |
| dict | XMACRO_HEADERS |
| str | MODELINE = '// clang-format off\n// modelines:' |
Replace `#pragma once` with explicit include guards across src/. `#pragma once` silently makes a cyclic include graph compile: a header that is re-entered mid-definition is simply skipped, leaving the first inclusion to finish with whatever it had. Explicit guards behave the same way at the preprocessor level, but they are greppable, portable, and -- crucially -- they make the anti-pattern visible in review instead of hiding it. Guard names are derived from the path relative to src/, e.g. src/develop/masks/masks_history.h -> DT_DEVELOP_MASKS_MASKS_HISTORY_H Usage: python3 tools/pragma_once_to_guards.py --check # list what would change, touch nothing python3 tools/pragma_once_to_guards.py # rewrite in place python3 tools/pragma_once_to_guards.py --add-missing # also guard headers that have NO guard python3 tools/pragma_once_to_guards.py --verify # exit 1 if any #pragma once came back
| pragma_once_to_guards.convert | ( | text, | |
| guard | |||
| ) |
Definition at line 60 of file pragma_once_to_guards.py.
Referenced by main().
| pragma_once_to_guards.guard_name | ( | path | ) |
Definition at line 47 of file pragma_once_to_guards.py.
Referenced by main().
| pragma_once_to_guards.headers | ( | ) |
Definition at line 52 of file pragma_once_to_guards.py.
Referenced by main().
| pragma_once_to_guards.main | ( | void | ) |
Definition at line 106 of file pragma_once_to_guards.py.
References convert(), guard_name(), headers(), main(), and wrap_unguarded().
Referenced by main().
| pragma_once_to_guards.wrap_unguarded | ( | text, | |
| guard | |||
| ) |
Guard a header that has neither #pragma once nor an #ifndef/#define pair. The opening goes after the leading licence block comment (so the guard wraps the actual content, not the whole file including its header comment); the #endif goes just above the trailing modeline block, mirroring convert().
Definition at line 82 of file pragma_once_to_guards.py.
Referenced by main().
| pragma_once_to_guards.GUARD_RE |
Definition at line 26 of file pragma_once_to_guards.py.
| str pragma_once_to_guards.MODELINE = '// clang-format off\n// modelines:' |
Definition at line 44 of file pragma_once_to_guards.py.
Definition at line 25 of file pragma_once_to_guards.py.
| dict pragma_once_to_guards.SKIP_DIRS = {'external'} |
Definition at line 24 of file pragma_once_to_guards.py.
| str pragma_once_to_guards.SRC = 'src' |
Definition at line 23 of file pragma_once_to_guards.py.
| dict pragma_once_to_guards.XMACRO_HEADERS |
Definition at line 32 of file pragma_once_to_guards.py.