From 6b94e0329841ed8e80dbb55a3f8c2eee41b3168b Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 14 Dec 2011 19:51:25 -0500 Subject: Make refcount declarations uniform. --- libdimension/dimension/camera.h | 6 +++--- libdimension/dimension/canvas.h | 2 +- libdimension/dimension/finish.h | 10 +++++----- libdimension/dimension/interior.h | 13 ++++--------- libdimension/dimension/light.h | 3 +-- libdimension/dimension/object.h | 2 +- libdimension/dimension/pattern.h | 2 +- libdimension/dimension/pigment.h | 2 +- libdimension/dimension/refcount.h | 11 ++++++----- libdimension/dimension/texture.h | 2 +- libdimension/refcount-internal.h | 3 ++- 11 files changed, 26 insertions(+), 30 deletions(-) diff --git a/libdimension/dimension/camera.h b/libdimension/dimension/camera.h index 75d86a9..00f0ad5 100644 --- a/libdimension/dimension/camera.h +++ b/libdimension/dimension/camera.h @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * + * Copyright (C) 2009-2011 Tavian Barnes * * * * This file is part of The Dimension Library. * * * @@ -44,9 +44,9 @@ struct dmnsn_camera { dmnsn_matrix trans; /**< Transformation matrix. */ - void *ptr; /**< @internal Generic pointer for camera info. */ + void *ptr; /**< Generic pointer for camera info. */ - dmnsn_refcount refcount; /**< @internal reference count. */ + DMNSN_REFCOUNT; /**< Reference count. */ }; /** diff --git a/libdimension/dimension/canvas.h b/libdimension/dimension/canvas.h index ba06b8c..6c6ff86 100644 --- a/libdimension/dimension/canvas.h +++ b/libdimension/dimension/canvas.h @@ -40,7 +40,7 @@ typedef struct dmnsn_canvas { */ dmnsn_tcolor *pixels; - dmnsn_refcount refcount; /**< @internal Reference count. */ + DMNSN_REFCOUNT; /**< Reference count. */ } dmnsn_canvas; /* Forward-declare dmnsn_canvas_optimizer */ diff --git a/libdimension/dimension/finish.h b/libdimension/dimension/finish.h index 4ac9239..5ff6a2c 100644 --- a/libdimension/dimension/finish.h +++ b/libdimension/dimension/finish.h @@ -38,8 +38,8 @@ typedef dmnsn_color dmnsn_ambient_fn(const dmnsn_ambient *ambient, /** Ambient finish component. */ struct dmnsn_ambient { - dmnsn_color ambient; /**< Ambient light. */ - dmnsn_refcount refcount; /**< @internal Reference count. */ + dmnsn_color ambient; /**< Ambient light. */ + DMNSN_REFCOUNT; /**< Reference count. */ }; /** Allocate a dummy ambient component. */ @@ -69,7 +69,7 @@ struct dmnsn_diffuse { dmnsn_diffuse_fn *diffuse_fn; /**< Diffuse callback. */ dmnsn_free_fn *free_fn; /**< Destructor callback. */ void *ptr; /**< Generic data pointer. */ - dmnsn_refcount refcount; /**< @internal Reference count. */ + DMNSN_REFCOUNT; /**< Reference count. */ }; /** Allocate a dummy diffuse component. */ @@ -101,7 +101,7 @@ struct dmnsn_specular { dmnsn_specular_fn *specular_fn; /**< Specular callback. */ dmnsn_free_fn *free_fn; /**< Destructor callback. */ void *ptr; /**< Generic data pointer. */ - dmnsn_refcount refcount; /**< @internal Reference count. */ + DMNSN_REFCOUNT; /**< Reference count. */ }; /** Allocate a dummy specular component. */ @@ -131,7 +131,7 @@ struct dmnsn_reflection { dmnsn_reflection_fn *reflection_fn; /**< Reflection callback. */ dmnsn_free_fn *free_fn; /**< Destructor callback. */ void *ptr; /**< Generic data pointer. */ - dmnsn_refcount refcount; /**< @internal Reference count. */ + DMNSN_REFCOUNT; /**< Reference count. */ }; /** Allocate a dummy reflection component. */ diff --git a/libdimension/dimension/interior.h b/libdimension/dimension/interior.h index a52c225..691b053 100644 --- a/libdimension/dimension/interior.h +++ b/libdimension/dimension/interior.h @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2010 Tavian Barnes * + * Copyright (C) 2010-2011 Tavian Barnes * * * * This file is part of The Dimension Library. * * * @@ -25,15 +25,10 @@ /** An interior. */ typedef struct dmnsn_interior { - double ior; /**< Refractive index. */ - + double ior; /**< Refractive index. */ dmnsn_free_fn *free_fn; /**< Destructor callback. */ - - /** Generic pointer. */ - void *ptr; - - /** @internal Reference count. */ - dmnsn_refcount refcount; + void *ptr; /**< Generic pointer. */ + DMNSN_REFCOUNT; /**< Reference count. */ } dmnsn_interior; /** diff --git a/libdimension/dimension/light.h b/libdimension/dimension/light.h index 4738164..a1f7ff2 100644 --- a/libdimension/dimension/light.h +++ b/libdimension/dimension/light.h @@ -65,8 +65,7 @@ struct dmnsn_light { /** Generic pointer for light info. */ void *ptr; - /** @internal Reference count. */ - dmnsn_refcount refcount; + DMNSN_REFCOUNT; /**< Reference count. */ }; /** diff --git a/libdimension/dimension/object.h b/libdimension/dimension/object.h index 24c4785..9019c69 100644 --- a/libdimension/dimension/object.h +++ b/libdimension/dimension/object.h @@ -89,7 +89,7 @@ struct dmnsn_object { void *ptr; /**< Generic pointer for object info. */ - dmnsn_refcount refcount; /**< @internal Reference count. */ + DMNSN_REFCOUNT; /**< Reference count. */ bool initialized; /**< @internal Whether the object is initialized yet. */ }; diff --git a/libdimension/dimension/pattern.h b/libdimension/dimension/pattern.h index 3854894..c21ca8d 100644 --- a/libdimension/dimension/pattern.h +++ b/libdimension/dimension/pattern.h @@ -42,7 +42,7 @@ struct dmnsn_pattern { void *ptr; /**< Generic pointer. */ - dmnsn_refcount refcount; /**< @internal Reference count. */ + DMNSN_REFCOUNT; /**< Reference count. */ }; /** diff --git a/libdimension/dimension/pigment.h b/libdimension/dimension/pigment.h index 176ff28..b046993 100644 --- a/libdimension/dimension/pigment.h +++ b/libdimension/dimension/pigment.h @@ -56,7 +56,7 @@ struct dmnsn_pigment { /** Generic pointer. */ void *ptr; - dmnsn_refcount refcount; /** @internal Reference count. */ + DMNSN_REFCOUNT; /** Reference count. */ bool initialized; /** @internal Whether the pigment is initialized. */ }; diff --git a/libdimension/dimension/refcount.h b/libdimension/dimension/refcount.h index f9f3286..9f6d8b0 100644 --- a/libdimension/dimension/refcount.h +++ b/libdimension/dimension/refcount.h @@ -23,10 +23,11 @@ * Generic reference count implementation. */ -/** - * Reference counter. - */ -typedef unsigned int dmnsn_refcount; +/** @internal The name of the reference count field in all structs. */ +#define DMNSN_REFCOUNT_NAME refcount + +/** @internal Declare a reference count field in a struct. */ +#define DMNSN_REFCOUNT unsigned int DMNSN_REFCOUNT_NAME /** * Increment a reference count. @@ -37,6 +38,6 @@ typedef unsigned int dmnsn_refcount; /* Suppress "address will always evaluate to true" warning */ \ void *testptr = (object); \ if (testptr) { \ - ++(object)->refcount; \ + ++(object)->DMNSN_REFCOUNT_NAME; \ } \ } while (0) diff --git a/libdimension/dimension/texture.h b/libdimension/dimension/texture.h index a3cf744..52756ac 100644 --- a/libdimension/dimension/texture.h +++ b/libdimension/dimension/texture.h @@ -31,7 +31,7 @@ typedef struct { dmnsn_matrix trans; /**< Transformation matrix. */ dmnsn_matrix trans_inv; /**< The inverse of the transformation matrix. */ - dmnsn_refcount refcount; /**< @internal Reference count. */ + DMNSN_REFCOUNT; /**< Reference count. */ bool initialized; /**< @internal Whether the texture is initialized yet. */ } dmnsn_texture; diff --git a/libdimension/refcount-internal.h b/libdimension/refcount-internal.h index c2321c9..5ae5d58 100644 --- a/libdimension/refcount-internal.h +++ b/libdimension/refcount-internal.h @@ -29,4 +29,5 @@ * @return Whether the object is now garbage. */ #define DMNSN_DECREF(object) \ - ((object) && ((object)->refcount == 0 || --(object)->refcount == 0)) + ((object) && ((object)->DMNSN_REFCOUNT_NAME == 0 \ + || --(object)->DMNSN_REFCOUNT_NAME == 0)) -- cgit v1.2.3