From 908be0480cb8f1d9f3da50a962e9064f2252b261 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Thu, 1 Apr 2010 20:06:30 +0100 Subject: [PATCH] cogl: Make private members really hard to accidentally use CoglColor and CoglMatrix have public declarations with private members so that we are free to change the implementation but the structures could still be allocated on the stack in applications. However it's quite easy not to realise the members are private and then access them directly. This patch wraps the members in a macro which redefines the symbol name when including the header outside of the clutter source. http://bugzilla.openedhand.com/show_bug.cgi?id=2065 --- cogl/cogl-matrix.h | 9 +++++---- cogl/cogl-types.h | 24 +++++++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/cogl/cogl-matrix.h b/cogl/cogl-matrix.h index 80b828e66..0d6d72752 100644 --- a/cogl/cogl-matrix.h +++ b/cogl/cogl-matrix.h @@ -28,6 +28,7 @@ #define __COGL_MATRIX_H #include +#include "cogl-types.h" G_BEGIN_DECLS @@ -100,10 +101,10 @@ struct _CoglMatrix /* Note: we may want to extend this later with private flags * and a cache of the inverse transform matrix. */ - float inv[16]; - unsigned long type; - unsigned long flags; - unsigned long _padding3; + float COGL_PRIVATE (inv)[16]; + unsigned long COGL_PRIVATE (type); + unsigned long COGL_PRIVATE (flags); + unsigned long COGL_PRIVATE (_padding3); }; /** diff --git a/cogl/cogl-types.h b/cogl/cogl-types.h index b45bad41e..547ed129a 100644 --- a/cogl/cogl-types.h +++ b/cogl/cogl-types.h @@ -32,6 +32,16 @@ G_BEGIN_DECLS +/* Some structures are meant to be opaque but they have public + definitions because we want the size to be public so they can be + allocated on the stack. This macro is used to ensure that users + don't accidentally access private members */ +#ifdef CLUTTER_COMPILATION +#define COGL_PRIVATE(x) x +#else +#define COGL_PRIVATE(x) private_member_ ## x +#endif + /** * CoglHandle: * @@ -251,17 +261,17 @@ typedef enum struct _CoglColor { /*< private >*/ - guint8 red; - guint8 green; - guint8 blue; + guint8 COGL_PRIVATE (red); + guint8 COGL_PRIVATE (green); + guint8 COGL_PRIVATE (blue); - guint8 alpha; + guint8 COGL_PRIVATE (alpha); /* padding in case we want to change to floats at * some point */ - guint32 padding0; - guint32 padding1; - guint32 padding2; + guint32 COGL_PRIVATE (padding0); + guint32 COGL_PRIVATE (padding1); + guint32 COGL_PRIVATE (padding2); }; /**