MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
my_compiler.h
1 #ifndef MY_COMPILER_INCLUDED
2 #define MY_COMPILER_INCLUDED
3 
4 /* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; version 2 of the License.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
18 
27 #include <my_global.h> /* stddef.h offsetof */
28 
33 /* GNU C/C++ */
34 #if defined __GNUC__
35 /* Convenience macro to test the minimum required GCC version. */
36 # define MY_GNUC_PREREQ(maj, min) \
37  ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
38 /* Any after 2.95... */
39 # define MY_ALIGN_EXT
40 /* Comunicate to the compiler the unreachability of the code. */
41 # if MY_GNUC_PREREQ(4,5)
42 # define MY_ASSERT_UNREACHABLE() __builtin_unreachable()
43 # endif
44 
45 /* Microsoft Visual C++ */
46 #elif defined _MSC_VER
47 # define MY_ALIGNOF(type) __alignof(type)
48 # define MY_ALIGNED(n) __declspec(align(n))
49 
50 /* Oracle Solaris Studio */
51 #elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
52 # if __SUNPRO_C >= 0x590
53 # define MY_ALIGN_EXT
54 # endif
55 
56 /* IBM XL C/C++ */
57 #elif defined __xlC__
58 # if __xlC__ >= 0x0600
59 # define MY_ALIGN_EXT
60 # endif
61 
62 /* HP aCC */
63 #elif defined(__HP_aCC) || defined(__HP_cc)
64 # if (__HP_aCC >= 60000) || (__HP_cc >= 60000)
65 # define MY_ALIGN_EXT
66 # endif
67 #endif
68 
69 #ifdef MY_ALIGN_EXT
70 
71 # define MY_ALIGNOF(type) __alignof__(type)
72 
73 # define MY_ALIGNED(n) __attribute__((__aligned__((n))))
74 #endif
75 
80 #ifndef MY_GNUC_PREREQ
81 # define MY_GNUC_PREREQ(maj, min) (0)
82 #endif
83 
84 #ifndef MY_ALIGNOF
85 # ifdef __cplusplus
86  template<typename type> struct my_alignof_helper { char m1; type m2; };
87  /* Invalid for non-POD types, but most compilers give the right answer. */
88 # define MY_ALIGNOF(type) offsetof(my_alignof_helper<type>, m2)
89 # else
90 # define MY_ALIGNOF(type) offsetof(struct { char m1; type m2; }, m2)
91 # endif
92 #endif
93 
94 #ifndef MY_ASSERT_UNREACHABLE
95 # define MY_ASSERT_UNREACHABLE() do { assert(0); } while (0)
96 #endif
97 
102 #ifdef __cplusplus
103 
107 # if defined(MY_ALIGNED)
108 /* Partial specialization used due to MSVC++. */
109 template<size_t alignment> struct my_alignment_imp;
110 template<> struct MY_ALIGNED(1) my_alignment_imp<1> {};
111 template<> struct MY_ALIGNED(2) my_alignment_imp<2> {};
112 template<> struct MY_ALIGNED(4) my_alignment_imp<4> {};
113 template<> struct MY_ALIGNED(8) my_alignment_imp<8> {};
114 template<> struct MY_ALIGNED(16) my_alignment_imp<16> {};
115 /* ... expand as necessary. */
116 # else
117 template<size_t alignment>
118 struct my_alignment_imp { double m1; };
119 # endif
120 
131 template <size_t size, size_t alignment>
132 struct my_aligned_storage
133 {
134  union
135  {
136  char data[size];
137  my_alignment_imp<alignment> align;
138  };
139 };
140 
141 #endif /* __cplusplus */
142 
143 # ifndef MY_ALIGNED
144 /*
145  Make sure MY_ALIGNED can be used also on platforms where we don't
146  have a way of aligning data structures.
147 */
148 #define MY_ALIGNED(size)
149 #endif
150 
151 #include <my_attribute.h>
152 
153 #endif /* MY_COMPILER_INCLUDED */