1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #ifndef _SAL_TYPES_H_
25 #define _SAL_TYPES_H_
26
27 #include <sal/config.h>
28
29 /* Grab __SIZEOFxxx constants from typesconfig tool on Unix */
30 #if defined UNX
31 #include <sal/typesizes.h>
32 #elif defined(WNT)
33 /* FIXME: autogeneration of type sizes on Win32/Win64? */
34 #define SAL_TYPES_ALIGNMENT2 1
35 #define SAL_TYPES_ALIGNMENT4 1
36 #define SAL_TYPES_ALIGNMENT8 1
37 #define SAL_TYPES_SIZEOFSHORT 2
38 #define SAL_TYPES_SIZEOFINT 4
39 #define SAL_TYPES_SIZEOFLONG 4
40 #define SAL_TYPES_SIZEOFLONGLONG 8
41 #if defined(_M_IX86)
42 #define SAL_TYPES_SIZEOFPOINTER 4
43 #elif defined(_M_AMD64)
44 #define SAL_TYPES_SIZEOFPOINTER 8
45 #endif
46 #elif defined(OS2)
47 #define SAL_TYPES_ALIGNMENT2 1
48 #define SAL_TYPES_ALIGNMENT4 1
49 #define SAL_TYPES_ALIGNMENT8 1
50 #define SAL_TYPES_SIZEOFSHORT 2
51 #define SAL_TYPES_SIZEOFINT 4
52 #define SAL_TYPES_SIZEOFLONG 4
53 #define SAL_TYPES_SIZEOFLONGLONG 8
54 #define SAL_TYPES_SIZEOFPOINTER 4
55 #endif
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61 /********************************************************************************/
62 /* Data types
63 */
64
65 /* Boolean */
66 typedef unsigned char sal_Bool;
67 # define sal_False ((sal_Bool)0)
68 # define sal_True ((sal_Bool)1)
69
70 /* char is assumed to always be 1 byte long */
71 typedef signed char sal_Int8;
72 typedef unsigned char sal_uInt8;
73
74 #if SAL_TYPES_SIZEOFSHORT == 2
75 typedef signed short sal_Int16;
76 typedef unsigned short sal_uInt16;
77 #else
78 #error "Could not find 16-bit type, add support for your architecture"
79 #endif
80
81 #if SAL_TYPES_SIZEOFLONG == 4
82 typedef signed long sal_Int32;
83 typedef unsigned long sal_uInt32;
84 #define SAL_PRIdINT32 "ld"
85 #define SAL_PRIuUINT32 "lu"
86 #define SAL_PRIxUINT32 "lx"
87 #define SAL_PRIXUINT32 "lX"
88 #elif SAL_TYPES_SIZEOFINT == 4
89 typedef signed int sal_Int32;
90 typedef unsigned int sal_uInt32;
91 #define SAL_PRIdINT32 "d"
92 #define SAL_PRIuUINT32 "u"
93 #define SAL_PRIxUINT32 "x"
94 #define SAL_PRIXUINT32 "X"
95 #else
96 #error "Could not find 32-bit type, add support for your architecture"
97 #endif
98
99 #if (_MSC_VER >= 1000)
100 typedef __int64 sal_Int64;
101 typedef unsigned __int64 sal_uInt64;
102
103 /* The following are macros that will add the 64 bit constant suffix. */
104 #define SAL_CONST_INT64(x) x##i64
105 #define SAL_CONST_UINT64(x) x##ui64
106
107 #define SAL_PRIdINT64 "I64d"
108 #define SAL_PRIuUINT64 "I64u"
109 #define SAL_PRIxUINT64 "I64x"
110 #define SAL_PRIXUINT64 "I64X"
111 #elif defined(__SUNPRO_CC) || defined(__SUNPRO_C) || defined (__GNUC__) || defined(__hpux) || defined (sgi)
112 #if SAL_TYPES_SIZEOFLONG == 8
113 typedef signed long int sal_Int64;
114 typedef unsigned long int sal_uInt64;
115
116
117 /* The following are macros that will add the 64 bit constant suffix. */
118 #define SAL_CONST_INT64(x) x##l
119 #define SAL_CONST_UINT64(x) x##ul
120
121 #define SAL_PRIdINT64 "ld"
122 #define SAL_PRIuUINT64 "lu"
123 #define SAL_PRIxUINT64 "lx"
124 #define SAL_PRIXUINT64 "lX"
125 #elif SAL_TYPES_SIZEOFLONGLONG == 8
126 typedef signed long long sal_Int64;
127 typedef unsigned long long sal_uInt64;
128
129 /* The following are macros that will add the 64 bit constant suffix. */
130 #define SAL_CONST_INT64(x) x##ll
131 #define SAL_CONST_UINT64(x) x##ull
132
133 #ifdef __MINGW32__
134 #define SAL_PRIdINT64 "I64d"
135 #define SAL_PRIuUINT64 "I64u"
136 #define SAL_PRIxUINT64 "I64x"
137 #define SAL_PRIXUINT64 "I64X"
138 #else
139 #define SAL_PRIdINT64 "lld"
140 #define SAL_PRIuUINT64 "llu"
141 #define SAL_PRIxUINT64 "llx"
142 #define SAL_PRIXUINT64 "llX"
143 #endif
144 #else
145 #error "Could not find 64-bit type, add support for your architecture"
146 #endif
147 #else
148 #error "Please define the 64-bit types for your architecture/compiler in sal/inc/sal/types.h"
149 #endif
150
151 typedef char sal_Char;
152 typedef signed char sal_sChar;
153 typedef unsigned char sal_uChar;
154
155 #if ( defined(SAL_W32) && !defined(__MINGW32__) )
156 typedef wchar_t sal_Unicode;
157 #else
158 #define SAL_UNICODE_NOTEQUAL_WCHAR_T
159 typedef sal_uInt16 sal_Unicode;
160 #endif
161
162 typedef void * sal_Handle;
163
164 /* sal_Size should currently be the native width of the platform */
165 #if SAL_TYPES_SIZEOFPOINTER == 4
166 typedef sal_uInt32 sal_Size;
167 typedef sal_Int32 sal_sSize;
168 #elif SAL_TYPES_SIZEOFPOINTER == 8
169 typedef sal_uInt64 sal_Size;
170 typedef sal_Int64 sal_sSize;
171 #else
172 #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler"
173 #endif
174
175 /* sal_PtrDiff holds the result of a pointer subtraction */
176 #if SAL_TYPES_SIZEOFPOINTER == 4
177 typedef sal_Int32 sal_PtrDiff;
178 #elif SAL_TYPES_SIZEOFPOINTER == 8
179 typedef sal_Int64 sal_PtrDiff;
180 #else
181 #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler"
182 #endif
183
184 /* printf-style conversion specification length modifiers for size_t and
185 ptrdiff_t (most platforms support C99, MSC has its own extension) */
186 #if defined(_MSC_VER) || defined(__MINGW32__)
187 #define SAL_PRI_SIZET "I"
188 #define SAL_PRI_PTRDIFFT "I"
189 #else
190 #define SAL_PRI_SIZET "z"
191 #define SAL_PRI_PTRDIFFT "t"
192 #endif
193
194 /* sal_IntPtr, sal_uIntPtr are integer types designed to hold pointers so that any valid
195 * pointer to void can be converted to this type and back to a pointer to void and the
196 * result will compare to the original pointer */
197 #if SAL_TYPES_SIZEOFPOINTER == 4
198 typedef sal_Int32 sal_IntPtr;
199 typedef sal_uInt32 sal_uIntPtr;
200 #define SAL_PRIdINTPTR SAL_PRIdINT32
201 #define SAL_PRIuUINTPTR SAL_PRIuUINT32
202 #define SAL_PRIxUINTPTR SAL_PRIxUINT32
203 #define SAL_PRIXUINTPTR SAL_PRIXUINT32
204 #elif SAL_TYPES_SIZEOFPOINTER == 8
205 typedef sal_Int64 sal_IntPtr;
206 typedef sal_uInt64 sal_uIntPtr;
207 #define SAL_PRIdINTPTR SAL_PRIdINT64
208 #define SAL_PRIuUINTPTR SAL_PRIuUINT64
209 #define SAL_PRIxUINTPTR SAL_PRIxUINT64
210 #define SAL_PRIXUINTPTR SAL_PRIXUINT64
211 #else
212 #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler"
213 #endif
214
215 /********************************************************************************/
216 /* Useful defines
217 */
218
219 /* The following SAL_MIN_INTn defines codify the assumption that the signed
220 * sal_Int types use two's complement representation. Defining them as
221 * "-0x7F... - 1" instead of as "-0x80..." prevents warnings about applying the
222 * unary minus operator to unsigned quantities.
223 */
224 #define SAL_MIN_INT8 ((sal_Int8) (-0x7F - 1))
225 #define SAL_MAX_INT8 ((sal_Int8) 0x7F)
226 #define SAL_MAX_UINT8 ((sal_uInt8) 0xFF)
227 #define SAL_MIN_INT16 ((sal_Int16) (-0x7FFF - 1))
228 #define SAL_MAX_INT16 ((sal_Int16) 0x7FFF)
229 #define SAL_MAX_UINT16 ((sal_uInt16) 0xFFFF)
230 #define SAL_MIN_INT32 ((sal_Int32) (-0x7FFFFFFF - 1))
231 #define SAL_MAX_INT32 ((sal_Int32) 0x7FFFFFFF)
232 #define SAL_MAX_UINT32 ((sal_uInt32) 0xFFFFFFFF)
233 #define SAL_MIN_INT64 ((sal_Int64) (SAL_CONST_INT64(-0x7FFFFFFFFFFFFFFF) - 1))
234 #define SAL_MAX_INT64 ((sal_Int64) SAL_CONST_INT64(0x7FFFFFFFFFFFFFFF))
235 #define SAL_MAX_UINT64 ((sal_uInt64) SAL_CONST_UINT64(0xFFFFFFFFFFFFFFFF))
236
237 #if SAL_TYPES_SIZEOFLONG == 4
238 #define SAL_MAX_SSIZE SAL_MAX_INT32
239 #define SAL_MAX_SIZE SAL_MAX_UINT32
240 #elif SAL_TYPES_SIZEOFLONG == 8
241 #define SAL_MAX_SSIZE SAL_MAX_INT64
242 #define SAL_MAX_SIZE SAL_MAX_UINT64
243 #endif
244
245 #if defined(SAL_W32) || defined(SAL_OS2) || defined(SAL_UNX)
246 # define SAL_MAX_ENUM 0x7fffffff
247 #elif defined(SAL_W16)
248 # define SAL_MAX_ENUM 0x7fff
249 #endif
250
251 #if defined(__clang__)
252 #define SAL_UNUSED __attribute__((__unused__))
253 #define SAL_UNUSED_MEMBER __attribute__((__unused__))
254 #elif defined(__GNUC__)
255 #define SAL_UNUSED __attribute__((__unused__))
256 #define SAL_UNUSED_MEMBER
257 #elif defined(_MSC_VER)
258 #define SAL_UNUSED __pragma(warning(suppress:4100;suppress:4101))
259 #define SAL_UNUSED_MEMBER __pragma(warning(suppress:4100;suppress:4101))
260 #else
261 #define SAL_UNUSED
262 #define SAL_UNUSED_MEMBER
263 #endif
264
265 #if defined(_MSC_VER) || defined(__MINGW32__)
266 # define SAL_DLLPUBLIC_EXPORT __declspec(dllexport)
267 #if defined(_MSC_VER)
268 # define SAL_DLLPUBLIC_IMPORT __declspec(dllimport)
269 #else
270 # define SAL_DLLPUBLIC_IMPORT
271 #endif // defined(_MSC_VER)
272 # define SAL_DLLPRIVATE
273 #if defined(_MSC_VER)
274 # define SAL_CALL __cdecl
275 # define SAL_CALL_ELLIPSE __cdecl
276 #else
277 # define SAL_CALL
278 # define SAL_CALL_ELLIPSE
279 #endif
280 #elif defined SAL_OS2 // YD
281 /* YD 25/09/2007 gcc doesn't like imports inside class members */
282 //# define SAL_DLLPUBLIC_EXPORT
283 /* YD 01/11/2011 */
284 # define SAL_DLLPUBLIC_EXPORT __declspec(dllexport)
285 # define SAL_DLLPUBLIC_IMPORT
286 # define SAL_DLLPRIVATE
287 # define SAL_CALL
288 # define SAL_CALL_ELLIPSE
289 #elif defined SAL_UNX
290 # if defined(__SUNPRO_CC) && (__SUNPRO_CC >= 0x550)
291 # define SAL_DLLPUBLIC_EXPORT __global
292 # define SAL_DLLPUBLIC_IMPORT
293 # define SAL_DLLPRIVATE __hidden
294 # elif defined(__SUNPRO_C ) && (__SUNPRO_C >= 0x550)
295 # define SAL_DLLPUBLIC_EXPORT __global
296 # define SAL_DLLPUBLIC_IMPORT
297 # define SAL_DLLPRIVATE __hidden
298 # elif defined(HAVE_GCC_VISIBILITY_FEATURE)
299 # define SAL_DLLPUBLIC_EXPORT __attribute__ ((visibility("default")))
300 # define SAL_DLLPUBLIC_IMPORT
301 # define SAL_DLLPRIVATE __attribute__ ((visibility("hidden")))
302 # else
303 # define SAL_DLLPUBLIC_EXPORT
304 # define SAL_DLLPUBLIC_IMPORT
305 # define SAL_DLLPRIVATE
306 # endif
307 # define SAL_CALL
308 # define SAL_CALL_ELLIPSE
309 #else
310 # error("unknown platform")
311 #endif
312
313 /**
314 Exporting the symbols necessary for exception handling on GCC.
315
316 These macros are used for inline declarations of exception classes, as in
317 rtl/malformeduriexception.hxx.
318 */
319 #if defined(__GNUC__) && ! defined(__MINGW32__)
320 #define SAL_EXCEPTION_DLLPUBLIC_EXPORT SAL_DLLPUBLIC_EXPORT
321 #define SAL_EXCEPTION_DLLPRIVATE SAL_DLLPRIVATE
322 #else
323 #define SAL_EXCEPTION_DLLPUBLIC_EXPORT
324 #define SAL_EXCEPTION_DLLPRIVATE
325 #endif
326
327 /** Use this for pure virtual classes, e.g. class SAL_NO_VTABLE Foo { ...
328 This hinders the compiler from setting a generic vtable stating that
329 a pure virtual function was called and thus slightly reduces code size.
330 */
331 #ifdef _MSC_VER
332 # define SAL_NO_VTABLE __declspec(novtable)
333 #else
334 # define SAL_NO_VTABLE
335 #endif
336
337 #ifdef SAL_W32
338 # pragma pack(push, 8)
339 #elif defined(SAL_OS2)
340 # pragma pack(push, 4)
341 #endif
342
343 /** This is the binary specification of a SAL sequence.
344 <br>
345 */
346 typedef struct _sal_Sequence
347 {
348 /** reference count of sequence<br>
349 */
350 sal_Int32 nRefCount;
351 /** element count<br>
352 */
353 sal_Int32 nElements;
354 /** elements array<br>
355 */
356 char elements[1];
357 } sal_Sequence;
358
359 #define SAL_SEQUENCE_HEADER_SIZE ((sal_Size)&((sal_Sequence *)0)->elements)
360
361 #if defined( SAL_W32) || defined(SAL_OS2)
362 #pragma pack(pop)
363 #endif
364
365
366 /** Wrap C++ const_cast, reinterpret_cast and static_cast expressions in
367 macros to keep code portable to old compilers (since most compilers still
368 lack RTTI support, dynamic_cast is not included here).
369 */
370 #ifdef __cplusplus
371 #if defined SAL_W32 || defined SOLARIS || defined LINUX || defined MACOSX || defined FREEBSD || defined NETBSD || defined AIX || defined OS2
372 #define SAL_CONST_CAST(type, expr) (const_cast< type >(expr))
373 #define SAL_REINTERPRET_CAST(type, expr) (reinterpret_cast< type >(expr))
374 #define SAL_STATIC_CAST(type, expr) (static_cast< type >(expr))
375 #else /* SAL_W32, SOLARIS, LINUX */
376 #define SAL_CONST_CAST(type, expr) ((type) (expr))
377 #define SAL_REINTERPRET_CAST(type, expr) ((type) (expr))
378 #define SAL_STATIC_CAST(type, expr) ((type) (expr))
379 #endif /* SAL_W32, SOLARIS, LINUX */
380 #endif /* __cplusplus */
381
382 /** Definition of function throw clause macros. These have been introduced
383 to reduce code size by balancing out compiler bugs.
384
385 These macros are ONLY for function declarations,
386 use common C++ throw statement for throwing exceptions, e.g.
387 throw RuntimeException();
388
389 SAL_THROW() should be used for all C++ functions, e.g. SAL_THROW( () )
390 SAL_THROW_EXTERN_C() should be used for all C functions
391 */
392 #ifdef __cplusplus
393 #if defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__sgi)
394 #define SAL_THROW( exc )
395 #else /* MSVC, all other */
396 #define SAL_THROW( exc ) throw exc
397 #endif /* __GNUC__, __SUNPRO_CC */
398 #define SAL_THROW_EXTERN_C() throw ()
399 #else /* ! __cplusplus */
400 /* SAL_THROW() must not be used in C headers, only SAL_THROW_EXTERN_C() is defined */
401 #define SAL_THROW_EXTERN_C()
402 #endif
403
404
405
406 #ifdef __cplusplus
407 enum __sal_NoAcquire
408 {
409 /** definition of a no acquire enum for ctors
410 */
411 SAL_NO_ACQUIRE
412 };
413 #endif /* __cplusplus */
414
415
416 #ifdef __cplusplus
417 }
418 #endif /* __cplusplus */
419
420 #ifdef __cplusplus
421
422 namespace sal {
423
424 /**
425 A static_cast between integral types, to avoid C++ compiler warnings.
426
427 In C++ source code, use sal::static_int_cast<T>(n) instead of
428 static_cast<T>(n) whenever a compiler warning about integral type problems
429 shall be silenced. That way, source code that needs to be modified when the
430 type of any of the expressions involved in the compiler warning is changed
431 can be found more easily.
432
433 Both template arguments T1 and T2 must be integral types.
434 */
static_int_cast(T2 n)435 template< typename T1, typename T2 > inline T1 static_int_cast(T2 n) {
436 return static_cast< T1 >(n);
437 }
438
439 }
440
441 #else /* __cplusplus */
442
443 /**
444 A cast between integer types, to avoid C compiler warnings.
445
446 In C source code, use SAL_INT_CAST(type, expr) instead of ((type) (expr))
447 whenever a compiler warning about integer type problems shall be silenced.
448 That way, source code that needs to be modified when the type of any of the
449 expressions involved in the compiler warning is changed can be found more
450 easily.
451
452 The argument 'type' must be an integer type and the argument 'expr' must be
453 an integer expression. Both arguments are evaluated exactly once.
454 */
455 #define SAL_INT_CAST(type, expr) ((type) (expr))
456
457 #endif /* __cplusplus */
458
459 #endif /*_SAL_TYPES_H_ */
460
461