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

Lines changed: 0 additions & 5 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 0 additions & 5 deletions
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

Lines changed: 1 addition & 9 deletions
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

Lines changed: 10 additions & 23 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 0 additions & 10 deletions
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

Lines changed: 12 additions & 0 deletions
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);

0 commit comments

Comments
 (0)