From 2b087cb45ae91f90492a935625570d7d42ee3ecb Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 7 Apr 2010 14:26:15 -0400 Subject: New dmnsn_malloc() function, and friends. I'm tired of checking for malloc failures everywhere, considering it never happens. So just bail out whenever it does. A lot of stuff is guaranteed to succeed if it returns now. --- libdimension/texture.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) (limited to 'libdimension/texture.c') diff --git a/libdimension/texture.c b/libdimension/texture.c index 28f5033..7feb0e0 100644 --- a/libdimension/texture.c +++ b/libdimension/texture.c @@ -20,18 +20,13 @@ #include "dimension.h" #include -#include /* For malloc */ /* Allocate a dummy pigment */ dmnsn_pigment * dmnsn_new_pigment() { - dmnsn_pigment *pigment = malloc(sizeof(dmnsn_pigment)); - if (pigment) { - pigment->free_fn = NULL; - } else { - errno = ENOMEM; - } + dmnsn_pigment *pigment = dmnsn_malloc(sizeof(dmnsn_pigment)); + pigment->free_fn = NULL; return pigment; } @@ -51,16 +46,12 @@ dmnsn_delete_pigment(dmnsn_pigment *pigment) dmnsn_finish * dmnsn_new_finish() { - dmnsn_finish *finish = malloc(sizeof(dmnsn_finish)); - if (finish) { - finish->diffuse_fn = NULL; - finish->specular_fn = NULL; - finish->ambient_fn = NULL; - finish->reflection_fn = NULL; - finish->free_fn = NULL; - } else { - errno = ENOMEM; - } + dmnsn_finish *finish = dmnsn_malloc(sizeof(dmnsn_finish)); + finish->diffuse_fn = NULL; + finish->specular_fn = NULL; + finish->ambient_fn = NULL; + finish->reflection_fn = NULL; + finish->free_fn = NULL; return finish; } @@ -80,13 +71,9 @@ dmnsn_delete_finish(dmnsn_finish *finish) dmnsn_texture * dmnsn_new_texture() { - dmnsn_texture *texture = malloc(sizeof(dmnsn_texture)); - if (texture) { - texture->pigment = NULL; - texture->finish = NULL; - } else { - errno = ENOMEM; - } + dmnsn_texture *texture = dmnsn_malloc(sizeof(dmnsn_texture)); + texture->pigment = NULL; + texture->finish = NULL; return texture; } -- cgit v1.2.3