cc: Reset resource update controller on closing of layer tree host
[chromium-blink-merge.git] / ppapi / c / pp_macros.h
bloba552885ea1d1dd6f7b102a47389bcfe039cc4796
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
6 /* From pp_macros.idl modified Wed Apr 10 11:57:14 2013. */
8 #ifndef PPAPI_C_PP_MACROS_H_
9 #define PPAPI_C_PP_MACROS_H_
12 #define PPAPI_RELEASE 31
14 /**
15 * @file
16 * Defines the common macros such as assert, inline, ...
22 * @addtogroup PP
23 * @{
26 /* Use PP_INLINE to tell the compiler to inline functions. The main purpose of
27 * inline functions in ppapi is to allow us to define convenience functions in
28 * the ppapi header files, without requiring clients or implementers to link a
29 * PPAPI C library. The "inline" keyword is not supported by pre-C99 C
30 * compilers (such as MS Visual Studio 2008 and older versions of GCC). MSVS
31 * supports __forceinline and GCC supports __inline__. Use of the static
32 * keyword ensures (in C) that the function is not compiled on its own, which
33 * could cause multiple definition errors.
34 * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx
35 * http://gcc.gnu.org/onlinedocs/gcc/Inline.html
37 #if defined(__cplusplus)
38 /* The inline keyword is part of C++ and guarantees we won't get multiple
39 * definition errors.
41 # define PP_INLINE inline
42 #else
43 # if defined(_MSC_VER)
44 # define PP_INLINE static __forceinline
45 # else
46 # define PP_INLINE static __inline__
47 # endif
48 #endif
50 /* This is a compile-time assertion useful for ensuring that a given type is
51 a given number of bytes wide. The size of the array is designed to be 1
52 (which should always be valid) if the enum's size is SIZE, and otherwise the
53 size of the array will be -1 (which all/most compilers should flag as an
54 error). This is wrapped inside a struct, because if it is a simple global
55 we get multiple definition errors at link time.
57 NAME is the name of the type without any spaces or the struct or enum
58 keywords.
60 CTYPENAME is the typename required by C. I.e., for a struct or enum, the
61 appropriate keyword must be included.
63 SIZE is the expected size in bytes.
65 #define PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, CTYPENAME, SIZE) \
66 struct PP_Dummy_Struct_For_##NAME { \
67 char _COMPILE_ASSERT_FAILED_The_type_named_ \
68 ## NAME ## _is_not_ ## SIZE ## \
69 _bytes_wide[(sizeof(CTYPENAME) == SIZE) ? 1 : -1]; }
71 /* PP_COMPILE_ASSERT_SIZE_IN_BYTES is for typenames that contain no spaces.
72 E.g.:
73 PP_COMPILE_ASSERT_SIZE_IN_BYTES(int, 4);
74 typedef struct { int a; } Foo;
75 PP_COMPILE_ASSERT_SIZE_IN_BYTES(Foo, 4);
77 #define PP_COMPILE_ASSERT_SIZE_IN_BYTES(NAME, SIZE) \
78 PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, NAME, SIZE)
80 /* PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES is for typenames that contain 'struct'
81 in C. That is, struct names that are not typedefs.
82 E.g.:
83 struct Foo { int a; };
84 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(Foo, 4);
86 #define PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(NAME, SIZE) \
87 PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, struct NAME, SIZE)
89 /* PP_COMPILE_ASSERT_ENUM_SIZE_IN_BYTES is for typenames that contain 'enum'
90 in C. That is, enum names that are not typedefs.
91 E.g.:
92 enum Bar { A = 0, B = 1 };
93 PP_COMPILE_ASSERT_ENUM_SIZE_IN_BYTES(Foo, 4);
95 #define PP_COMPILE_ASSERT_ENUM_SIZE_IN_BYTES(NAME, SIZE) \
96 PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, enum NAME, SIZE)
98 /* This is roughly copied from base/compiler_specific.h, and makes it possible
99 to pass 'this' in a constructor initializer list, when you really mean it.
100 E.g.:
101 Foo::Foo(MyInstance* instance)
102 : PP_ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {}
104 #if defined(_MSC_VER)
105 # define PP_ALLOW_THIS_IN_INITIALIZER_LIST(code) \
106 __pragma(warning(push)) \
107 __pragma(warning(disable:4355)) \
108 code \
109 __pragma(warning(pop))
110 #else
111 # define PP_ALLOW_THIS_IN_INITIALIZER_LIST(code) code
112 #endif
115 * @}
116 * End of addtogroup PP
119 #endif /* PPAPI_C_PP_MACROS_H_ */