Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0507977

Browse files
committed
Introduce pg_attribute_nonnull(...)
pg_attribute_nonnull(...) can be used to generate compiler warningswhen a function is called with the specified arguments set to NULL, asper an idea from Andres Freund. An empty argument list indicates thatno pointer arguments can be NULL. pg_attribute_nonnull() only works forcompilers that support the nonnull function attribute. If nonnull isnot supported, pg_attribute_nonnull() has no effect.As a beginning, this commit uses it for the DefineCustomXXXVariable()functions to generate warnings when the "name" and "value" arguments areset to NULL. This will likely be expanded to other places in thefuture, where it makes sense.Author: Nathan BossartReviewed by: Michael Paquier, Tom LaneDiscussion:https://postgr.es/m/20220525061739.ur7x535vtzyzkmqo@alap3.anarazel.de
1 parentc99c67f commit0507977

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

‎src/include/c.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,17 @@
144144
#definepg_attribute_no_sanitize_alignment()
145145
#endif
146146

147+
/*
148+
* pg_attribute_nonnull means the compiler should warn if the function is
149+
* called with the listed arguments set to NULL. If no arguments are
150+
* listed, the compiler should warn if any pointer arguments are set to NULL.
151+
*/
152+
#if__has_attribute (nonnull)
153+
#definepg_attribute_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
154+
#else
155+
#definepg_attribute_nonnull(...)
156+
#endif
157+
147158
/*
148159
* Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only
149160
* used in assert-enabled builds, to avoid compiler warnings about unused

‎src/include/utils/guc.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ extern void DefineCustomBoolVariable(const char *name,
307307
intflags,
308308
GucBoolCheckHookcheck_hook,
309309
GucBoolAssignHookassign_hook,
310-
GucShowHookshow_hook);
310+
GucShowHookshow_hook)pg_attribute_nonnull(1,4);
311311

312312
externvoidDefineCustomIntVariable(constchar*name,
313313
constchar*short_desc,
@@ -320,7 +320,7 @@ extern void DefineCustomIntVariable(const char *name,
320320
intflags,
321321
GucIntCheckHookcheck_hook,
322322
GucIntAssignHookassign_hook,
323-
GucShowHookshow_hook);
323+
GucShowHookshow_hook)pg_attribute_nonnull(1,4);
324324

325325
externvoidDefineCustomRealVariable(constchar*name,
326326
constchar*short_desc,
@@ -333,7 +333,7 @@ extern void DefineCustomRealVariable(const char *name,
333333
intflags,
334334
GucRealCheckHookcheck_hook,
335335
GucRealAssignHookassign_hook,
336-
GucShowHookshow_hook);
336+
GucShowHookshow_hook)pg_attribute_nonnull(1,4);
337337

338338
externvoidDefineCustomStringVariable(constchar*name,
339339
constchar*short_desc,
@@ -344,7 +344,7 @@ extern void DefineCustomStringVariable(const char *name,
344344
intflags,
345345
GucStringCheckHookcheck_hook,
346346
GucStringAssignHookassign_hook,
347-
GucShowHookshow_hook);
347+
GucShowHookshow_hook)pg_attribute_nonnull(1,4);
348348

349349
externvoidDefineCustomEnumVariable(constchar*name,
350350
constchar*short_desc,
@@ -356,7 +356,7 @@ extern void DefineCustomEnumVariable(const char *name,
356356
intflags,
357357
GucEnumCheckHookcheck_hook,
358358
GucEnumAssignHookassign_hook,
359-
GucShowHookshow_hook);
359+
GucShowHookshow_hook)pg_attribute_nonnull(1,4);
360360

361361
externvoidMarkGUCPrefixReserved(constchar*className);
362362

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp