Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbfd7ed

Browse files
committed
Add macros wrapping all usage of gcc's __attribute__.
Until now __attribute__() was defined to be empty for all compilers but gcc. That's problematic because it prevents using it in other compilers; which is necessary e.g. for atomics portability. It's also just generally dubious to do so in a header as widely included as c.h. Instead add pg_attribute_format_arg, pg_attribute_printf, pg_attribute_noreturn macros which are implemented in the compilers that understand them. Also add pg_attribute_noreturn and pg_attribute_packed, but don't provide fallbacks, since they can affect functionality. This means that external code that, possibly unwittingly, relied on __attribute__ defined to be empty on !gcc compilers may now run into warnings or errors on those compilers. But there shouldn't be many occurances of that and it's hard to work around... Discussion: [email protected] Author: Oskari Saarenmaa, with some minor changes by me.
1 parent 66ece31 commit bbfd7ed

Some content is hidden

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

68 files changed

+167
-132
lines changed

contrib/cube/cubescan.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ float ({integer}|{real})([eE]{integer})?
6060

6161
%%
6262

63-
void __attribute__((noreturn))
63+
void pg_attribute_noreturn
6464
yyerror(NDBOX **result, const char *message)
6565
{
6666
if (*yytext == YY_END_OF_BUFFER_CHAR)

contrib/pg_upgrade/pg_upgrade.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ void optionally_create_toast_tables(void);
359359
bool
360360
exec_prog(const char *log_file, const char *opt_log_file,
361361
bool throw_error, const char *fmt,...)
362-
__attribute__((format(PG_PRINTF_ATTRIBUTE, 4, 5)));
362+
pg_attribute_printf(4, 5);
363363
void verify_directories(void);
364364
bool pid_lock_file_exists(const char *datadir);
365365

@@ -445,7 +445,7 @@ void init_tablespaces(void);
445445
PGconn *connectToServer(ClusterInfo *cluster, const char *db_name);
446446
PGresult *
447447
executeQueryOrDie(PGconn *conn, const char *fmt,...)
448-
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
448+
pg_attribute_printf(2, 3);
449449

450450
char *cluster_conn_opts(ClusterInfo *cluster);
451451

@@ -462,17 +462,17 @@ int get_user_info(char **user_name_p);
462462
void check_ok(void);
463463
void
464464
report_status(eLogType type, const char *fmt,...)
465-
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
465+
pg_attribute_printf(2, 3);
466466
void
467467
pg_log(eLogType type, const char *fmt,...)
468-
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
468+
pg_attribute_printf(2, 3);
469469
void
470470
pg_fatal(const char *fmt,...)
471-
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2), noreturn));
471+
pg_attribute_printf(1, 2) pg_attribute_noreturn;
472472
void end_progress_output(void);
473473
void
474474
prep_status(const char *fmt,...)
475-
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
475+
pg_attribute_printf(1, 2);
476476
void check_ok(void);
477477
const char *getErrorText(int errNum);
478478
unsigned int str2uint(const char *str);
@@ -489,7 +489,7 @@ void old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster);
489489
void
490490
parallel_exec_prog(const char *log_file, const char *opt_log_file,
491491
const char *fmt,...)
492-
__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
492+
pg_attribute_printf(3, 4);
493493
void parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
494494
char *old_pgdata, char *new_pgdata,
495495
char *old_tablespace);

contrib/pg_upgrade/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ prep_status(const char *fmt,...)
8282

8383

8484
static
85-
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0)))
85+
pg_attribute_printf(2, 0)
8686
void
8787
pg_log_v(eLogType type, const char *fmt, va_list ap)
8888
{

contrib/pg_xlogdump/pg_xlogdump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ typedef struct XLogDumpStats
6969

7070
static void
7171
fatal_error(const char *fmt,...)
72-
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
72+
pg_attribute_printf(1, 2);
7373

7474
/*
7575
* Big red button to push when things go horribly wrong.

contrib/pgcrypto/px.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ void px_memset(void *ptr, int c, size_t len);
208208
#ifdef PX_DEBUG
209209
void
210210
px_debug(const char *fmt,...)
211-
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
211+
pg_attribute_printf(1, 2);
212212
#else
213213
#define px_debug(...)
214214
#endif

contrib/seg/segscan.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ float ({integer}|{real})([eE]{integer})?
5959

6060
%%
6161

62-
void __attribute__((noreturn))
62+
void pg_attribute_noreturn
6363
yyerror(SEG *result, const char *message)
6464
{
6565
if (*yytext == YY_END_OF_BUFFER_CHAR)

src/backend/access/transam/xlogreader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static void
3636
report_invalid_record(XLogReaderState *state, const char *fmt,...)
3737
/* This extension allows gcc to check the format string for consistency with
3838
the supplied arguments. */
39-
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
39+
pg_attribute_printf(2, 3);
4040

4141
static void ResetDecoder(XLogReaderState *state);
4242

src/backend/postmaster/autovacuum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ int AutovacuumLauncherPid = 0;
286286
static pid_t avlauncher_forkexec(void);
287287
static pid_t avworker_forkexec(void);
288288
#endif
289-
NON_EXEC_STATIC void AutoVacWorkerMain(int argc, char *argv[]) __attribute__((noreturn));
290-
NON_EXEC_STATIC void AutoVacLauncherMain(int argc, char *argv[]) __attribute__((noreturn));
289+
NON_EXEC_STATIC void AutoVacWorkerMain(int argc, char *argv[]) pg_attribute_noreturn;
290+
NON_EXEC_STATIC void AutoVacLauncherMain(int argc, char *argv[]) pg_attribute_noreturn;
291291

292292
static Oid do_start_worker(void);
293293
static void launcher_determine_sleep(bool canlaunch, bool recursing,

src/backend/postmaster/pgarch.c

Lines changed: 1 addition & 1 deletion
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[]) __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

Lines changed: 1 addition & 1 deletion
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[]) __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);

0 commit comments

Comments
 (0)