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
This commit is contained in:
Neil Roberts 2010-04-01 20:06:30 +01:00
parent 3fea5051db
commit 774f5e0bdf
2 changed files with 22 additions and 11 deletions

View File

@ -28,6 +28,7 @@
#define __COGL_MATRIX_H
#include <glib.h>
#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);
};
/**

View File

@ -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);
};
/**