Skip to content

Commit 3485f1b

Browse files
authored
add portable nonnull macros (ros2#382)
* add portable nonnull macros Signed-off-by: William Woodall <william@osrfoundation.org> * undo spurious change Signed-off-by: William Woodall <william@osrfoundation.org> * uncrustify Signed-off-by: William Woodall <william@osrfoundation.org> Signed-off-by: William Woodall <william@osrfoundation.org>
1 parent 9a84764 commit 3485f1b

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

include/rcutils/macros.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
/// \file
15+
/// @file
1616

1717
#ifndef RCUTILS__MACROS_H_
1818
#define RCUTILS__MACROS_H_
@@ -30,7 +30,7 @@ extern "C"
3030
#define RCUTILS_WARN_UNUSED _Check_return_
3131
#endif
3232

33-
/// @cond Doxygen_Suppress
33+
/// \cond Doxygen_Suppress
3434
// This block either sets RCUTILS_THREAD_LOCAL or RCUTILS_THREAD_LOCAL_PTHREAD.
3535
#if defined _WIN32 || defined __CYGWIN__
3636
// Windows or Cygwin
@@ -142,6 +142,19 @@ extern "C"
142142
# define RCUTILS_UNLIKELY(x) (x)
143143
#endif // _WIN32
144144

145+
// Provide the compiler a hint about an argument being nonnull when possible.
146+
#ifndef _WIN32
147+
# define RCUTILS_NONNULL __attribute__((__nonnull__))
148+
# define RCUTILS_NONNULL_ARGS(...) __attribute__((__nonnull__(__VA_ARGS__)))
149+
# define RCUTILS_RETURNS_NONNULL __attribute__((__returns_nonnull__))
150+
# define RCUTILS_HAS_NONNULL 1
151+
#else
152+
# define RCUTILS_NONNULL
153+
# define RCUTILS_NONNULL_ARGS(...)
154+
# define RCUTILS_RETURNS_NONNULL
155+
# define RCUTILS_HAS_NONNULL 0
156+
#endif // _WIN32
157+
145158
#if defined RCUTILS_ENABLE_FAULT_INJECTION
146159
#include "rcutils/testing/fault_injection.h"
147160

0 commit comments

Comments
 (0)