[cogl] Add compile time checks for size of public structs
- From: Robert Bragg <rbragg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl] Add compile time checks for size of public structs
- Date: Mon, 16 May 2011 13:14:09 +0000 (UTC)
commit 2da24ab86301ff75670beb4150b56d9339e590d1
Author: Robert Bragg <robert linux intel com>
Date: Fri May 13 17:30:08 2011 +0100
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.
cogl/cogl-euler.h | 1 +
cogl/cogl-matrix.h | 1 +
cogl/cogl-quaternion.h | 1 +
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 ca623e8..e82eab1 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 f94a644..36f21ba 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 1b83bac..33ca984 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 36f5269..ab610c1 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:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]