~ubuntu-branches/ubuntu/lucid/mysql-dfsg-5.1/lucid-security

« back to all changes in this revision

Viewing changes to include/my_compiler.h

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 22:33:55 UTC
  • mto: (1.2.1) (37.1.1 lucid-security)
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: package-import@ubuntu.com-20120222223355-ku1tb4r70osci6v2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef MY_COMPILER_INCLUDED
 
2
#define MY_COMPILER_INCLUDED
 
3
 
 
4
/* Copyright (c) 2010, 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
 
 
19
/**
 
20
  Header for compiler-dependent features.
 
21
 
 
22
  Intended to contain a set of reusable wrappers for preprocessor
 
23
  macros, attributes, pragmas, and any other features that are
 
24
  specific to a target compiler.
 
25
*/
 
26
 
 
27
#include <my_global.h>                          /* stddef.h offsetof */
 
28
 
 
29
/**
 
30
  Compiler-dependent internal convenience macros.
 
31
*/
 
32
 
 
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
/** Specifies the minimum alignment of a type. */
 
71
# define MY_ALIGNOF(type)   __alignof__(type)
 
72
/** Determine the alignment requirement of a type. */
 
73
# define MY_ALIGNED(n)      __attribute__((__aligned__((n))))
 
74
#endif
 
75
 
 
76
/**
 
77
  Generic (compiler-independent) features.
 
78
*/
 
79
 
 
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
 
 
98
/**
 
99
  C++ Type Traits
 
100
*/
 
101
 
 
102
#ifdef __cplusplus
 
103
 
 
104
/**
 
105
  Opaque storage with a particular alignment.
 
106
*/
 
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
 
 
121
/**
 
122
  A POD type with a given size and alignment.
 
123
 
 
124
  @remark If the compiler does not support a alignment attribute
 
125
          (MY_ALIGN macro), the default alignment of a double is
 
126
          used instead.
 
127
 
 
128
  @tparam size        The minimum size.
 
129
  @tparam alignment   The desired alignment: 1, 2, 4, 8 or 16.
 
130
*/
 
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
#include <my_attribute.h>
 
144
 
 
145
#endif /* MY_COMPILER_INCLUDED */