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

Commit91aec93

Browse files
committed
Rearrange c.h to create a "compiler characteristics" section.
Generalize section 1 to handle stuff that is principally about thecompiler (not libraries), such as attributes, and collect stuff therethat had been dropped into various other parts of c.h. Also, pushall the gettext macros into section 8, so that section 0 is reallyjust inclusions rather than inclusions and random other stuff.The primary goal here is to get pg_attribute_aligned() defined beforesection 3, so that we can use it with int128. But this seems like goodcleanup anyway.This patch just moves macro definitions around, and shouldn't resultin any changes in generated code. But I'll push it out separatelyto see if the buildfarm agrees.Discussion:https://postgr.es/m/20171110185747.31519.28038@wrigleys.postgresql.org
1 parent6d77652 commit91aec93

File tree

1 file changed

+136
-135
lines changed

1 file changed

+136
-135
lines changed

‎src/include/c.h

Lines changed: 136 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* sectiondescription
2727
* -------------------------------------------------------
2828
*0)pg_config.h and standard system headers
29-
*1)hacks to cope with non-ANSI C compilers
29+
*1)compiler characteristics
3030
*2)bool, true, false, TRUE, FALSE
3131
*3)standard system types
3232
*4)IsValid macros for system types
@@ -90,61 +90,133 @@
9090
#include<stdint.h>
9191
#endif
9292
#include<sys/types.h>
93-
9493
#include<errno.h>
9594
#if defined(WIN32)|| defined(__CYGWIN__)
9695
#include<fcntl.h>/* ensure O_BINARY is available */
9796
#endif
97+
#include<locale.h>
98+
#ifdefENABLE_NLS
99+
#include<libintl.h>
100+
#endif
98101

99102
#if defined(WIN32)|| defined(__CYGWIN__)
100103
/* We have to redefine some system functions after they are included above. */
101104
#include"pg_config_os.h"
102105
#endif
103106

104-
/*
105-
* Force disable inlining if PG_FORCE_DISABLE_INLINE is defined. This is used
106-
* to work around compiler bugs and might also be useful for investigatory
107-
* purposes by defining the symbol in the platform's header..
107+
108+
/* ----------------------------------------------------------------
109+
*Section 1: compiler characteristics
108110
*
109-
* This is done early (in slightly the wrong section) as functionality later
110-
* in this file might want to rely on inline functions.
111+
* type prefixes (const, signed, volatile, inline) are handled in pg_config.h.
112+
* ----------------------------------------------------------------
113+
*/
114+
115+
/*
116+
* Disable "inline" if PG_FORCE_DISABLE_INLINE is defined.
117+
* This is used to work around compiler bugs and might also be useful for
118+
* investigatory purposes.
111119
*/
112120
#ifdefPG_FORCE_DISABLE_INLINE
113121
#undef inline
114122
#defineinline
115123
#endif
116124

117-
/* Must be before gettext() games below */
118-
#include<locale.h>
125+
/*
126+
* Attribute macros
127+
*
128+
* GCC: https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
129+
* GCC: https://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html
130+
* Sunpro: https://docs.oracle.com/cd/E18659_01/html/821-1384/gjzke.html
131+
* XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/function_attributes.html
132+
* XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/type_attrib.html
133+
*/
119134

120-
#define_(x) gettext(x)
135+
/* only GCC supports the unused attribute */
136+
#ifdef__GNUC__
137+
#definepg_attribute_unused() __attribute__((unused))
138+
#else
139+
#definepg_attribute_unused()
140+
#endif
121141

122-
#ifdefENABLE_NLS
123-
#include<libintl.h>
142+
/*
143+
* Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only
144+
* used in assert-enabled builds, to avoid compiler warnings about unused
145+
* variables in assert-disabled builds.
146+
*/
147+
#ifdefUSE_ASSERT_CHECKING
148+
#definePG_USED_FOR_ASSERTS_ONLY
124149
#else
125-
#definegettext(x) (x)
126-
#definedgettext(d,x) (x)
127-
#definengettext(s,p,n) ((n) == 1 ? (s) : (p))
128-
#definedngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
150+
#definePG_USED_FOR_ASSERTS_ONLY pg_attribute_unused()
129151
#endif
130152

153+
/* GCC and XLC support format attributes */
154+
#if defined(__GNUC__)|| defined(__IBMC__)
155+
#definepg_attribute_format_arg(a) __attribute__((format_arg(a)))
156+
#definepg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
157+
#else
158+
#definepg_attribute_format_arg(a)
159+
#definepg_attribute_printf(f,a)
160+
#endif
161+
162+
/* GCC, Sunpro and XLC support aligned, packed and noreturn */
163+
#if defined(__GNUC__)|| defined(__SUNPRO_C)|| defined(__IBMC__)
164+
#definepg_attribute_aligned(a) __attribute__((aligned(a)))
165+
#definepg_attribute_noreturn() __attribute__((noreturn))
166+
#definepg_attribute_packed() __attribute__((packed))
167+
#defineHAVE_PG_ATTRIBUTE_NORETURN 1
168+
#else
131169
/*
132-
*Use this to mark string constants as needing translation at some later
133-
*time, rather than immediately. This is useful for cases where you need
134-
*access to the original string and translated string, and for cases where
135-
*immediate translation is not possible, like when initializing global
136-
*variables.
137-
*http://www.gnu.org/software/autoconf/manual/gettext/Special-cases.html
170+
* NB: aligned and packed are not given default definitions because they
171+
* affect code functionality; they *must* be implemented by the compiler
172+
* if they are to be used.
138173
*/
139-
#definegettext_noop(x) (x)
174+
#definepg_attribute_noreturn()
175+
#endif
140176

177+
/*
178+
* Forcing a function not to be inlined can be useful if it's the slow path of
179+
* a performance-critical function, or should be visible in profiles to allow
180+
* for proper cost attribution. Note that unlike the pg_attribute_XXX macros
181+
* above, this should be placed before the function's return type and name.
182+
*/
183+
/* GCC, Sunpro and XLC support noinline via __attribute__ */
184+
#if (defined(__GNUC__)&&__GNUC__>2)|| defined(__SUNPRO_C)|| defined(__IBMC__)
185+
#definepg_noinline __attribute__((noinline))
186+
/* msvc via declspec */
187+
#elif defined(_MSC_VER)
188+
#definepg_noinline __declspec(noinline)
189+
#else
190+
#definepg_noinline
191+
#endif
141192

142-
/* ----------------------------------------------------------------
143-
*Section 1: hacks to cope with non-ANSI C compilers
193+
/*
194+
* Mark a point as unreachable in a portable fashion. This should preferably
195+
* be something that the compiler understands, to aid code generation.
196+
* In assert-enabled builds, we prefer abort() for debugging reasons.
197+
*/
198+
#if defined(HAVE__BUILTIN_UNREACHABLE)&& !defined(USE_ASSERT_CHECKING)
199+
#definepg_unreachable() __builtin_unreachable()
200+
#elif defined(_MSC_VER)&& !defined(USE_ASSERT_CHECKING)
201+
#definepg_unreachable() __assume(0)
202+
#else
203+
#definepg_unreachable() abort()
204+
#endif
205+
206+
/*
207+
* Hints to the compiler about the likelihood of a branch. Both likely() and
208+
* unlikely() return the boolean value of the contained expression.
144209
*
145-
*type prefixes (const, signed, volatile, inline) are handled in pg_config.h.
146-
*----------------------------------------------------------------
210+
*These should only be used sparingly, in very hot code paths. It's very easy
211+
*to mis-estimate likelihoods.
147212
*/
213+
#if__GNUC__ >=3
214+
#definelikely(x)__builtin_expect((x) != 0, 1)
215+
#defineunlikely(x) __builtin_expect((x) != 0, 0)
216+
#else
217+
#definelikely(x)((x) != 0)
218+
#defineunlikely(x) ((x) != 0)
219+
#endif
148220

149221
/*
150222
* CppAsString
@@ -183,6 +255,7 @@
183255
#endif
184256
#endif
185257

258+
186259
/* ----------------------------------------------------------------
187260
*Section 2:bool, true, false, TRUE, FALSE
188261
* ----------------------------------------------------------------
@@ -209,6 +282,7 @@ typedef char bool;
209282
#ifndeffalse
210283
#definefalse((bool) 0)
211284
#endif
285+
212286
#endif/* not C++ */
213287

214288
#ifndefTRUE
@@ -492,16 +566,6 @@ typedef NameData *Name;
492566

493567
#defineNameStr(name)((name).data)
494568

495-
/*
496-
* Support macros for escaping strings. escape_backslash should be true
497-
* if generating a non-standard-conforming string. Prefixing a string
498-
* with ESCAPE_STRING_SYNTAX guarantees it is non-standard-conforming.
499-
* Beware of multiple evaluation of the "ch" argument!
500-
*/
501-
#defineSQL_STR_DOUBLE(ch,escape_backslash)\
502-
((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
503-
504-
#defineESCAPE_STRING_SYNTAX'E'
505569

506570
/* ----------------------------------------------------------------
507571
*Section 4:IsValid macros for system types
@@ -563,6 +627,9 @@ typedef NameData *Name;
563627
*
564628
* NOTE: TYPEALIGN[_DOWN] will not work if ALIGNVAL is not a power of 2.
565629
* That case seems extremely unlikely to be needed in practice, however.
630+
*
631+
* NOTE: MAXIMUM_ALIGNOF, and hence MAXALIGN(), intentionally exclude any
632+
* larger-than-8-byte types the compiler might have.
566633
* ----------------
567634
*/
568635

@@ -600,64 +667,6 @@ typedef NameData *Name;
600667
/* we don't currently need wider versions of the other ALIGN macros */
601668
#defineMAXALIGN64(LEN)TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN))
602669

603-
/* ----------------
604-
* Attribute macros
605-
*
606-
* GCC: https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
607-
* GCC: https://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html
608-
* Sunpro: https://docs.oracle.com/cd/E18659_01/html/821-1384/gjzke.html
609-
* XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/function_attributes.html
610-
* XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/type_attrib.html
611-
* ----------------
612-
*/
613-
614-
/* only GCC supports the unused attribute */
615-
#ifdef__GNUC__
616-
#definepg_attribute_unused() __attribute__((unused))
617-
#else
618-
#definepg_attribute_unused()
619-
#endif
620-
621-
/* GCC and XLC support format attributes */
622-
#if defined(__GNUC__)|| defined(__IBMC__)
623-
#definepg_attribute_format_arg(a) __attribute__((format_arg(a)))
624-
#definepg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
625-
#else
626-
#definepg_attribute_format_arg(a)
627-
#definepg_attribute_printf(f,a)
628-
#endif
629-
630-
/* GCC, Sunpro and XLC support aligned, packed and noreturn */
631-
#if defined(__GNUC__)|| defined(__SUNPRO_C)|| defined(__IBMC__)
632-
#definepg_attribute_aligned(a) __attribute__((aligned(a)))
633-
#definepg_attribute_noreturn() __attribute__((noreturn))
634-
#definepg_attribute_packed() __attribute__((packed))
635-
#defineHAVE_PG_ATTRIBUTE_NORETURN 1
636-
#else
637-
/*
638-
* NB: aligned and packed are not given default definitions because they
639-
* affect code functionality; they *must* be implemented by the compiler
640-
* if they are to be used.
641-
*/
642-
#definepg_attribute_noreturn()
643-
#endif
644-
645-
646-
/*
647-
* Forcing a function not to be inlined can be useful if it's the slow path of
648-
* a performance-critical function, or should be visible in profiles to allow
649-
* for proper cost attribution. Note that unlike the pg_attribute_XXX macros
650-
* above, this should be placed before the function's return type and name.
651-
*/
652-
/* GCC, Sunpro and XLC support noinline via __attribute__ */
653-
#if (defined(__GNUC__)&&__GNUC__>2)|| defined(__SUNPRO_C)|| defined(__IBMC__)
654-
#definepg_noinline __attribute__((noinline))
655-
/* msvc via declspec */
656-
#elif defined(_MSC_VER)
657-
#definepg_noinline __declspec(noinline)
658-
#else
659-
#definepg_noinline
660-
#endif
661670

662671
/* ----------------------------------------------------------------
663672
*Section 6:assertions
@@ -694,6 +703,7 @@ typedef NameData *Name;
694703
#defineAssertArg(condition) assert(condition)
695704
#defineAssertState(condition) assert(condition)
696705
#defineAssertPointerAlignment(ptr,bndr)((void)true)
706+
697707
#else/* USE_ASSERT_CHECKING && !FRONTEND */
698708

699709
/*
@@ -939,36 +949,6 @@ typedef NameData *Name;
939949
} while (0)
940950

941951

942-
/*
943-
* Mark a point as unreachable in a portable fashion. This should preferably
944-
* be something that the compiler understands, to aid code generation.
945-
* In assert-enabled builds, we prefer abort() for debugging reasons.
946-
*/
947-
#if defined(HAVE__BUILTIN_UNREACHABLE)&& !defined(USE_ASSERT_CHECKING)
948-
#definepg_unreachable() __builtin_unreachable()
949-
#elif defined(_MSC_VER)&& !defined(USE_ASSERT_CHECKING)
950-
#definepg_unreachable() __assume(0)
951-
#else
952-
#definepg_unreachable() abort()
953-
#endif
954-
955-
956-
/*
957-
* Hints to the compiler about the likelihood of a branch. Both likely() and
958-
* unlikely() return the boolean value of the contained expression.
959-
*
960-
* These should only be used sparingly, in very hot code paths. It's very easy
961-
* to mis-estimate likelihoods.
962-
*/
963-
#if__GNUC__ >=3
964-
#definelikely(x)__builtin_expect((x) != 0, 1)
965-
#defineunlikely(x) __builtin_expect((x) != 0, 0)
966-
#else
967-
#definelikely(x)((x) != 0)
968-
#defineunlikely(x) ((x) != 0)
969-
#endif
970-
971-
972952
/* ----------------------------------------------------------------
973953
*Section 8:random stuff
974954
* ----------------------------------------------------------------
@@ -978,26 +958,47 @@ typedef NameData *Name;
978958
#defineHIGHBIT(0x80)
979959
#defineIS_HIGHBIT_SET(ch)((unsigned char)(ch) & HIGHBIT)
980960

961+
/*
962+
* Support macros for escaping strings. escape_backslash should be true
963+
* if generating a non-standard-conforming string. Prefixing a string
964+
* with ESCAPE_STRING_SYNTAX guarantees it is non-standard-conforming.
965+
* Beware of multiple evaluation of the "ch" argument!
966+
*/
967+
#defineSQL_STR_DOUBLE(ch,escape_backslash)\
968+
((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
969+
970+
#defineESCAPE_STRING_SYNTAX'E'
971+
972+
981973
#defineSTATUS_OK(0)
982974
#defineSTATUS_ERROR(-1)
983975
#defineSTATUS_EOF(-2)
984976
#defineSTATUS_FOUND(1)
985977
#defineSTATUS_WAITING(2)
986978

987-
988979
/*
989-
* Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only
990-
* used in assert-enabled builds, to avoid compiler warnings about unused
991-
* variables in assert-disabled builds.
980+
* gettext support
992981
*/
993-
#ifdefUSE_ASSERT_CHECKING
994-
#definePG_USED_FOR_ASSERTS_ONLY
995-
#else
996-
#definePG_USED_FOR_ASSERTS_ONLY pg_attribute_unused()
982+
983+
#ifndefENABLE_NLS
984+
/* stuff we'd otherwise get from <libintl.h> */
985+
#definegettext(x) (x)
986+
#definedgettext(d,x) (x)
987+
#definengettext(s,p,n) ((n) == 1 ? (s) : (p))
988+
#definedngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
997989
#endif
998990

991+
#define_(x) gettext(x)
999992

1000-
/* gettext domain name mangling */
993+
/*
994+
*Use this to mark string constants as needing translation at some later
995+
*time, rather than immediately. This is useful for cases where you need
996+
*access to the original string and translated string, and for cases where
997+
*immediate translation is not possible, like when initializing global
998+
*variables.
999+
*http://www.gnu.org/software/autoconf/manual/gettext/Special-cases.html
1000+
*/
1001+
#definegettext_noop(x) (x)
10011002

10021003
/*
10031004
* To better support parallel installations of major PostgreSQL

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp