Skip to content

Commit 74938d1

Browse files
committed
IWYU widely useful pragmas
Add various widely useful "IWYU pragma" annotations, such as - Common header files such as c.h, postgres.h should be "always_keep". - System headers included in c.h, postgres.h etc. should be considered "export". - Some portability headers such as getopt_long.h should be "always_keep", so they are not considered superfluous on some platforms. - Certain system headers included from portability headers should be considered "export" because the purpose of the portability header is to wrap them. - Superfluous includes marked as "for backward compatibility" get a formal IWYU annotation. - Generated header included in utils/syscache.h is marked exported. This is a very commonly used include and this avoids lots of complaints. Discussion: https://www.postgresql.org/message-id/flat/9395d484-eff4-47c2-b276-8e228526c8ae@eisentraut.org
1 parent 761c795 commit 74938d1

File tree

12 files changed

+30
-10
lines changed

12 files changed

+30
-10
lines changed

src/include/c.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
19+
/* IWYU pragma: always_keep */
1920
/*
2021
*----------------------------------------------------------------
2122
* TABLE OF CONTENTS
@@ -46,6 +47,8 @@
4647
#ifndef C_H
4748
#define C_H
4849

50+
/* IWYU pragma: begin_exports */
51+
4952
/*
5053
* These headers must be included before any system headers, because on some
5154
* platforms they affect the behavior of the system headers (for example, by
@@ -1327,4 +1330,6 @@ typedef intptr_t sigjmp_buf[5];
13271330
/* /port compatibility functions */
13281331
#include "port.h"
13291332

1333+
/* IWYU pragma: end_exports */
1334+
13301335
#endif /* C_H */

src/include/getopt_long.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
*
77
* src/include/getopt_long.h
88
*/
9+
/* IWYU pragma: always_keep */
910
#ifndef GETOPT_LONG_H
1011
#define GETOPT_LONG_H
1112

12-
#include "pg_getopt.h"
13+
#include "pg_getopt.h" /* IWYU pragma: export */
1314

1415
#ifndef HAVE_STRUCT_OPTION
1516

src/include/pg_getopt.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
*
1616
* src/include/pg_getopt.h
1717
*/
18+
/* IWYU pragma: always_keep */
1819
#ifndef PG_GETOPT_H
1920
#define PG_GETOPT_H
2021

2122
/* POSIX says getopt() is provided by unistd.h */
22-
#include <unistd.h>
23+
#include <unistd.h> /* IWYU pragma: export */
2324

2425
/* rely on the system's getopt.h if present */
2526
#ifdef HAVE_GETOPT_H
26-
#include <getopt.h>
27+
#include <getopt.h> /* IWYU pragma: export */
2728
#endif
2829

2930
/*

src/include/pg_trace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
#ifndef PG_TRACE_H
1313
#define PG_TRACE_H
1414

15-
#include "utils/probes.h"
15+
#include "utils/probes.h" /* IWYU pragma: export */
1616

1717
#endif /* PG_TRACE_H */

src/include/pgstat.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
#include "portability/instr_time.h"
1717
#include "postmaster/pgarch.h" /* for MAX_XFN_CHARS */
1818
#include "replication/conflict.h"
19-
#include "utils/backend_progress.h" /* for backward compatibility */
20-
#include "utils/backend_status.h" /* for backward compatibility */
19+
#include "utils/backend_progress.h" /* for backward compatibility */ /* IWYU pragma: export */
20+
#include "utils/backend_status.h" /* for backward compatibility */ /* IWYU pragma: export */
2121
#include "utils/pgstat_kind.h"
2222
#include "utils/relcache.h"
23-
#include "utils/wait_event.h" /* for backward compatibility */
23+
#include "utils/wait_event.h" /* for backward compatibility */ /* IWYU pragma: export */
2424

2525

2626
/* ----------

src/include/port/pg_iovec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#ifndef WIN32
1717

1818
#include <limits.h>
19-
#include <sys/uio.h>
19+
#include <sys/uio.h> /* IWYU pragma: export */
2020
#include <unistd.h>
2121

2222
#else

src/include/port/pg_pthread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef PG_PTHREAD_H
1414
#define PG_PTHREAD_H
1515

16-
#include <pthread.h>
16+
#include <pthread.h> /* IWYU pragma: export */
1717

1818
#ifndef HAVE_PTHREAD_BARRIER_WAIT
1919

src/include/postgres.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
17+
/* IWYU pragma: always_keep */
1718
/*
1819
*----------------------------------------------------------------
1920
* TABLE OF CONTENTS
@@ -42,10 +43,14 @@
4243
#ifndef POSTGRES_H
4344
#define POSTGRES_H
4445

46+
/* IWYU pragma: begin_exports */
47+
4548
#include "c.h"
4649
#include "utils/elog.h"
4750
#include "utils/palloc.h"
4851

52+
/* IWYU pragma: end_exports */
53+
4954
/* ----------------------------------------------------------------
5055
* Section 1: Datum type + support functions
5156
* ----------------------------------------------------------------

src/include/postgres_ext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
22+
/* IWYU pragma: always_keep */
2223

2324
#ifndef POSTGRES_EXT_H
2425
#define POSTGRES_EXT_H

src/include/postgres_fe.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
18+
/* IWYU pragma: always_keep */
1819
#ifndef POSTGRES_FE_H
1920
#define POSTGRES_FE_H
2021

2122
#ifndef FRONTEND
2223
#define FRONTEND 1
2324
#endif
2425

26+
/* IWYU pragma: begin_exports */
27+
2528
#include "c.h"
2629

2730
#include "common/fe_memutils.h"
2831

32+
/* IWYU pragma: end_exports */
33+
2934
#endif /* POSTGRES_FE_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy