diff options
author | Robert Bragg <robert@linux.intel.com> | 2011-05-13 17:30:08 +0100 |
---|---|---|
committer | Robert Bragg <robert@linux.intel.com> | 2011-05-16 14:12:49 +0100 |
commit | 2da24ab86301ff75670beb4150b56d9339e590d1 (patch) | |
tree | 2b42a6389698e0f41187e2816eda294010257513 | |
parent | df1915d95735f4d13489f955235f5e532161494a (diff) | |
download | cogl-2da24ab86301ff75670beb4150b56d9339e590d1.tar.gz |
Add compile time checks for size of public structs
To help catch accidental changes to the size of public structs that can
be allocated on the stack this patch adds compile time checks that our
struct sizes haven't changed.
-rw-r--r-- | cogl/cogl-euler.h | 1 | ||||
-rw-r--r-- | cogl/cogl-matrix.h | 1 | ||||
-rw-r--r-- | cogl/cogl-quaternion.h | 1 | ||||
-rw-r--r-- | cogl/cogl-types.h | 12 |
4 files changed, 15 insertions, 0 deletions
diff --git a/cogl/cogl-euler.h b/cogl/cogl-euler.h index ca623e82..e82eab16 100644 --- a/cogl/cogl-euler.h +++ b/cogl/cogl-euler.h @@ -157,6 +157,7 @@ struct _CoglEuler float padding3; float padding4; }; +COGL_STRUCT_SIZE_ASSERT (CoglEuler, 32); /** * cogl_euler_init: diff --git a/cogl/cogl-matrix.h b/cogl/cogl-matrix.h index f94a6442..36f21ba9 100644 --- a/cogl/cogl-matrix.h +++ b/cogl/cogl-matrix.h @@ -108,6 +108,7 @@ struct _CoglMatrix unsigned long COGL_PRIVATE (flags); unsigned long COGL_PRIVATE (_padding3); }; +COGL_STRUCT_SIZE_ASSERT (CoglMatrix, 128 + sizeof (unsigned long) * 3); /** * cogl_matrix_init_identity: diff --git a/cogl/cogl-quaternion.h b/cogl/cogl-quaternion.h index 1b83bac5..33ca9845 100644 --- a/cogl/cogl-quaternion.h +++ b/cogl/cogl-quaternion.h @@ -132,6 +132,7 @@ struct _CoglQuaternion float padding2; float padding3; }; +COGL_STRUCT_SIZE_ASSERT (CoglQuaternion, 32); /** * cogl_quaternion_init: diff --git a/cogl/cogl-types.h b/cogl/cogl-types.h index 36f5269b..ab610c17 100644 --- a/cogl/cogl-types.h +++ b/cogl/cogl-types.h @@ -47,6 +47,16 @@ G_BEGIN_DECLS #define COGL_PRIVATE(x) private_member_ ## x #endif +/* To help catch accidental changes to public structs that should + * be stack allocated we use this macro to compile time assert that + * a struct size is as expected. + */ +#define COGL_STRUCT_SIZE_ASSERT(TYPE, SIZE) \ +typedef struct { \ + char compile_time_assert_ ## TYPE ## _size[ \ + (sizeof (TYPE) == (SIZE)) ? 1 : -1]; \ + } _ ## TYPE ## SizeCheck + /** * CoglHandle: * @@ -344,6 +354,7 @@ struct _CoglColor guint32 COGL_PRIVATE (padding1); guint32 COGL_PRIVATE (padding2); }; +COGL_STRUCT_SIZE_ASSERT (CoglColor, 16); /** * CoglTextureVertex: @@ -364,6 +375,7 @@ struct _CoglTextureVertex CoglColor color; }; +COGL_STRUCT_SIZE_ASSERT (CoglTextureVertex, 36); /** * CoglTextureFlags: |