Support #pragma once
PATCH 1/1 Support #pragma once
"#pragma once" acts like a multiple-inclusion guard affecting the entire file, without an associated preprocessor symbol.
This allows use of sparse on projects that rely on #pragma once without also using an ifndef-based multiple-inclusion guard, such as systemd; without this change, sparse will get into an include loop.
--- ident-list.h | 1 + pre-process.c | 9 +++++++++ token.h | 2 +- validation/pragma-once.c | 5 +++++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 validation/pragma-once.c
ident-list.h +1 -0
@@ -97,6 +97,7 @@ IDENT(error); IDENT(__error__);* itself by name, preventing these tokens from expanding when compiling * sparse. */ IDENT (defined); +IDENT (once);__IDENT (pragma_ident,"__pragma__" ,0 );__IDENT (__VA_ARGS___ident,"__VA_ARGS__" ,0 );__IDENT (__LINE___ident,"__LINE__" ,0 );
pre-process.c +9 -0
@@ -743,6 +743,11 @@ static int already_tokenized(const char *path)struct stream *s = input_streams + stream; next = s->next_stream; +if (s->once) { +if (strcmp (path, s->name)) +continue ; +return 1 ; + }if (s->constant !=CONSTANT_FILE_YES )continue ;if (strcmp (path, s->name))
@@ -1809,6 +1814,10 @@ static int handle_pragma(struct stream *stream, struct token **line, struct toke {struct token *next = *line; +if (match_ident (token->next, &once_ident) &&eof_token (token->next->next)) { + stream->once =1 ; +return 1 ; + } token->ident = &pragma_ident; token->pos.newline =1 ; token->pos.whitespace =1 ;
token.h +1 -1
@@ -40,7 +40,7 @@ struct stream {/* Use these to check for "already parsed" */ enum constantfile constant; -int dirty, next_stream; +int dirty, next_stream, once;struct ident *protect;struct token *ifndef;struct token *top_if;
validation/pragma-once.c new file +5 -0
@@ -0,0 +1,5 @@ +#pragma once +#include "pragma-once.c" +/* +* check-name: #pragma once +*/
Signature · 1 line
1.8.2.1
Quoted 8 lines · Josh Triplett
"#pragma once" acts like a multiple-inclusion guard affecting the entire file, without an associated preprocessor symbol.
This allows use of sparse on projects that rely on #pragma once without also using an ifndef-based multiple-inclusion guard, such as systemd; without this change, sparse will get into an include loop.
Signed-off-by Josh Triplett <[email protected]>
awesome, thanks for doing this!
Auke
Christopher Li
maintainerQuoted 7 lines · Josh Triplett
"#pragma once" acts like a multiple-inclusion guard affecting the entire file, without an associated preprocessor symbol.
This allows use of sparse on projects that rely on #pragma once without also using an ifndef-based multiple-inclusion guard, such as systemd; without this change, sparse will get into an include loop.
Your two patches has been applied to the chrisl repository.
Thanks
Chris