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.
This commit is contained in:
parent
df1915d957
commit
2da24ab863
@ -157,6 +157,7 @@ struct _CoglEuler
|
||||
float padding3;
|
||||
float padding4;
|
||||
};
|
||||
COGL_STRUCT_SIZE_ASSERT (CoglEuler, 32);
|
||||
|
||||
/**
|
||||
* cogl_euler_init:
|
||||
|
@ -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:
|
||||
|
@ -132,6 +132,7 @@ struct _CoglQuaternion
|
||||
float padding2;
|
||||
float padding3;
|
||||
};
|
||||
COGL_STRUCT_SIZE_ASSERT (CoglQuaternion, 32);
|
||||
|
||||
/**
|
||||
* cogl_quaternion_init:
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user