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

Commit6c35b3a

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 parentad083e4 commit6c35b3a

File tree

1 file changed

+110
-108
lines changed

1 file changed

+110
-108
lines changed

‎src/include/c.h

Lines changed: 110 additions & 108 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,65 +90,108 @@
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>
119-
120-
#define_(x) gettext(x)
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+
*/
121134

122-
#ifdefENABLE_NLS
123-
#include<libintl.h>
135+
/* only GCC supports the unused attribute */
136+
#ifdef__GNUC__
137+
#definepg_attribute_unused() __attribute__((unused))
124138
#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))
139+
#definepg_attribute_unused()
129140
#endif
130141

131142
/*
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
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.
138146
*/
139-
#definegettext_noop(x) (x)
147+
#ifdefUSE_ASSERT_CHECKING
148+
#definePG_USED_FOR_ASSERTS_ONLY
149+
#else
150+
#definePG_USED_FOR_ASSERTS_ONLY pg_attribute_unused()
151+
#endif
140152

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
141161

142-
/* ----------------------------------------------------------------
143-
*Section 1: hacks to cope with non-ANSI C compilers
144-
*
145-
* type prefixes (const, signed, volatile, inline) are handled in pg_config.h.
146-
* ----------------------------------------------------------------
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
169+
/*
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.
147173
*/
174+
#definepg_attribute_noreturn()
175+
#endif
176+
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
148189

149190
/*
150191
* CppAsString
151192
*Convert the argument to a string, using the C preprocessor.
193+
* CppAsString2
194+
*Convert the argument to a string, after one round of macro expansion.
152195
* CppConcat
153196
*Concatenate two arguments together, using the C preprocessor.
154197
*
@@ -157,6 +200,7 @@
157200
* backward compatibility with existing PostgreSQL code.
158201
*/
159202
#defineCppAsString(identifier) #identifier
203+
#defineCppAsString2(x)CppAsString(x)
160204
#defineCppConcat(x,y)x##y
161205

162206
/*
@@ -180,6 +224,7 @@
180224
#endif
181225
#endif
182226

227+
183228
/* ----------------------------------------------------------------
184229
*Section 2:bool, true, false, TRUE, FALSE, NULL
185230
* ----------------------------------------------------------------
@@ -206,6 +251,7 @@ typedef char bool;
206251
#ifndeffalse
207252
#definefalse((bool) 0)
208253
#endif
254+
209255
#endif/* not C++ */
210256

211257
typedefbool*BoolPtr;
@@ -497,16 +543,6 @@ typedef NameData *Name;
497543

498544
#defineNameStr(name)((name).data)
499545

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

511547
/* ----------------------------------------------------------------
512548
*Section 4:IsValid macros for system types
@@ -571,6 +607,9 @@ typedef NameData *Name;
571607
*
572608
* NOTE: TYPEALIGN[_DOWN] will not work if ALIGNVAL is not a power of 2.
573609
* That case seems extremely unlikely to be needed in practice, however.
610+
*
611+
* NOTE: MAXIMUM_ALIGNOF, and hence MAXALIGN(), intentionally exclude any
612+
* larger-than-8-byte types the compiler might have.
574613
* ----------------
575614
*/
576615

@@ -607,47 +646,6 @@ typedef NameData *Name;
607646
/* we don't currently need wider versions of the other ALIGN macros */
608647
#defineMAXALIGN64(LEN)TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN))
609648

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

652650
/* ----------------------------------------------------------------
653651
*Section 6:assertions
@@ -684,6 +682,7 @@ typedef NameData *Name;
684682
#defineAssertArg(condition) assert(condition)
685683
#defineAssertState(condition) assert(condition)
686684
#defineAssertPointerAlignment(ptr,bndr)((void)true)
685+
687686
#else/* USE_ASSERT_CHECKING && !FRONTEND */
688687

689688
/*
@@ -929,20 +928,6 @@ typedef NameData *Name;
929928
} while (0)
930929

931930

932-
/*
933-
* Mark a point as unreachable in a portable fashion. This should preferably
934-
* be something that the compiler understands, to aid code generation.
935-
* In assert-enabled builds, we prefer abort() for debugging reasons.
936-
*/
937-
#if defined(HAVE__BUILTIN_UNREACHABLE)&& !defined(USE_ASSERT_CHECKING)
938-
#definepg_unreachable() __builtin_unreachable()
939-
#elif defined(_MSC_VER)&& !defined(USE_ASSERT_CHECKING)
940-
#definepg_unreachable() __assume(0)
941-
#else
942-
#definepg_unreachable() abort()
943-
#endif
944-
945-
946931
/* ----------------------------------------------------------------
947932
*Section 8:random stuff
948933
* ----------------------------------------------------------------
@@ -952,26 +937,47 @@ typedef NameData *Name;
952937
#defineHIGHBIT(0x80)
953938
#defineIS_HIGHBIT_SET(ch)((unsigned char)(ch) & HIGHBIT)
954939

940+
/*
941+
* Support macros for escaping strings. escape_backslash should be TRUE
942+
* if generating a non-standard-conforming string. Prefixing a string
943+
* with ESCAPE_STRING_SYNTAX guarantees it is non-standard-conforming.
944+
* Beware of multiple evaluation of the "ch" argument!
945+
*/
946+
#defineSQL_STR_DOUBLE(ch,escape_backslash)\
947+
((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
948+
949+
#defineESCAPE_STRING_SYNTAX'E'
950+
951+
955952
#defineSTATUS_OK(0)
956953
#defineSTATUS_ERROR(-1)
957954
#defineSTATUS_EOF(-2)
958955
#defineSTATUS_FOUND(1)
959956
#defineSTATUS_WAITING(2)
960957

961-
962958
/*
963-
* Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only
964-
* used in assert-enabled builds, to avoid compiler warnings about unused
965-
* variables in assert-disabled builds.
959+
* gettext support
966960
*/
967-
#ifdefUSE_ASSERT_CHECKING
968-
#definePG_USED_FOR_ASSERTS_ONLY
969-
#else
970-
#definePG_USED_FOR_ASSERTS_ONLY pg_attribute_unused()
961+
962+
#ifndefENABLE_NLS
963+
/* stuff we'd otherwise get from <libintl.h> */
964+
#definegettext(x) (x)
965+
#definedgettext(d,x) (x)
966+
#definengettext(s,p,n) ((n) == 1 ? (s) : (p))
967+
#definedngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
971968
#endif
972969

970+
#define_(x) gettext(x)
973971

974-
/* gettext domain name mangling */
972+
/*
973+
*Use this to mark string constants as needing translation at some later
974+
*time, rather than immediately. This is useful for cases where you need
975+
*access to the original string and translated string, and for cases where
976+
*immediate translation is not possible, like when initializing global
977+
*variables.
978+
*http://www.gnu.org/software/autoconf/manual/gettext/Special-cases.html
979+
*/
980+
#definegettext_noop(x) (x)
975981

976982
/*
977983
* To better support parallel installations of major PostgreSQL
@@ -986,10 +992,6 @@ typedef NameData *Name;
986992
*
987993
* Make sure this matches the installation rules in nls-global.mk.
988994
*/
989-
990-
/* need a second indirection because we want to stringize the macro value, not the name */
991-
#defineCppAsString2(x) CppAsString(x)
992-
993995
#ifdefSO_MAJOR_VERSION
994996
#definePG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
995997
#else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp