LibreOffice: sal/types.h Source File

LibreOffice LibreOffice 7.0 SDK C/C++ API Reference

types.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20 #ifndef INCLUDED_SAL_TYPES_H
21 #define INCLUDED_SAL_TYPES_H
22
23 #include "sal/config.h"
24
25 #include <stddef.h>
26
27 #include "sal/macros.h"
28 #include "sal/typesizes.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 typedef unsigned char sal_Bool;
35 # define sal_False ((sal_Bool)0)
36 # define sal_True ((sal_Bool)1)
37
38 /* char is assumed to always be 1 byte long */
39 typedef signed char sal_Int8;
40 typedef unsigned char sal_uInt8;
41
42 #if SAL_TYPES_SIZEOFSHORT == 2
43 typedef signed short sal_Int16;
44 typedef unsigned short sal_uInt16;
45 #else
46 #error "Could not find 16-bit type, add support for your architecture"
47 #endif
48
49 #if SAL_TYPES_SIZEOFLONG == 4
50 typedef signed long sal_Int32;
51 typedef unsigned long sal_uInt32;
52 #define SAL_PRIdINT32 "ld"
53 #define SAL_PRIuUINT32 "lu"
54 #define SAL_PRIxUINT32 "lx"
55 #define SAL_PRIXUINT32 "lX"
56 #elif SAL_TYPES_SIZEOFINT == 4
57 typedef signed int sal_Int32;
58 typedef unsigned int sal_uInt32;
59 #define SAL_PRIdINT32 "d"
60 #define SAL_PRIuUINT32 "u"
61 #define SAL_PRIxUINT32 "x"
62 #define SAL_PRIXUINT32 "X"
63 #else
64 #error "Could not find 32-bit type, add support for your architecture"
65 #endif
66
67 #ifdef _MSC_VER
68 typedef __int64 sal_Int64;
69 typedef unsigned __int64 sal_uInt64;
70
71 /* The following are macros that will add the 64 bit constant suffix. */
72 #define SAL_CONST_INT64(x) x##i64
73 #define SAL_CONST_UINT64(x) x##ui64
74
75 #define SAL_PRIdINT64 "I64d"
76 #define SAL_PRIuUINT64 "I64u"
77 #define SAL_PRIxUINT64 "I64x"
78 #define SAL_PRIXUINT64 "I64X"
79 #elif defined (__GNUC__)
80 #if SAL_TYPES_SIZEOFLONG == 8
81 typedef signed long int sal_Int64;
82 typedef unsigned long int sal_uInt64;
83
84
85 /* The following are macros that will add the 64 bit constant suffix. */
86 #define SAL_CONST_INT64(x) x##l
87 #define SAL_CONST_UINT64(x) x##ul
88
89 #define SAL_PRIdINT64 "ld"
90 #define SAL_PRIuUINT64 "lu"
91 #define SAL_PRIxUINT64 "lx"
92 #define SAL_PRIXUINT64 "lX"
93 #elif SAL_TYPES_SIZEOFLONGLONG == 8
94 typedef signed long long sal_Int64;
95 typedef unsigned long long sal_uInt64;
96
97 /* The following are macros that will add the 64 bit constant suffix. */
98 #define SAL_CONST_INT64(x) x##ll
99 #define SAL_CONST_UINT64(x) x##ull
100
101 #define SAL_PRIdINT64 "lld"
102 #define SAL_PRIuUINT64 "llu"
103 #define SAL_PRIxUINT64 "llx"
104 #define SAL_PRIXUINT64 "llX"
105 #else
106 #error "Could not find 64-bit type, add support for your architecture"
107 #endif
108 #else
109 #error "Please define the 64-bit types for your architecture/compiler in include/sal/types.h"
110 #endif
111
116 typedef char sal_Char;
117
122 typedef signed char sal_sChar;
123
128 typedef unsigned char sal_uChar;
129
130 #if defined LIBO_INTERNAL_ONLY && defined __cplusplus
131 #define SAL_UNICODE_NOTEQUAL_WCHAR_T
132 typedef char16_t sal_Unicode;
133 #elif defined(_WIN32)
134 typedef wchar_t sal_Unicode;
135 #else
136 #define SAL_UNICODE_NOTEQUAL_WCHAR_T
137 typedef sal_uInt16 sal_Unicode;
138 #endif
139
140 typedef void * sal_Handle;
141
142 /* sal_Size should currently be the native width of the platform */
143 #if SAL_TYPES_SIZEOFPOINTER == 4
144 typedef sal_uInt32 sal_Size;
145 typedef sal_Int32 sal_sSize;
146 #elif SAL_TYPES_SIZEOFPOINTER == 8
147 typedef sal_uInt64 sal_Size;
148 typedef sal_Int64 sal_sSize;
149 #else
150 #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler"
151 #endif
152
153 /* sal_PtrDiff holds the result of a pointer subtraction */
154 #if SAL_TYPES_SIZEOFPOINTER == 4
155 typedef sal_Int32 sal_PtrDiff;
156 #elif SAL_TYPES_SIZEOFPOINTER == 8
157 typedef sal_Int64 sal_PtrDiff;
158 #else
159 #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler"
160 #endif
161
162 /* printf-style conversion specification length modifiers for size_t and
163 ptrdiff_t (most platforms support C99, MSC has its own extension) */
164 #if defined(_MSC_VER)
165 #define SAL_PRI_SIZET "I"
166 #define SAL_PRI_PTRDIFFT "I"
167 #else
168 #define SAL_PRI_SIZET "z"
169 #define SAL_PRI_PTRDIFFT "t"
170 #endif
171
172 /* sal_IntPtr, sal_uIntPtr are integer types designed to hold pointers so that any valid
173 * pointer to void can be converted to this type and back to a pointer to void and the
174 * result will compare to the original pointer */
175 #if SAL_TYPES_SIZEOFPOINTER == 4
176 typedef sal_Int32 sal_IntPtr;
177 typedef sal_uInt32 sal_uIntPtr;
178 #define SAL_PRIdINTPTR SAL_PRIdINT32
179 #define SAL_PRIuUINTPTR SAL_PRIuUINT32
180 #define SAL_PRIxUINTPTR SAL_PRIxUINT32
181 #define SAL_PRIXUINTPTR SAL_PRIXUINT32
182 #elif SAL_TYPES_SIZEOFPOINTER == 8
183 typedef sal_Int64 sal_IntPtr;
184 typedef sal_uInt64 sal_uIntPtr;
185 #define SAL_PRIdINTPTR SAL_PRIdINT64
186 #define SAL_PRIuUINTPTR SAL_PRIuUINT64
187 #define SAL_PRIxUINTPTR SAL_PRIxUINT64
188 #define SAL_PRIXUINTPTR SAL_PRIXUINT64
189 #else
190 #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler"
191 #endif
192
193 /* The following SAL_MIN_INTn defines codify the assumption that the signed
194 * sal_Int types use two's complement representation. Defining them as
195 * "-0x7F... - 1" instead of as "-0x80..." prevents warnings about applying the
196 * unary minus operator to unsigned quantities.
197 */
198 #define SAL_MIN_INT8 ((sal_Int8) (-0x7F - 1))
199 #define SAL_MAX_INT8 ((sal_Int8) 0x7F)
200 #define SAL_MAX_UINT8 ((sal_uInt8) 0xFF)
201 #define SAL_MIN_INT16 ((sal_Int16) (-0x7FFF - 1))
202 #define SAL_MAX_INT16 ((sal_Int16) 0x7FFF)
203 #define SAL_MAX_UINT16 ((sal_uInt16) 0xFFFF)
204 #define SAL_MIN_INT32 ((sal_Int32) (-0x7FFFFFFF - 1))
205 #define SAL_MAX_INT32 ((sal_Int32) 0x7FFFFFFF)
206 #define SAL_MAX_UINT32 ((sal_uInt32) 0xFFFFFFFF)
207 #define SAL_MIN_INT64 ((sal_Int64) (SAL_CONST_INT64(-0x7FFFFFFFFFFFFFFF) - 1))
208 #define SAL_MAX_INT64 ((sal_Int64) SAL_CONST_INT64(0x7FFFFFFFFFFFFFFF))
209 #define SAL_MAX_UINT64 ((sal_uInt64) SAL_CONST_UINT64(0xFFFFFFFFFFFFFFFF))
210
211 #if SAL_TYPES_SIZEOFPOINTER == 4
212 #define SAL_MAX_SSIZE SAL_MAX_INT32
213 #define SAL_MAX_SIZE SAL_MAX_UINT32
214 #elif SAL_TYPES_SIZEOFPOINTER == 8
215 #define SAL_MAX_SSIZE SAL_MAX_INT64
216 #define SAL_MAX_SIZE SAL_MAX_UINT64
217 #endif
218
219 #define SAL_MAX_ENUM 0x7fffffff
220
221 #if defined(_MSC_VER)
222 # define SAL_DLLPUBLIC_EXPORT __declspec(dllexport)
223 # define SAL_JNI_EXPORT __declspec(dllexport)
224 # define SAL_DLLPUBLIC_IMPORT __declspec(dllimport)
225 # define SAL_DLLPRIVATE
226 # define SAL_DLLPUBLIC_TEMPLATE
227 # define SAL_DLLPUBLIC_RTTI
228 # define SAL_CALL __cdecl
229 #elif defined SAL_UNX
230 # if defined(__GNUC__)
231 # if defined(DISABLE_DYNLOADING)
232 # define SAL_DLLPUBLIC_EXPORT __attribute__ ((visibility("hidden")))
233 # define SAL_JNI_EXPORT __attribute__ ((visibility("default")))
234 # define SAL_DLLPUBLIC_IMPORT __attribute__ ((visibility("hidden")))
235 # define SAL_DLLPRIVATE __attribute__ ((visibility("hidden")))
236 # define SAL_DLLPUBLIC_TEMPLATE __attribute__ ((visibility("hidden")))
237 # define SAL_DLLPUBLIC_RTTI
238 # else
239 # define SAL_DLLPUBLIC_EXPORT __attribute__ ((visibility("default")))
240 # define SAL_JNI_EXPORT __attribute__ ((visibility("default")))
241 # define SAL_DLLPUBLIC_IMPORT __attribute__ ((visibility("default")))
242 # define SAL_DLLPRIVATE __attribute__ ((visibility("hidden")))
243 # define SAL_DLLPUBLIC_TEMPLATE __attribute__ ((visibility("default")))
244 # if defined __clang__
245 # if __has_attribute(type_visibility)
246 # define SAL_DLLPUBLIC_RTTI __attribute__ ((type_visibility("default")))
247 # else
248 # define SAL_DLLPUBLIC_RTTI __attribute__ ((visibility("default")))
249 # endif
250 # else
251 # define SAL_DLLPUBLIC_RTTI
252 # endif
253 # endif
254 # else
255 # define SAL_DLLPUBLIC_EXPORT
256 # define SAL_JNI_EXPORT
257 # define SAL_DLLPUBLIC_IMPORT
258 # define SAL_DLLPRIVATE
259 # define SAL_DLLPUBLIC_TEMPLATE
260 # define SAL_DLLPUBLIC_RTTI
261 # endif
262 # define SAL_CALL
263 #else
264 # error("unknown platform")
265 #endif
266
273 #if defined(__GNUC__)
274 # if defined(DISABLE_DYNLOADING)
275 # define SAL_EXCEPTION_DLLPUBLIC_EXPORT __attribute__((visibility("default")))
276 # else
277 # define SAL_EXCEPTION_DLLPUBLIC_EXPORT SAL_DLLPUBLIC_EXPORT
278 # endif
279 # define SAL_EXCEPTION_DLLPRIVATE SAL_DLLPRIVATE
280 #else
281 # define SAL_EXCEPTION_DLLPUBLIC_EXPORT
282 # define SAL_EXCEPTION_DLLPRIVATE
283 #endif
284
291 #if defined LIBO_INTERNAL_ONLY && defined __cplusplus
292 #define SAL_WARN_UNUSED_RESULT [[nodiscard]]
293 #elif (defined __GNUC__ \
294 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))) \
295 || defined __clang__
296 # define SAL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
297 #else
298 # define SAL_WARN_UNUSED_RESULT
299 #endif
300
305 #ifdef _MSC_VER
306 # define SAL_NO_VTABLE __declspec(novtable)
307 #else
308 # define SAL_NO_VTABLE
309 #endif
310
311 #ifdef _WIN32
312 # pragma pack(push, 8)
313 #endif
314
317 typedef struct _sal_Sequence
318 {
321 sal_Int32 nRefCount;
324 sal_Int32 nElements;
327 char elements[1];
328 } sal_Sequence;
329
330 #define SAL_SEQUENCE_HEADER_SIZE ((sal_Size) offsetof(sal_Sequence,elements))
331
332 #if defined( _WIN32)
333 #pragma pack(pop)
334 #endif
335
336 #if defined __cplusplus
337
342 #define SAL_THROW_EXTERN_C() throw ()
343
348 #if defined(LIBO_INTERNAL_ONLY) && defined(__COVERITY__)
349 # define COVERITY_NOEXCEPT_FALSE noexcept(false)
350 #else
351 # define COVERITY_NOEXCEPT_FALSE
352 #endif
353
354 #else
355
356 #define SAL_THROW_EXTERN_C()
357
358 #endif
359
360 #ifdef __cplusplus
361 }
362 #endif /* __cplusplus */
363
364 #ifdef __cplusplus
365
366 enum __sal_NoAcquire
367 {
370 SAL_NO_ACQUIRE
371 };
372
373 namespace com { namespace sun { namespace star { } } }
374
379 namespace css = ::com::sun::star;
380
389 #if defined LIBO_INTERNAL_ONLY
390 #define SAL_DELETED_FUNCTION = delete
391 #else
392 #define SAL_DELETED_FUNCTION
393 #endif
394
402 #if defined LIBO_INTERNAL_ONLY
403 #define SAL_OVERRIDE override
404 #else
405 #define SAL_OVERRIDE
406 #endif
407
408 #endif /* __cplusplus */
409
410 #ifdef __cplusplus
411
412 namespace sal {
413
425 template< typename T1, typename T2 > inline T1 static_int_cast(T2 n) {
426 return static_cast< T1 >(n);
427 }
428
429 }
430
431 #else /* __cplusplus */
432
445 #define SAL_INT_CAST(type, expr) ((type) (expr))
446
447 #endif /* __cplusplus */
448
454 #if defined __GNUC__ || defined __clang__
455 #if defined LIBO_INTERNAL_ONLY
456 # define SAL_DEPRECATED(message) __attribute__((deprecated(message)))
457 #else
458 # define SAL_DEPRECATED(message) __attribute__((deprecated))
459 #endif
460 #elif defined(_MSC_VER)
461 # define SAL_DEPRECATED(message) __declspec(deprecated(message))
462 #else
463 # define SAL_DEPRECATED(message)
464 #endif
465
477 #ifdef LIBO_INTERNAL_ONLY
478 # define SAL_DEPRECATED_INTERNAL(message)
479 #else
480 # define SAL_DEPRECATED_INTERNAL(message) SAL_DEPRECATED(message)
481 #endif
482
490 #if defined LIBO_INTERNAL_ONLY && defined __GNUC__
491 #define SAL_WNODEPRECATED_DECLARATIONS_PUSH \
492 _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic push)) \
493 _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic ignored "-Wdeprecated-declarations"))
494 #define SAL_WNODEPRECATED_DECLARATIONS_POP \
495 _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic pop))
496 #else
497 # define SAL_WNODEPRECATED_DECLARATIONS_PUSH
498 # define SAL_WNODEPRECATED_DECLARATIONS_POP
499 #endif
500
517 #ifdef _MSC_VER
518 #define SAL_WNOUNREACHABLE_CODE_PUSH \
519 __pragma(warning(push)) \
520 __pragma(warning(disable:4702)) \
521 __pragma(warning(disable:4722))
522 #define SAL_WNOUNREACHABLE_CODE_POP \
523 __pragma(warning(pop))
524 #else
525 /* Add definitions for GCC and Clang if needed */
526 #define SAL_WNOUNREACHABLE_CODE_PUSH
527 #define SAL_WNOUNREACHABLE_CODE_POP
528 #endif
529
553 #if defined __cplusplus
554 #if defined __GNUC__ || defined __clang__
555 #define SAL_UNUSED_PARAMETER __attribute__ ((unused))
556 #else
557 #define SAL_UNUSED_PARAMETER
558 #endif
559 #endif
560
573 #if defined LIBO_INTERNAL_ONLY && (defined __GNUC__ || defined __clang__)
574 #define SAL_WARN_UNUSED __attribute__((warn_unused))
575 #else
576 #define SAL_WARN_UNUSED
577 #endif
578
580
581 #if defined __GNUC__ || defined __clang__
582 // Macro to try to catch and warn on assignments inside expr.
583 # define SAL_DETAIL_BOOLEAN_EXPR(expr) \
584 __extension__ ({ \
585 int sal_boolean_var_; \
586 if (expr) \
587 sal_boolean_var_ = 1; \
588 else \
589 sal_boolean_var_ = 0; \
590 sal_boolean_var_; \
591 })
592
603 # define SAL_LIKELY(expr) __builtin_expect(SAL_DETAIL_BOOLEAN_EXPR((expr)), 1)
604
615 # define SAL_UNLIKELY(expr) __builtin_expect(SAL_DETAIL_BOOLEAN_EXPR((expr)), 0)
616
628 # define SAL_HOT __attribute__((hot))
629
643 # define SAL_COLD __attribute__((cold))
644 #else
645 # define SAL_LIKELY(expr) (expr)
646 # define SAL_UNLIKELY(expr) (expr)
647 # define SAL_HOT
648 # define SAL_COLD
649 #endif
650
652
654
663 #ifndef __has_attribute
664 #define __has_attribute(x) 0
665 #endif
666
667 #if defined LIBO_INTERNAL_ONLY && ((defined __GNUC__ && !defined __clang__) || (defined __clang__ && __has_attribute(returns_nonnull)))
668 #define SAL_RETURNS_NONNULL __attribute__((returns_nonnull))
669 #else
670 #define SAL_RETURNS_NONNULL
671 #endif
672
674 #endif // INCLUDED_SAL_TYPES_H
675
676 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
com::sun::star
Definition: types.h:373
sal_Char
char sal_Char
A legacy synonym for char.
Definition: types.h:116
SAL_NO_ACQUIRE
@ SAL_NO_ACQUIRE
definition of a no acquire enum for ctors
Definition: types.h:370
sal_Handle
void * sal_Handle
Definition: types.h:140
sal
Definition: types.h:412
sal_uInt8
unsigned char sal_uInt8
Definition: types.h:40
sal_Sequence
struct _sal_Sequence sal_Sequence
This is the binary specification of a SAL sequence.
_sal_Sequence::nRefCount
sal_Int32 nRefCount
reference count of sequence
Definition: types.h:321
sal_Bool
unsigned char sal_Bool
Definition: types.h:34
config.h
__sal_NoAcquire
__sal_NoAcquire
Definition: types.h:367
com
Definition: types.h:373
_sal_Sequence::nElements
sal_Int32 nElements
element count
Definition: types.h:324
typesizes.h
_sal_Sequence::elements
char elements[1]
elements array
Definition: types.h:327
macros.h
sal_Unicode
sal_uInt16 sal_Unicode
Definition: types.h:137
_sal_Sequence
This is the binary specification of a SAL sequence.
Definition: types.h:318
sal_uChar
unsigned char sal_uChar
A legacy synonym for unsigned char.
Definition: types.h:128
sal_sChar
signed char sal_sChar
A legacy synonym for signed char.
Definition: types.h:122
sal_Int8
signed char sal_Int8
Definition: types.h:39
sal::static_int_cast
T1 static_int_cast(T2 n)
A static_cast between integral types, to avoid C++ compiler warnings.
Definition: types.h:425