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

Skip to content

Commit 3691edf

Browse files
committed
pg_noreturn to replace pg_attribute_noreturn()
We want to support a "noreturn" decoration on more compilers besides just GCC-compatible ones, but for that we need to move the decoration in front of the function declaration instead of either behind it or wherever, which is the current style afforded by GCC-style attributes. Also rename the macro to "pg_noreturn" to be similar to the C11 standard "noreturn". pg_noreturn is now supported on all compilers that support C11 (using _Noreturn), as well as GCC-compatible ones (using __attribute__, as before), as well as MSVC (using __declspec). (When PostgreSQL requires C11, the latter two variants can be dropped.) Now, all supported compilers effectively support pg_noreturn, so the extra code for !HAVE_PG_ATTRIBUTE_NORETURN can be dropped. This also fixes a possible problem if third-party code includes stdnoreturn.h, because then the current definition of #define pg_attribute_noreturn() __attribute__((noreturn)) would cause an error. Note that the C standard does not support a noreturn attribute on function pointer types. So we have to drop these here. There are only two instances at this time, so it's not a big loss. In one case, we can make up for it by adding the pg_noreturn to a wrapper function and adding a pg_unreachable(), in the other case, the latter was already done before. Reviewed-by: Dagfinn Ilmari Mannsåker <[email protected]> Reviewed-by: Andres Freund <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/pxr5b3z7jmkpenssra5zroxi7qzzp6eswuggokw64axmdixpnk@zbwxuq7gbbcw
1 parent cc5d985 commit 3691edf

File tree

54 files changed

+118
-118
lines changed

Some content is hidden

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

54 files changed

+118
-118
lines changed

contrib/dblink/dblink.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ xpstrdup(const char *in)
160160
return pstrdup(in);
161161
}
162162

163-
static void
164-
pg_attribute_noreturn()
163+
pg_noreturn static void
165164
dblink_res_internalerror(PGconn *conn, PGresult *res, const char *p2)
166165
{
167166
char *msg = pchomp(PQerrorMessage(conn));
@@ -170,8 +169,7 @@ dblink_res_internalerror(PGconn *conn, PGresult *res, const char *p2)
170169
elog(ERROR, "%s: %s", p2, msg);
171170
}
172171

173-
static void
174-
pg_attribute_noreturn()
172+
pg_noreturn static void
175173
dblink_conn_not_avail(const char *conname)
176174
{
177175
if (conname)

contrib/pgcrypto/px.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ int px_find_hmac(const char *name, PX_HMAC **res);
181181
int px_find_cipher(const char *name, PX_Cipher **res);
182182
int px_find_combo(const char *name, PX_Combo **res);
183183

184-
void px_THROW_ERROR(int err) pg_attribute_noreturn();
184+
pg_noreturn void px_THROW_ERROR(int err);
185185
const char *px_strerror(int err);
186186

187187
const char *px_resolve_alias(const PX_Alias *list, const char *name);

src/backend/access/transam/xlogrecovery.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4778,8 +4778,7 @@ check_primary_slot_name(char **newval, void **extra, GucSource source)
47784778
* that we have odd behaviors such as unexpected GUC ordering dependencies.
47794779
*/
47804780

4781-
static void
4782-
pg_attribute_noreturn()
4781+
pg_noreturn static void
47834782
error_multiple_recovery_targets(void)
47844783
{
47854784
ereport(ERROR,

src/backend/backup/basebackup_incremental.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ static void manifest_process_wal_range(JsonManifestParseContext *context,
139139
TimeLineID tli,
140140
XLogRecPtr start_lsn,
141141
XLogRecPtr end_lsn);
142-
static void manifest_report_error(JsonManifestParseContext *context,
143-
const char *fmt,...)
144-
pg_attribute_printf(2, 3) pg_attribute_noreturn();
142+
pg_noreturn static void manifest_report_error(JsonManifestParseContext *context,
143+
const char *fmt,...)
144+
pg_attribute_printf(2, 3);
145145
static int compare_block_numbers(const void *a, const void *b);
146146

147147
/*

src/backend/postmaster/autovacuum.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ int AutovacuumLauncherPid = 0;
317317

318318
static Oid do_start_worker(void);
319319
static void ProcessAutoVacLauncherInterrupts(void);
320-
static void AutoVacLauncherShutdown(void) pg_attribute_noreturn();
320+
pg_noreturn static void AutoVacLauncherShutdown(void);
321321
static void launcher_determine_sleep(bool canlaunch, bool recursing,
322322
struct timeval *nap);
323323
static void launch_worker(TimestampTz now);

src/backend/postmaster/launch_backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static pid_t internal_forkexec(const char *child_kind, int child_slot,
171171
typedef struct
172172
{
173173
const char *name;
174-
void (*main_fn) (const void *startup_data, size_t startup_data_len) pg_attribute_noreturn();
174+
void (*main_fn) (const void *startup_data, size_t startup_data_len);
175175
bool shmem_attach;
176176
} child_process_kind;
177177

src/backend/postmaster/postmaster.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ static void LogChildExit(int lev, const char *procname,
425425
static void PostmasterStateMachine(void);
426426
static void UpdatePMState(PMState newState);
427427

428-
static void ExitPostmaster(int status) pg_attribute_noreturn();
428+
pg_noreturn static void ExitPostmaster(int status);
429429
static int ServerLoop(void);
430430
static int BackendStartup(ClientSocket *client_sock);
431431
static void report_fork_failure_to_client(ClientSocket *client_sock, int errnum);

src/backend/replication/logical/tablesync.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ static StringInfo copybuf = NULL;
139139
/*
140140
* Exit routine for synchronization worker.
141141
*/
142-
static void
143-
pg_attribute_noreturn()
142+
pg_noreturn static void
144143
finish_sync_worker(void)
145144
{
146145
/*

src/backend/replication/walsender.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ typedef void (*WalSndSendDataCallback) (void);
237237
static void WalSndLoop(WalSndSendDataCallback send_data);
238238
static void InitWalSenderSlot(void);
239239
static void WalSndKill(int code, Datum arg);
240-
static void WalSndShutdown(void) pg_attribute_noreturn();
240+
pg_noreturn static void WalSndShutdown(void);
241241
static void XLogSendPhysical(void);
242242
static void XLogSendLogical(void);
243243
static void WalSndDone(WalSndSendDataCallback send_data);

src/backend/utils/adt/ri_triggers.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ static bool ri_PerformCheck(const RI_ConstraintInfo *riinfo,
235235
static void ri_ExtractValues(Relation rel, TupleTableSlot *slot,
236236
const RI_ConstraintInfo *riinfo, bool rel_is_pk,
237237
Datum *vals, char *nulls);
238-
static void ri_ReportViolation(const RI_ConstraintInfo *riinfo,
239-
Relation pk_rel, Relation fk_rel,
240-
TupleTableSlot *violatorslot, TupleDesc tupdesc,
241-
int queryno, bool is_restrict, bool partgone) pg_attribute_noreturn();
238+
pg_noreturn static void ri_ReportViolation(const RI_ConstraintInfo *riinfo,
239+
Relation pk_rel, Relation fk_rel,
240+
TupleTableSlot *violatorslot, TupleDesc tupdesc,
241+
int queryno, bool is_restrict, bool partgone);
242242

243243

244244
/*

0 commit comments

Comments
 (0)