From df33e223baa85b600863fc1b38850a5c37680632 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 27 May 2014 13:46:51 -0400 Subject: pigment: Kill ->ptr field. --- libdimension/pigment.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'libdimension/pigment.c') diff --git a/libdimension/pigment.c b/libdimension/pigment.c index 6134c2b..e392d7b 100644 --- a/libdimension/pigment.c +++ b/libdimension/pigment.c @@ -25,19 +25,32 @@ #include "dimension-internal.h" +static void +dmnsn_default_pigment_free_fn(dmnsn_pigment *pigment) +{ + dmnsn_free(pigment); +} + /* Allocate a dummy pigment */ dmnsn_pigment * dmnsn_new_pigment(void) { dmnsn_pigment *pigment = DMNSN_MALLOC(dmnsn_pigment); - pigment->pigment_fn = NULL; + dmnsn_init_pigment(pigment); + return pigment; +} + +/* Initialize a pigment */ +void +dmnsn_init_pigment(dmnsn_pigment *pigment) +{ + pigment->pigment_fn = NULL; pigment->initialize_fn = NULL; - pigment->free_fn = NULL; - pigment->trans = dmnsn_identity_matrix(); - pigment->quick_color = DMNSN_TCOLOR(dmnsn_black); - pigment->initialized = false; + pigment->free_fn = dmnsn_default_pigment_free_fn; + pigment->trans = dmnsn_identity_matrix(); + pigment->quick_color = DMNSN_TCOLOR(dmnsn_black); + pigment->initialized = false; DMNSN_REFCOUNT_INIT(pigment); - return pigment; } /* Free a pigment */ @@ -45,10 +58,7 @@ void dmnsn_delete_pigment(dmnsn_pigment *pigment) { if (DMNSN_DECREF(pigment)) { - if (pigment->free_fn) { - pigment->free_fn(pigment->ptr); - } - dmnsn_free(pigment); + pigment->free_fn(pigment); } } -- cgit v1.2.3