Zero  0.1.0
w_workaround.h
Go to the documentation of this file.
1 /* -*- mode:C++; c-basic-offset:4 -*-
2  Shore-MT -- Multi-threaded port of the SHORE storage manager
3 
4  Copyright (c) 2007-2009
5  Data Intensive Applications and Systems Labaratory (DIAS)
6  Ecole Polytechnique Federale de Lausanne
7 
8  All Rights Reserved.
9 
10  Permission to use, copy, modify and distribute this software and
11  its documentation is hereby granted, provided that both the
12  copyright notice and this permission notice appear in all copies of
13  the software, derivative works or modified versions, and any
14  portions thereof, and that both notices appear in supporting
15  documentation.
16 
17  This code is distributed in the hope that it will be useful, but
18  WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS
20  DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
21  RESULTING FROM THE USE OF THIS SOFTWARE.
22 */
23 
24 /*<std-header orig-src='shore' incl-file-exclusion='W_WORKAROUND_H'>
25 
26  $Id: w_workaround.h,v 1.61 2010/12/08 17:37:37 nhall Exp $
27 
28 SHORE -- Scalable Heterogeneous Object REpository
29 
30 Copyright (c) 1994-99 Computer Sciences Department, University of
31  Wisconsin -- Madison
32 All Rights Reserved.
33 
34 Permission to use, copy, modify and distribute this software and its
35 documentation is hereby granted, provided that both the copyright
36 notice and this permission notice appear in all copies of the
37 software, derivative works or modified versions, and any portions
38 thereof, and that both notices appear in supporting documentation.
39 
40 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
41 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
42 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
43 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
44 
45 This software was developed with support by the Advanced Research
46 Project Agency, ARPA order number 018 (formerly 8230), monitored by
47 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
48 Further funding for this work was provided by DARPA through
49 Rome Research Laboratory Contract No. F30602-97-2-0247.
50 
51 */
52 
53 #ifndef __W_WORKAROUND_H
54 #define __W_WORKAROUND_H
55 
56 #include "w_defines.h"
57 
58 /* -- do not edit anything above this line -- </std-header>*/
59 
65 #ifdef __GNUC__
66 
67 /* Mechanism to make disjoint gcc numbering appear linear for comparison
68  purposes. Without this all the Shore gcc hacks break when a new major
69  number is encountered.
70 */
71 
72 #define W_GCC_VER(major, minor) (((major) << 16) + (minor))
73 
74 #ifndef __GNUC_MINOR__ /* gcc-1.something -- No minor version number */
75 #define W_GCC_THIS_VER W_GCC_VER(__GNUC__,0)
76 #else
77 #define W_GCC_THIS_VER W_GCC_VER(__GNUC__,__GNUC_MINOR__)
78 #endif
79 
80 #if W_GCC_THIS_VER < W_GCC_VER(2, 5)
81 /* XXX all the following tests assume this filter is used */
82 #error This software requires gcc 2.5.x or a later release.
83 #error Gcc 2.6.0 is preferred.
84 #endif
85 
86 #if W_GCC_THIS_VER < W_GCC_VER(2, 6)
87 
88 /*
89  * G++ also has a bug in calling the destructor of a template
90  */
91 # define GNUG_BUG_2 1
92 
93 /*
94  * G++ seems to have a problem calling ::operator delete
95  */
96 # define GNUG_BUG_3 1
97 
98 /*
99  * G++ version 2.4.5 has problems with templates that don't have
100  * destructors explicitly defined. It also seems to have problems
101  * with classes used to instantiate templates if those classes
102  * do not have destructors.
103  */
104 # define GNUG_BUG_7 1
105 
106 /* bug #8:
107  * gcc include files don't define signal() as in ANSI C.
108  * we need to get around that
109  */
110 # define GNUG_BUG_8 1
111 
112 #endif /* gcc < 2.6 */
113 
114 /*
115  * #12
116  * This is a bug in parsing specific to gcc 2.6.0.
117  * The compiler misinterprets:
118  * int(j)
119  * to be a declaration of j as an int rather than the correct
120  * interpretation as a cast of j to an int. This shows up in
121  * statements like:
122  * istrstream(c) >> i;
123 */
124 
125 /* see below for more info on GNUG_BUG_12 */
126 #define GNUG_BUG_12(arg) arg
127 #if W_GCC_THIS_VER > W_GCC_VER(2, 5)
128 # undef GNUG_BUG_12
129 # define GNUG_BUG_12(arg) (arg)
130 #endif
131 
132 #if W_GCC_THIS_VER > W_GCC_VER(2, 5)
133 /*
134  * GNU 2.6.0 : template functions that are
135  * not member functions don't get exported from the
136  * implementation file.
137  */
138 #define GNUG_BUG_13 1
139 
140 /*
141  * Cannot explicitly instantiate function templates.
142  */
143 #define GNUG_BUG_14 1
144 #endif
145 
146 #if W_GCC_THIS_VER > W_GCC_VER(2, 6)
147 /* gcc 2.7.2 has bogus warning messages; it doesn't inherit pointer
148  properties correctly */
149 #define GNUG_BUG_15 1
150 #endif
151 
152 /* Gcc 64 bit integer math incorrectly optimizes range comparisons such as
153  if (i64 < X || i64 > Y)
154  zzz;
155  This should be re-examined when we upgrade to 2.8, perhaps it is fixed and
156  we can make this a 2.7 dependency.
157  */
158 #define GNUG_BUG_16
159 
160 /******************************************************************************
161  *
162  * Migration to standard C++
163  *
164  ******************************************************************************/
165 #if W_GCC_THIS_VER >= W_GCC_VER(2, 90)
166 /*
167  * EGCS is 2.90 (which really screws up any attempt to fix
168  * things based on __GNUC_MINOR__ and __GNUC__
169  * and egcs does not define any different macro to identify itself.
170  */
171 #endif
172 
173 #if W_GCC_THIS_VER < W_GCC_VER(2, 8)
174 
175 # define BIND_FRIEND_OPERATOR_PART_1(TYP,L,TMPLa,TMPLb)
176 # define BIND_FRIEND_OPERATOR_PART_1B(TYP1,TYP3,TYP2,TMPLa,TMPLc,TMPLb)
177 # define BIND_FRIEND_OPERATOR_PART_2(TYP)
178 # define BIND_FRIEND_OPERATOR_PART_2B(TYP1,TYP2)
179 
180 # else
181 
182 # define BIND_FRIEND_OPERATOR_PART_1(TYP, L, TMPLa, TMPLb) \
183  template <class TYP, class L> \
184  ostream & operator<<(ostream&o, const TMPLa,TMPLb& l);
185 
186 # define BIND_FRIEND_OPERATOR_PART_1B(TYP1, TYP3, TYP2, TMPLa, TMPLc, TMPLb) \
187  template <class TYP1, class TYP3, class TYP2> \
188  ostream & operator<<(ostream&o, const TMPLa,TMPLc,TMPLb& l);
189 
190 # define BIND_FRIEND_OPERATOR_PART_2(TYP, L)\
191  <TYP, L>
192 
193 # define BIND_FRIEND_OPERATOR_PART_2B(TYP1, L, TYP2)\
194  <TYP1, L, TYP2>
195 
196 # endif
197 
198 /* XXX
199  * The gcc-3.x object model has changes which allow THIS to change
200  * based upon inheritance and such. That isn't a problem. However,
201  * they added a poor warning which breaks ANY use of offsetof(), even
202  * legitimate cases where it is THE ONLY way to get the correct result and
203  * where the result would be correct with the new model. This offsetof
204  * implementation is designed to avoid that particular compiler warning.
205  * Until the GCC guys admit they are doing something dumb, we need to do this.
206  *
207  * This could arguably belong in w_base.h, I put it here since w_base.h
208  * always sucks this in and it is a compiler-dependency.
209  */
210 #if W_GCC_THIS_VER >= W_GCC_VER(3, 0)
211 #define w_offsetof(t, f) \
212  ((size_t)((char*)&(*(t*)sizeof(t)).f - (char *)&(*(t*)sizeof(t))))
213 #endif
214 
215 #endif /* __GNUC__ */
216 
217 /******************************************************************************
218  *
219  * C string bug
220  *
221  ******************************************************************************/
222 
223 /*
224  * a C string constant is of type (const char*). some routines assume that
225  * they are (char*). this is to cast away the const in those cases.
226  */
227 #define C_STRING_BUG (char *)
228 
229 
230 
231 /* This is really a library problem; stream.form() and stream.scan()
232  aren't standard, but GNUisms. On the other hand, they should
233  be in the standard, because they save us from static form() buffers.
234  Using the W_FORM() and W_FORM2() macros instead of
235  stream.form() or stream << form() encapsulates this use, so the
236  optimal solution can be used on each platform.
237  If a portable scan() equivalent is written, a similar set
238  of W_SCAN macros could encapuslate input scanning too.
239  */
240 #define W_FORM(stream) stream << form
241 
242 // in w_form.cpp
243 extern const char* form(const char*, ...);
244 
245 #define W_FORM2(stream, args) W_FORM(stream) args
246 
247 /*
248  * Try to use the system definition of offsetof, and provide one here
249  * if the system's isn't in the standard place.
250  */
251 #ifndef offsetof
252 #include <cstddef>
253 #endif
254 #ifndef offsetof
255 #define offsetof(type,member) ((size_t)((&(type *)0)->member))
256 #endif
257 
258 #ifndef w_offsetof
259 /* FRJ: Sun's CC returns an address near the top of the stack when
260  given ``offsetof(a, b.c())'', where c() returns a reference to a
261  private member of b. This seems to work around the issue (bug?).
262  OLD:
263  //template<class T>
264  //static T* get_null() { return nullptr; }
265  //#define w_offsetof(class,member) ((size_t) &get_null<class>()->member)
266  NEW: below
267  */
268 #define w_offsetof(class,member) offsetof(class,member)
269 #endif
270 
271 /*<std-footer incl-file-exclusion='W_WORKAROUND_H'> -- do not edit anything below this line -- */
272 
273 #endif // __W_WORKAROUND_H /*</std-footer>*/
const char * form(const char *,...)