Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: ppapi/c/pp_macros.h

Issue 5674004: Add compile assertions to enforce the sizes of all structs and enums in the C... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef PPAPI_C_PP_MACROS_H_ 5 #ifndef PPAPI_C_PP_MACROS_H_
6 #define PPAPI_C_PP_MACROS_H_ 6 #define PPAPI_C_PP_MACROS_H_
7 7
8 /** 8 /**
9 * @file 9 * @file
10 * Defines the API ... 10 * Defines the API ...
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 NAME is the name of the type without any spaces or the struct or enum 47 NAME is the name of the type without any spaces or the struct or enum
48 keywords. 48 keywords.
49 49
50 CTYPENAME is the typename required by C. I.e., for a struct or enum, the 50 CTYPENAME is the typename required by C. I.e., for a struct or enum, the
51 appropriate keyword must be included. 51 appropriate keyword must be included.
52 52
53 SIZE is the expected size in bytes. 53 SIZE is the expected size in bytes.
54 */ 54 */
55 #define PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, CTYPENAME, SIZE) \ 55 #define PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, CTYPENAME, SIZE) \
56 struct _dummy_struct_for_##NAME { \ 56 struct PP_Dummy_Struct_For_##NAME { \
57 char _COMPILE_ASSERT_FAILED_The_type_named_ \ 57 char _COMPILE_ASSERT_FAILED_The_type_named_ \
58 ## NAME ## _is_not_ ## SIZE ## \ 58 ## NAME ## _is_not_ ## SIZE ## \
59 _bytes_wide[(sizeof(CTYPENAME) == SIZE) ? 1 : -1]; } 59 _bytes_wide[(sizeof(CTYPENAME) == SIZE) ? 1 : -1]; }
60 60
61 /* PP_COMPILE_ASSERT_SIZE_IN_BYTES is for typenames that contain no spaces. 61 /* PP_COMPILE_ASSERT_SIZE_IN_BYTES is for typenames that contain no spaces.
62 E.g.: 62 E.g.:
63 PP_COMPILE_ASSERT_SIZE_IN_BYTES(int, 4); 63 PP_COMPILE_ASSERT_SIZE_IN_BYTES(int, 4);
64 typedef struct { int a; } Foo; 64 typedef struct { int a; } Foo;
65 PP_COMPILE_ASSERT_SIZE_IN_BYTES(Foo, 4); 65 PP_COMPILE_ASSERT_SIZE_IN_BYTES(Foo, 4);
66 */ 66 */
67 #define PP_COMPILE_ASSERT_SIZE_IN_BYTES(NAME, SIZE) \ 67 #define PP_COMPILE_ASSERT_SIZE_IN_BYTES(NAME, SIZE) \
68 PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, NAME, SIZE) 68 PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, NAME, SIZE)
69 69
70 /* PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES is for typenames that contain 'struct' 70 /* PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES is for typenames that contain 'struct'
71 in C. That is, struct names that are not typedefs. 71 in C. That is, struct names that are not typedefs.
72 E.g.: 72 E.g.:
73 struct Foo { int a; }; 73 struct Foo { int a; };
74 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(Foo, 4); 74 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(Foo, 4);
75 */ 75 */
76 #define PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(NAME, SIZE) \ 76 #define PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(NAME, SIZE) \
77 PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, struct NAME, SIZE) 77 PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, struct NAME, SIZE)
78 78
79 /* PP_COMPILE_ASSERT_ENUM_SIZE_IN_BYTES is for typenames that contain 'enum'
80 in C. That is, enum names that are not typedefs.
81 E.g.:
82 enum Bar { A = 0, B = 1 };
83 PP_COMPILE_ASSERT_ENUM_SIZE_IN_BYTES(Foo, 4);
84 */
85 #define PP_COMPILE_ASSERT_ENUM_SIZE_IN_BYTES(NAME, SIZE) \
86 PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, enum NAME, SIZE)
87
79 /** 88 /**
80 * @} 89 * @}
81 * End of addtogroup PP 90 * End of addtogroup PP
82 */ 91 */
83 92
84 #endif // PPAPI_C_PP_MACROS_H_ 93 #endif // PPAPI_C_PP_MACROS_H_
85 94
OLDNEW
« ppapi/c/dev/pp_video_dev.h ('K') | « ppapi/c/pp_instance.h ('k') | ppapi/c/pp_module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698