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

Commita891050

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.Back-patch of commit91aec93.Discussion:https://postgr.es/m/20171110185747.31519.28038@wrigleys.postgresql.org
1 parent8d8f85d commita891050

File tree

1 file changed

+120
-118
lines changed

1 file changed

+120
-118
lines changed

‎src/include/c.h

Lines changed: 120 additions & 118 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, NULL
3131
*3)standard system types
3232
*4)IsValid macros for system types
@@ -90,61 +90,117 @@
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+
* Mark a point as unreachable in a portable fashion. This should preferably
179+
* be something that the compiler understands, to aid code generation.
180+
* In assert-enabled builds, we prefer abort() for debugging reasons.
181+
*/
182+
#if defined(HAVE__BUILTIN_UNREACHABLE)&& !defined(USE_ASSERT_CHECKING)
183+
#definepg_unreachable() __builtin_unreachable()
184+
#elif defined(_MSC_VER)&& !defined(USE_ASSERT_CHECKING)
185+
#definepg_unreachable() __assume(0)
186+
#else
187+
#definepg_unreachable() abort()
188+
#endif
141189

142-
/* ----------------------------------------------------------------
143-
*Section 1: hacks to cope with non-ANSI C compilers
190+
/*
191+
* Hints to the compiler about the likelihood of a branch. Both likely() and
192+
* unlikely() return the boolean value of the contained expression.
144193
*
145-
*type prefixes (const, signed, volatile, inline) are handled in pg_config.h.
146-
*----------------------------------------------------------------
194+
*These should only be used sparingly, in very hot code paths. It's very easy
195+
*to mis-estimate likelihoods.
147196
*/
197+
#if__GNUC__ >=3
198+
#definelikely(x)__builtin_expect((x) != 0, 1)
199+
#defineunlikely(x) __builtin_expect((x) != 0, 0)
200+
#else
201+
#definelikely(x)((x) != 0)
202+
#defineunlikely(x) ((x) != 0)
203+
#endif
148204

149205
/*
150206
* CppAsString
@@ -183,6 +239,7 @@
183239
#endif
184240
#endif
185241

242+
186243
/* ----------------------------------------------------------------
187244
*Section 2:bool, true, false, TRUE, FALSE, NULL
188245
* ----------------------------------------------------------------
@@ -209,6 +266,7 @@ typedef char bool;
209266
#ifndeffalse
210267
#definefalse((bool) 0)
211268
#endif
269+
212270
#endif/* not C++ */
213271

214272
typedefbool*BoolPtr;
@@ -502,16 +560,6 @@ typedef NameData *Name;
502560

503561
#defineNameStr(name)((name).data)
504562

505-
/*
506-
* Support macros for escaping strings. escape_backslash should be TRUE
507-
* if generating a non-standard-conforming string. Prefixing a string
508-
* with ESCAPE_STRING_SYNTAX guarantees it is non-standard-conforming.
509-
* Beware of multiple evaluation of the "ch" argument!
510-
*/
511-
#defineSQL_STR_DOUBLE(ch,escape_backslash)\
512-
((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
513-
514-
#defineESCAPE_STRING_SYNTAX'E'
515563

516564
/* ----------------------------------------------------------------
517565
*Section 4:IsValid macros for system types
@@ -579,6 +627,9 @@ typedef NameData *Name;
579627
*
580628
* NOTE: TYPEALIGN[_DOWN] will not work if ALIGNVAL is not a power of 2.
581629
* 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.
582633
* ----------------
583634
*/
584635

@@ -615,47 +666,6 @@ typedef NameData *Name;
615666
/* we don't currently need wider versions of the other ALIGN macros */
616667
#defineMAXALIGN64(LEN)TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN))
617668

618-
/* ----------------
619-
* Attribute macros
620-
*
621-
* GCC: https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
622-
* GCC: https://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html
623-
* Sunpro: https://docs.oracle.com/cd/E18659_01/html/821-1384/gjzke.html
624-
* XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/function_attributes.html
625-
* XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/type_attrib.html
626-
* ----------------
627-
*/
628-
629-
/* only GCC supports the unused attribute */
630-
#ifdef__GNUC__
631-
#definepg_attribute_unused() __attribute__((unused))
632-
#else
633-
#definepg_attribute_unused()
634-
#endif
635-
636-
/* GCC and XLC support format attributes */
637-
#if defined(__GNUC__)|| defined(__IBMC__)
638-
#definepg_attribute_format_arg(a) __attribute__((format_arg(a)))
639-
#definepg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
640-
#else
641-
#definepg_attribute_format_arg(a)
642-
#definepg_attribute_printf(f,a)
643-
#endif
644-
645-
/* GCC, Sunpro and XLC support aligned, packed and noreturn */
646-
#if defined(__GNUC__)|| defined(__SUNPRO_C)|| defined(__IBMC__)
647-
#definepg_attribute_aligned(a) __attribute__((aligned(a)))
648-
#definepg_attribute_noreturn() __attribute__((noreturn))
649-
#definepg_attribute_packed() __attribute__((packed))
650-
#defineHAVE_PG_ATTRIBUTE_NORETURN 1
651-
#else
652-
/*
653-
* NB: aligned and packed are not given default definitions because they
654-
* affect code functionality; they *must* be implemented by the compiler
655-
* if they are to be used.
656-
*/
657-
#definepg_attribute_noreturn()
658-
#endif
659669

660670
/* ----------------------------------------------------------------
661671
*Section 6:assertions
@@ -692,6 +702,7 @@ typedef NameData *Name;
692702
#defineAssertArg(condition) assert(condition)
693703
#defineAssertState(condition) assert(condition)
694704
#defineAssertPointerAlignment(ptr,bndr)((void)true)
705+
695706
#else/* USE_ASSERT_CHECKING && !FRONTEND */
696707

697708
/*
@@ -937,36 +948,6 @@ typedef NameData *Name;
937948
} while (0)
938949

939950

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

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

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

990+
#define_(x) gettext(x)
997991

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

10001002
/*
10011003
* To better support parallel installations of major PostgreSQL

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp