Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
macros.h
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17 
18 #ifndef ARROW_UTIL_MACROS_H
19 #define ARROW_UTIL_MACROS_H
20 
21 // From Google gutil
22 #ifndef ARROW_DISALLOW_COPY_AND_ASSIGN
23 #define ARROW_DISALLOW_COPY_AND_ASSIGN(TypeName) \
24  TypeName(const TypeName&) = delete; \
25  void operator=(const TypeName&) = delete
26 #endif
27 
28 #define ARROW_UNUSED(x) (void)x
29 #define ARROW_ARG_UNUSED(x)
30 //
31 // GCC can be told that a certain branch is not likely to be taken (for
32 // instance, a CHECK failure), and use that information in static analysis.
33 // Giving it this information can help it optimize for the common case in
34 // the absence of better information (ie. -fprofile-arcs).
35 //
36 #if defined(__GNUC__)
37 #define ARROW_PREDICT_FALSE(x) (__builtin_expect(x, 0))
38 #define ARROW_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
39 #define ARROW_NORETURN __attribute__((noreturn))
40 #define ARROW_PREFETCH(addr) __builtin_prefetch(addr)
41 #elif defined(_MSC_VER)
42 #define ARROW_NORETURN __declspec(noreturn)
43 #define ARROW_PREDICT_FALSE(x) x
44 #define ARROW_PREDICT_TRUE(x) x
45 #define ARROW_PREFETCH(addr)
46 #else
47 #define ARROW_NORETURN
48 #define ARROW_PREDICT_FALSE(x) x
49 #define ARROW_PREDICT_TRUE(x) x
50 #define ARROW_PREFETCH(addr)
51 #endif
52 
53 #if (defined(__GNUC__) || defined(__APPLE__))
54 #define ARROW_MUST_USE_RESULT __attribute__((warn_unused_result))
55 #elif defined(_MSC_VER)
56 #define ARROW_MUST_USE_RESULT
57 #else
58 #define ARROW_MUST_USE_RESULT
59 #endif
60 
61 // ----------------------------------------------------------------------
62 // C++/CLI support macros (see ARROW-1134)
63 
64 #ifndef NULLPTR
65 
66 #ifdef __cplusplus_cli
67 #define NULLPTR __nullptr
68 #else
69 #define NULLPTR nullptr
70 #endif
71 
72 #endif // ifndef NULLPTR
73 
74 // ----------------------------------------------------------------------
75 
76 // macros to disable padding
77 // these macros are portable across different compilers and platforms
78 //[https://github.com/google/flatbuffers/blob/master/include/flatbuffers/flatbuffers.h#L1355]
79 #if !defined(MANUALLY_ALIGNED_STRUCT)
80 #if defined(_MSC_VER)
81 #define MANUALLY_ALIGNED_STRUCT(alignment) \
82  __pragma(pack(1)); \
83  struct __declspec(align(alignment))
84 #define STRUCT_END(name, size) \
85  __pragma(pack()); \
86  static_assert(sizeof(name) == size, "compiler breaks packing rules")
87 #elif defined(__GNUC__) || defined(__clang__)
88 #define MANUALLY_ALIGNED_STRUCT(alignment) \
89  _Pragma("pack(1)") struct __attribute__((aligned(alignment)))
90 #define STRUCT_END(name, size) \
91  _Pragma("pack()") static_assert(sizeof(name) == size, "compiler breaks packing rules")
92 #else
93 #error Unknown compiler, please define structure alignment macros
94 #endif
95 #endif // !defined(MANUALLY_ALIGNED_STRUCT)
96 
97 #endif // ARROW_UTIL_MACROS_H