summaryrefslogtreecommitdiffstats
path: root/libdimension/finish_combination.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-04-07 14:26:15 -0400
committerTavian Barnes <tavianator@gmail.com>2010-04-07 14:34:52 -0400
commit2b087cb45ae91f90492a935625570d7d42ee3ecb (patch)
treea464213b08d04c8c91c8879a84e534f895c84378 /libdimension/finish_combination.c
parent7d6663eeb68bf9d0a3dff86128827c0c1d85df69 (diff)
downloaddimension-2b087cb45ae91f90492a935625570d7d42ee3ecb.tar.xz
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.
Diffstat (limited to 'libdimension/finish_combination.c')
-rw-r--r--libdimension/finish_combination.c65
1 files changed, 22 insertions, 43 deletions
diff --git a/libdimension/finish_combination.c b/libdimension/finish_combination.c
index 472dc23..c281285 100644
--- a/libdimension/finish_combination.c
+++ b/libdimension/finish_combination.c
@@ -20,7 +20,6 @@
#include "dimension.h"
#include <errno.h>
-#include <stdlib.h> /* For malloc */
#include <math.h>
/*
@@ -119,47 +118,27 @@ dmnsn_finish_combination_free_fn(void *ptr)
dmnsn_finish *
dmnsn_new_finish_combination(dmnsn_finish *f1, dmnsn_finish *f2)
{
- if (f1 && f2) {
- dmnsn_finish *finish = dmnsn_new_finish();
- if (finish) {
- dmnsn_finish **params = malloc(2*sizeof(dmnsn_finish *));
- if (!params) {
- dmnsn_delete_finish(finish);
- dmnsn_delete_finish(f2);
- dmnsn_delete_finish(f1);
- errno = ENOMEM;
- return NULL;
- }
-
- params[0] = f1;
- params[1] = f2;
-
- finish->ptr = params;
-
- if (f1->diffuse_fn || f2->diffuse_fn)
- finish->diffuse_fn = &dmnsn_finish_combination_diffuse_fn;
-
- if (f1->specular_fn || f2->specular_fn)
- finish->specular_fn = &dmnsn_finish_combination_specular_fn;
-
- if (f1->ambient_fn || f2->ambient_fn)
- finish->ambient_fn = &dmnsn_finish_combination_ambient_fn;
-
- if (f1->reflection_fn || f2->reflection_fn)
- finish->reflection_fn = &dmnsn_finish_combination_reflection_fn;
-
- finish->free_fn = &dmnsn_finish_combination_free_fn;
-
- return finish;
- } else {
- dmnsn_delete_finish(f2);
- dmnsn_delete_finish(f1);
- }
- } else if (f1) {
- dmnsn_delete_finish(f1);
- } else if (f2) {
- dmnsn_delete_finish(f2);
- }
+ dmnsn_finish *finish = dmnsn_new_finish();
+
+ dmnsn_finish **params = dmnsn_malloc(2*sizeof(dmnsn_finish *));
+ params[0] = f1;
+ params[1] = f2;
+
+ finish->ptr = params;
+
+ if (f1->diffuse_fn || f2->diffuse_fn)
+ finish->diffuse_fn = &dmnsn_finish_combination_diffuse_fn;
+
+ if (f1->specular_fn || f2->specular_fn)
+ finish->specular_fn = &dmnsn_finish_combination_specular_fn;
+
+ if (f1->ambient_fn || f2->ambient_fn)
+ finish->ambient_fn = &dmnsn_finish_combination_ambient_fn;
+
+ if (f1->reflection_fn || f2->reflection_fn)
+ finish->reflection_fn = &dmnsn_finish_combination_reflection_fn;
+
+ finish->free_fn = &dmnsn_finish_combination_free_fn;
- return NULL;
+ return finish;
}