Skip to content

Commit 785941c

Browse files
committed
Tweak __attribute__-wrapping macros for better pgindent results.
This improves on commit bbfd7ed by making two simple changes: * pg_attribute_noreturn now takes parentheses, ie pg_attribute_noreturn(). Likewise pg_attribute_unused(), pg_attribute_packed(). This reduces pgindent's tendency to misformat declarations involving them. * attributes are now always attached to function declarations, not definitions. Previously some places were taking creative shortcuts, which were not merely candidates for bad misformatting by pgindent but often were outright wrong anyway. (It does little good to put a noreturn annotation where callers can't see it.) In any case, if we would like to believe that these macros can be used with non-gcc compilers, we should avoid gratuitous variance in usage patterns. I also went through and manually improved the formatting of a lot of declarations, and got rid of excessively repetitive (and now obsolete anyway) comments informing the reader what pg_attribute_printf is for.
1 parent d04c8ed commit 785941c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+168
-356
lines changed

contrib/cube/cube.c

-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ PG_MODULE_MAGIC;
2626
#define ARRPTR(x) ( (double *) ARR_DATA_PTR(x) )
2727
#define ARRNELEMS(x) ArrayGetNItems( ARR_NDIM(x), ARR_DIMS(x))
2828

29-
extern int cube_yyparse(NDBOX **result);
30-
extern void cube_yyerror(NDBOX **result, const char *message);
31-
extern void cube_scanner_init(const char *str);
32-
extern void cube_scanner_finish(void);
33-
3429
/*
3530
** Input/Output routines
3631
*/

contrib/cube/cubedata.h

+9
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,12 @@ typedef struct NDBOX
4646
#define DatumGetNDBOX(x) ((NDBOX *) PG_DETOAST_DATUM(x))
4747
#define PG_GETARG_NDBOX(x) DatumGetNDBOX(PG_GETARG_DATUM(x))
4848
#define PG_RETURN_NDBOX(x) PG_RETURN_POINTER(x)
49+
50+
/* in cubescan.l */
51+
extern int cube_yylex(void);
52+
extern void cube_yyerror(NDBOX **result, const char *message) pg_attribute_noreturn();
53+
extern void cube_scanner_init(const char *str);
54+
extern void cube_scanner_finish(void);
55+
56+
/* in cubeparse.y */
57+
extern int cube_yyparse(NDBOX **result);

contrib/cube/cubeparse.y

-5
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,9 @@
2222
#define YYMALLOC palloc
2323
#define YYFREE pfree
2424

25-
extern int cube_yylex(void);
26-
2725
static char *scanbuf;
2826
static int scanbuflen;
2927

30-
extern int cube_yyparse(NDBOX **result);
31-
extern void cube_yyerror(NDBOX **result, const char *message);
32-
3328
static int delim_count(char *s, char delim);
3429
static NDBOX * write_box(unsigned int dim, char *str1, char *str2);
3530
static NDBOX * write_point_as_box(char *s, int dim);

contrib/cube/cubescan.l

+1-9
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* contrib/cube/cubescan.l
55
*/
66

7-
#include "postgres.h"
8-
97
/* No reason to constrain amount of data slurped */
108
#define YY_READ_BUF_SIZE 16777216
119

@@ -24,12 +22,6 @@ static YY_BUFFER_STATE scanbufhandle;
2422
/* this is now declared in cubeparse.y: */
2523
/* static char *scanbuf; */
2624
/* static int scanbuflen; */
27-
28-
/* flex 2.5.4 doesn't bother with a decl for this */
29-
int cube_yylex(void);
30-
31-
void cube_scanner_init(const char *str);
32-
void cube_scanner_finish(void);
3325
%}
3426

3527
%option 8bit
@@ -60,7 +52,7 @@ float ({integer}|{real})([eE]{integer})?
6052

6153
%%
6254

63-
void pg_attribute_noreturn
55+
void
6456
yyerror(NDBOX **result, const char *message)
6557
{
6658
if (*yytext == YY_END_OF_BUFFER_CHAR)

contrib/pg_upgrade/pg_upgrade.h

+10-23
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,9 @@ void optionally_create_toast_tables(void);
356356
/* exec.c */
357357

358358
#define EXEC_PSQL_ARGS "--echo-queries --set ON_ERROR_STOP=on --no-psqlrc --dbname=template1"
359-
bool
360-
exec_prog(const char *log_file, const char *opt_log_file,
361-
bool throw_error, const char *fmt,...)
362-
pg_attribute_printf(4, 5);
359+
360+
bool exec_prog(const char *log_file, const char *opt_log_file,
361+
bool throw_error, const char *fmt,...) pg_attribute_printf(4, 5);
363362
void verify_directories(void);
364363
bool pid_lock_file_exists(const char *datadir);
365364

@@ -443,9 +442,7 @@ void init_tablespaces(void);
443442
/* server.c */
444443

445444
PGconn *connectToServer(ClusterInfo *cluster, const char *db_name);
446-
PGresult *
447-
executeQueryOrDie(PGconn *conn, const char *fmt,...)
448-
pg_attribute_printf(2, 3);
445+
PGresult *executeQueryOrDie(PGconn *conn, const char *fmt,...) pg_attribute_printf(2, 3);
449446

450447
char *cluster_conn_opts(ClusterInfo *cluster);
451448

@@ -460,19 +457,11 @@ void check_pghost_envvar(void);
460457
char *quote_identifier(const char *s);
461458
int get_user_info(char **user_name_p);
462459
void check_ok(void);
463-
void
464-
report_status(eLogType type, const char *fmt,...)
465-
pg_attribute_printf(2, 3);
466-
void
467-
pg_log(eLogType type, const char *fmt,...)
468-
pg_attribute_printf(2, 3);
469-
void
470-
pg_fatal(const char *fmt,...)
471-
pg_attribute_printf(1, 2) pg_attribute_noreturn;
460+
void report_status(eLogType type, const char *fmt,...) pg_attribute_printf(2, 3);
461+
void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2, 3);
462+
void pg_fatal(const char *fmt,...) pg_attribute_printf(1, 2) pg_attribute_noreturn();
472463
void end_progress_output(void);
473-
void
474-
prep_status(const char *fmt,...)
475-
pg_attribute_printf(1, 2);
464+
void prep_status(const char *fmt,...) pg_attribute_printf(1, 2);
476465
void check_ok(void);
477466
const char *getErrorText(int errNum);
478467
unsigned int str2uint(const char *str);
@@ -486,10 +475,8 @@ void new_9_0_populate_pg_largeobject_metadata(ClusterInfo *cluster,
486475
void old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster);
487476

488477
/* parallel.c */
489-
void
490-
parallel_exec_prog(const char *log_file, const char *opt_log_file,
491-
const char *fmt,...)
492-
pg_attribute_printf(3, 4);
478+
void parallel_exec_prog(const char *log_file, const char *opt_log_file,
479+
const char *fmt,...) pg_attribute_printf(3, 4);
493480
void parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
494481
char *old_pgdata, char *new_pgdata,
495482
char *old_tablespace);

contrib/pg_upgrade/util.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
LogOpts log_opts;
1919

20+
static void pg_log_v(eLogType type, const char *fmt, va_list ap) pg_attribute_printf(2, 0);
21+
22+
2023
/*
2124
* report_status()
2225
*
@@ -81,9 +84,7 @@ prep_status(const char *fmt,...)
8184
}
8285

8386

84-
static
85-
pg_attribute_printf(2, 0)
86-
void
87+
static void
8788
pg_log_v(eLogType type, const char *fmt, va_list ap)
8889
{
8990
char message[QUERY_ALLOC];

contrib/pg_xlogdump/pg_xlogdump.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ typedef struct XLogDumpStats
6767
Stats record_stats[RM_NEXT_ID][MAX_XLINFO_TYPES];
6868
} XLogDumpStats;
6969

70-
static void
71-
fatal_error(const char *fmt,...)
72-
pg_attribute_printf(1, 2);
70+
static void fatal_error(const char *fmt,...) pg_attribute_printf(1, 2);
7371

7472
/*
7573
* Big red button to push when things go horribly wrong.

contrib/pgcrypto/px.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ void px_set_debug_handler(void (*handler) (const char *));
206206
void px_memset(void *ptr, int c, size_t len);
207207

208208
#ifdef PX_DEBUG
209-
void
210-
px_debug(const char *fmt,...)
211-
pg_attribute_printf(1, 2);
209+
void px_debug(const char *fmt,...) pg_attribute_printf(1, 2);
212210
#else
213211
#define px_debug(...)
214212
#endif

contrib/seg/seg.c

-10
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@
2323

2424
PG_MODULE_MAGIC;
2525

26-
extern int seg_yyparse(SEG *result);
27-
extern void seg_yyerror(SEG *result, const char *message);
28-
extern void seg_scanner_init(const char *str);
29-
extern void seg_scanner_finish(void);
30-
31-
/*
32-
extern int seg_yydebug;
33-
*/
34-
3526
/*
3627
* Auxiliary data structure for picksplit method.
3728
*/
@@ -103,7 +94,6 @@ bool seg_different(SEG *a, SEG *b);
10394
** Auxiliary funxtions
10495
*/
10596
static int restore(char *s, float val, int n);
106-
int significant_digits(char *s);
10797

10898

10999
/*****************************************************************************

contrib/seg/segdata.h

+12
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,15 @@ typedef struct SEG
1010
char l_ext;
1111
char u_ext;
1212
} SEG;
13+
14+
/* in seg.c */
15+
extern int significant_digits(char *str);
16+
17+
/* in segscan.l */
18+
extern int seg_yylex(void);
19+
extern void seg_yyerror(SEG *result, const char *message) pg_attribute_noreturn();
20+
extern void seg_scanner_init(const char *str);
21+
extern void seg_scanner_finish(void);
22+
23+
/* in segparse.y */
24+
extern int seg_yyparse(SEG *result);

contrib/seg/segparse.y

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "fmgr.h"
99
#include "utils/builtins.h"
10+
1011
#include "segdata.h"
1112

1213
/*
@@ -20,13 +21,6 @@
2021
#define YYMALLOC palloc
2122
#define YYFREE pfree
2223

23-
extern int seg_yylex(void);
24-
25-
extern int significant_digits(char *str); /* defined in seg.c */
26-
27-
extern int seg_yyparse(SEG *result);
28-
extern void seg_yyerror(SEG *result, const char *message);
29-
3024
static float seg_atof(char *value);
3125

3226
static char strbuf[25] = {

contrib/seg/segscan.l

+1-9
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* A scanner for EMP-style numeric ranges
44
*/
55

6-
#include "postgres.h"
7-
86
/* No reason to constrain amount of data slurped */
97
#define YY_READ_BUF_SIZE 16777216
108

@@ -22,12 +20,6 @@ fprintf_to_ereport(const char *fmt, const char *msg)
2220
static YY_BUFFER_STATE scanbufhandle;
2321
static char *scanbuf;
2422
static int scanbuflen;
25-
26-
/* flex 2.5.4 doesn't bother with a decl for this */
27-
int seg_yylex(void);
28-
29-
void seg_scanner_init(const char *str);
30-
void seg_scanner_finish(void);
3123
%}
3224

3325
%option 8bit
@@ -59,7 +51,7 @@ float ({integer}|{real})([eE]{integer})?
5951

6052
%%
6153

62-
void pg_attribute_noreturn
54+
void
6355
yyerror(SEG *result, const char *message)
6456
{
6557
if (*yytext == YY_END_OF_BUFFER_CHAR)

src/backend/access/transam/xlogreader.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ static bool ValidXLogRecord(XLogReaderState *state, XLogRecord *record,
3232
XLogRecPtr recptr);
3333
static int ReadPageInternal(XLogReaderState *state, XLogRecPtr pageptr,
3434
int reqLen);
35-
static void
36-
report_invalid_record(XLogReaderState *state, const char *fmt,...)
37-
/* This extension allows gcc to check the format string for consistency with
38-
the supplied arguments. */
39-
pg_attribute_printf(2, 3);
35+
static void report_invalid_record(XLogReaderState *state, const char *fmt,...) pg_attribute_printf(2, 3);
4036

4137
static void ResetDecoder(XLogReaderState *state);
4238

src/backend/postmaster/autovacuum.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ int AutovacuumLauncherPid = 0;
281281
static pid_t avlauncher_forkexec(void);
282282
static pid_t avworker_forkexec(void);
283283
#endif
284-
NON_EXEC_STATIC void AutoVacWorkerMain(int argc, char *argv[]) pg_attribute_noreturn;
285-
NON_EXEC_STATIC void AutoVacLauncherMain(int argc, char *argv[]) pg_attribute_noreturn;
284+
NON_EXEC_STATIC void AutoVacWorkerMain(int argc, char *argv[]) pg_attribute_noreturn();
285+
NON_EXEC_STATIC void AutoVacLauncherMain(int argc, char *argv[]) pg_attribute_noreturn();
286286

287287
static Oid do_start_worker(void);
288288
static void launcher_determine_sleep(bool canlaunch, bool recursing,

src/backend/postmaster/pgarch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static volatile sig_atomic_t ready_to_stop = false;
8686
static pid_t pgarch_forkexec(void);
8787
#endif
8888

89-
NON_EXEC_STATIC void PgArchiverMain(int argc, char *argv[]) pg_attribute_noreturn;
89+
NON_EXEC_STATIC void PgArchiverMain(int argc, char *argv[]) pg_attribute_noreturn();
9090
static void pgarch_exit(SIGNAL_ARGS);
9191
static void ArchSigHupHandler(SIGNAL_ARGS);
9292
static void ArchSigTermHandler(SIGNAL_ARGS);

src/backend/postmaster/pgstat.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ static instr_time total_func_time;
251251
static pid_t pgstat_forkexec(void);
252252
#endif
253253

254-
NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn;
254+
NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn();
255255
static void pgstat_exit(SIGNAL_ARGS);
256256
static void pgstat_beshutdown_hook(int code, Datum arg);
257257
static void pgstat_sighup_handler(SIGNAL_ARGS);

src/backend/postmaster/postmaster.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ static void LogChildExit(int lev, const char *procname,
380380
int pid, int exitstatus);
381381
static void PostmasterStateMachine(void);
382382
static void BackendInitialize(Port *port);
383-
static void BackendRun(Port *port) pg_attribute_noreturn;
384-
static void ExitPostmaster(int status) pg_attribute_noreturn;
383+
static void BackendRun(Port *port) pg_attribute_noreturn();
384+
static void ExitPostmaster(int status) pg_attribute_noreturn();
385385
static int ServerLoop(void);
386386
static int BackendStartup(Port *port);
387387
static int ProcessStartupPacket(Port *port, bool SSLdone);

src/backend/postmaster/syslogger.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static volatile sig_atomic_t rotation_requested = false;
130130
static pid_t syslogger_forkexec(void);
131131
static void syslogger_parseArgs(int argc, char *argv[]);
132132
#endif
133-
NON_EXEC_STATIC void SysLoggerMain(int argc, char *argv[]) pg_attribute_noreturn;
133+
NON_EXEC_STATIC void SysLoggerMain(int argc, char *argv[]) pg_attribute_noreturn();
134134
static void process_pipe_input(char *logbuffer, int *bytes_in_logbuffer);
135135
static void flush_pipe_input(char *logbuffer, int *bytes_in_logbuffer);
136136
static void open_csvlogfile(void);

src/backend/replication/repl_scanner.l

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ addlitchar(unsigned char ychar)
205205
appendStringInfoChar(&litbuf, ychar);
206206
}
207207

208-
void pg_attribute_noreturn
208+
void
209209
yyerror(const char *message)
210210
{
211211
ereport(ERROR,

src/backend/replication/walsender.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ typedef void (*WalSndSendDataCallback) (void);
193193
static void WalSndLoop(WalSndSendDataCallback send_data);
194194
static void InitWalSenderSlot(void);
195195
static void WalSndKill(int code, Datum arg);
196-
static void WalSndShutdown(void) pg_attribute_noreturn;
196+
static void WalSndShutdown(void) pg_attribute_noreturn();
197197
static void XLogSendPhysical(void);
198198
static void XLogSendLogical(void);
199199
static void WalSndDone(WalSndSendDataCallback send_data);

src/backend/utils/error/elog.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@
8282
#undef _
8383
#define _(x) err_gettext(x)
8484

85-
static const char *
86-
err_gettext(const char *str)
87-
/* This extension allows gcc to check the format string for consistency with
88-
the supplied arguments. */
89-
pg_attribute_format_arg(1);
85+
static const char *err_gettext(const char *str) pg_attribute_format_arg(1);
9086
static void set_errdata_field(MemoryContextData *cxt, char **ptr, const char *str);
9187

9288
/* Global variables */

src/backend/utils/misc/guc.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@ char *GUC_check_errmsg_string;
129129
char *GUC_check_errdetail_string;
130130
char *GUC_check_errhint_string;
131131

132-
static void
133-
do_serialize(char **destptr, Size *maxbytes, const char *fmt,...)
134-
/* This lets gcc check the format string for consistency. */
135-
pg_attribute_printf(3, 4);
132+
static void do_serialize(char **destptr, Size *maxbytes, const char *fmt,...) pg_attribute_printf(3, 4);
136133

137134
static void set_config_sourcefile(const char *name, char *sourcefile,
138135
int sourceline);

src/bin/pg_ctl/pg_ctl.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,7 @@ static pid_t postmasterPID = -1;
116116
#endif
117117

118118

119-
static void
120-
write_stderr(const char *fmt,...)
121-
/* This extension allows gcc to check the format string for consistency with
122-
the supplied arguments. */
123-
pg_attribute_printf(1, 2);
119+
static void write_stderr(const char *fmt,...) pg_attribute_printf(1, 2);
124120
static void do_advice(void);
125121
static void do_help(void);
126122
static void set_mode(char *modeopt);

src/bin/pg_dump/parallel.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ static ShutdownInformation shutdown_info;
7878
static const char *modulename = gettext_noop("parallel archiver");
7979

8080
static ParallelSlot *GetMyPSlot(ParallelState *pstate);
81-
static void
82-
parallel_msg_master(ParallelSlot *slot, const char *modulename,
83-
const char *fmt, va_list ap)
84-
pg_attribute_printf(3, 0);
81+
static void parallel_msg_master(ParallelSlot *slot, const char *modulename,
82+
const char *fmt, va_list ap) pg_attribute_printf(3, 0);
8583
static void archive_close_connection(int code, void *arg);
8684
static void ShutdownWorkersHard(ParallelState *pstate);
8785
static void WaitForTerminatingWorkers(ParallelState *pstate);

0 commit comments

Comments
 (0)