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/object.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'libdimension/object.c') diff --git a/libdimension/object.c b/libdimension/object.c index 9f17971..51db42f 100644 --- a/libdimension/object.c +++ b/libdimension/object.c @@ -20,16 +20,12 @@ #include "dimension.h" #include -#include /* For malloc */ -/* Allocate an intersection - cannot fail */ +/* Allocate an intersection */ dmnsn_intersection * dmnsn_new_intersection() { - dmnsn_intersection *intersection = malloc(sizeof(dmnsn_intersection)); - if (!intersection) { - dmnsn_error(DMNSN_SEVERITY_HIGH, "Couldn't allocate an intersection."); - } + dmnsn_intersection *intersection = dmnsn_malloc(sizeof(dmnsn_intersection)); return intersection; } @@ -44,15 +40,11 @@ dmnsn_delete_intersection(dmnsn_intersection *intersection) dmnsn_object * dmnsn_new_object() { - dmnsn_object *object = malloc(sizeof(dmnsn_object)); - if (object) { - object->texture = NULL; - object->interior = NULL; - object->trans = dmnsn_identity_matrix(); - object->free_fn = NULL; - } else { - errno = ENOMEM; - } + dmnsn_object *object = dmnsn_malloc(sizeof(dmnsn_object)); + object->texture = NULL; + object->interior = NULL; + object->trans = dmnsn_identity_matrix(); + object->free_fn = NULL; return object; } -- cgit v1.2.3