diff options
author | dmichael@google.com <dmichael@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-12 21:45:10 +0000 |
---|---|---|
committer | dmichael@google.com <dmichael@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-12 21:45:10 +0000 |
commit | 41ec328301235a14486cf928ca119b73211319ad (patch) | |
tree | 3e4565493f7a621e08be9872a4a88bc8721a86c4 /ppapi/c | |
parent | 4203e6ba7883f062b505b04fbb61c8b15bba3a5d (diff) | |
download | chromium_src-41ec328301235a14486cf928ca119b73211319ad.zip chromium_src-41ec328301235a14486cf928ca119b73211319ad.tar.gz chromium_src-41ec328301235a14486cf928ca119b73211319ad.tar.bz2 |
Force 8-byte alignment in PP_InputEvent. Rev PPP_Instance interface to 0.3 because this changes the size of PP_InputEvent on Linux x86-32. Add an assertion for the size of PP_InputEvent.
Note I had to tweak the macro to allow for a typename of "struct PP_InputEvent", because I was relying on having no spaces in the typename. Now there's a separate macro for structs. Other options would include:
- adding a typedef, e.g. PP_InputEvent_t, and using that in the original macro (this was my initial approach, but I decided I'd rather make a new macro than obfuscate the PP_InputEvent declaration)
- Make PP_InputEvent itself a typedef, i.e. typedef struct {...} PP_InputEvent. This would make it impossible to forward-declare PP_InputEvent, and would require code changes elsewhere.
- Change the macro some other way so that we don't need 2 macros (e.g., don't use the passed typename when creating a unique name). Use another trick like using the line number. This also has the drawback of making the error message less helpful.
BUG=62983
TEST=NaCl tests/ppapi_proxy/event_example (see http://codereview.chromium.org/3767003/show)
Review URL: http://codereview.chromium.org/4861002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66000 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/c')
-rw-r--r-- | ppapi/c/pp_input_event.h | 9 | ||||
-rw-r--r-- | ppapi/c/pp_macros.h | 33 | ||||
-rw-r--r-- | ppapi/c/ppp_instance.h | 2 |
3 files changed, 40 insertions, 4 deletions
diff --git a/ppapi/c/pp_input_event.h b/ppapi/c/pp_input_event.h index 715c016..7f95e09 100644 --- a/ppapi/c/pp_input_event.h +++ b/ppapi/c/pp_input_event.h @@ -14,6 +14,7 @@ */ #include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_macros.h" #include "ppapi/c/pp_stdint.h" #include "ppapi/c/pp_time.h" @@ -149,6 +150,10 @@ struct PP_InputEvent_Wheel { PP_Bool scroll_by_page; }; +/* Ensure the elements of the struct (especially the time_stamp) are aligned on + 8-byte boundaries, since some compilers align doubles on 8-byte boundaries + for 32-bit x86, and some align on 4-byte boundaries. */ +#pragma pack(push, 8) struct PP_InputEvent { /** Identifies the type of the event. */ PP_InputEvent_Type type; @@ -173,6 +178,10 @@ struct PP_InputEvent { char padding[64]; } u; }; +#pragma pack(pop) +/* TODO(dmichael): Figure out why the input event is not 80 bytes wide on Mac. +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent, 80); + */ /** * @} diff --git a/ppapi/c/pp_macros.h b/ppapi/c/pp_macros.h index ffc48b0..a46ea2e 100644 --- a/ppapi/c/pp_macros.h +++ b/ppapi/c/pp_macros.h @@ -42,12 +42,39 @@ (which should always be valid) if the enum's size is SIZE, and otherwise the size of the array will be -1 (which all/most compilers should flag as an error). This is wrapped inside a struct, because if it is a simple global - we get multiple definition errors at link time. */ -#define PP_COMPILE_ASSERT_SIZE_IN_BYTES(NAME, SIZE) \ + we get multiple definition errors at link time. + + NAME is the name of the type without any spaces or the struct or enum + keywords. + + CTYPENAME is the typename required by C. I.e., for a struct or enum, the + appropriate keyword must be included. + + SIZE is the expected size in bytes. + */ +#define PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, CTYPENAME, SIZE) \ struct _dummy_struct_for_##NAME { \ char _COMPILE_ASSERT_FAILED_The_type_named_ \ ## NAME ## _is_not_ ## SIZE ## \ -_bytes_wide[(sizeof(NAME) == SIZE) ? 1 : -1]; } +_bytes_wide[(sizeof(CTYPENAME) == SIZE) ? 1 : -1]; } + +/* PP_COMPILE_ASSERT_SIZE_IN_BYTES is for typenames that contain no spaces. + E.g.: + PP_COMPILE_ASSERT_SIZE_IN_BYTES(int, 4); + typedef struct { int a; } Foo; + PP_COMPILE_ASSERT_SIZE_IN_BYTES(Foo, 4); + */ +#define PP_COMPILE_ASSERT_SIZE_IN_BYTES(NAME, SIZE) \ +PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, NAME, SIZE) + +/* PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES is for typenames that contain 'struct' + in C. That is, struct names that are not typedefs. + E.g.: + struct Foo { int a; }; + PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(Foo, 4); + */ +#define PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(NAME, SIZE) \ +PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, struct NAME, SIZE) /** * @} diff --git a/ppapi/c/ppp_instance.h b/ppapi/c/ppp_instance.h index cb7988d..19907ca 100644 --- a/ppapi/c/ppp_instance.h +++ b/ppapi/c/ppp_instance.h @@ -13,7 +13,7 @@ struct PP_InputEvent; struct PP_Var; -#define PPP_INSTANCE_INTERFACE "PPP_Instance;0.2" +#define PPP_INSTANCE_INTERFACE "PPP_Instance;0.3" /** * @file |