model: fix const correctness of ConstBrushModel internals

Couldn't find a neat way to make the container_of macro const agnostic, so
just have a const and non-const version.  Silences a bunch of -Wcast-qual
warnings so that real problems are easier to spot.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
Kevin Shanahan 2013-04-24 16:19:00 +09:30
parent 979342e2de
commit 580204e255
2 changed files with 6 additions and 2 deletions

View File

@ -471,7 +471,7 @@ static inline const brushmodel_t *
ConstBrushModel(const model_t *model)
{
assert(model && model->type == mod_brush);
return container_of(model, brushmodel_t, model);
return const_container_of(model, brushmodel_t, model);
}
static inline brushmodel_t *

View File

@ -45,7 +45,11 @@ typedef enum { false, true } qboolean;
*
*/
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#define const_container_of(ptr, type, member) ({ \
typeof( ((const type *)0)->member ) *__mptr = (ptr); \
(const type *)( (const char *)__mptr - offsetof(type,member) );})
#endif /* QTYPES_H */