summaryrefslogtreecommitdiff
path: root/gjs/macros.h
blob: 951099764fa32d65097d01378ba5f6e30bf1d331 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
/*
 * SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
 * SPDX-FileCopyrightText: 2017 Chun-wei Fan
 */

#ifndef GJS_MACROS_H_
#define GJS_MACROS_H_

#include <glib.h>

#ifdef G_OS_WIN32
# ifdef GJS_COMPILATION
#  define GJS_EXPORT __declspec(dllexport)
# else
#  define GJS_EXPORT __declspec(dllimport)
# endif
#    define siginfo_t void
#else
#    define GJS_EXPORT __attribute__((visibility("default")))
#endif

/**
 * GJS_USE:
 *
 * Indicates a return value must be used, or the compiler should log a warning.
 * Equivalent to [[nodiscard]], but this macro is for use in external headers
 * which are not necessarily compiled with a C++ compiler.
 */
#if defined(__GNUC__) || defined(__clang__)
#    define GJS_USE __attribute__((warn_unused_result))
#else
#    define GJS_USE
#endif

/**
 * GJS_JSAPI_RETURN_CONVENTION:
 *
 * Same as [[nodiscard]], but indicates that a return value of true or non-null
 * means that no exception must be pending on the passed-in #JSContext.
 * Conversely, a return value of false or nullptr means that an exception must
 * be pending, or else an uncatchable exception has been thrown.
 *
 * It's intended for use by static analysis tools to do better consistency
 * checks. If not using them, then it has the same effect as [[nodiscard]].
 * It's also intended as documentation for the programmer.
 */
#ifdef __clang_analyzer__
#    define GJS_JSAPI_RETURN_CONVENTION \
        [[nodiscard]] __attribute__((annotate("jsapi_return_convention")))
#else
#    define GJS_JSAPI_RETURN_CONVENTION [[nodiscard]]
#endif

#ifdef __GNUC__
#    define GJS_ALWAYS_INLINE __attribute__((always_inline))
#else
#    define GJS_ALWAYS_INLINE
#endif

#endif /* GJS_MACROS_H_ */