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. --- dimension/common.rules | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'dimension/common.rules') diff --git a/dimension/common.rules b/dimension/common.rules index e477df5..e604b9f 100644 --- a/dimension/common.rules +++ b/dimension/common.rules @@ -29,10 +29,7 @@ IDENTIFIER: "identifier" { symbol = dmnsn_find_symbol(symtable, id); } $$ = dmnsn_new_astnode(DMNSN_AST_IDENTIFIER, @$); - $$.ptr = strdup(id); - if (!$$.ptr) - dmnsn_error(DMNSN_SEVERITY_HIGH, - "Couldn't allocate room for identifier."); + $$.ptr = dmnsn_strdup(id); free($1); } ; @@ -410,21 +407,13 @@ FLOAT: ARITH_EXPR { FLOAT_LITERAL: "integer" { $$ = dmnsn_new_astnode(DMNSN_AST_INTEGER, @$); - $$.ptr = malloc(sizeof(long)); - if (!$$.ptr) - dmnsn_error(DMNSN_SEVERITY_HIGH, - "Failed to allocate room for integer."); - + $$.ptr = dmnsn_malloc(sizeof(long)); *(long *)$$.ptr = strtol($1, NULL, 0); free($1); } | "float" { $$ = dmnsn_new_astnode(DMNSN_AST_FLOAT, @$); - $$.ptr = malloc(sizeof(double)); - if (!$$.ptr) - dmnsn_error(DMNSN_SEVERITY_HIGH, - "Failed to allocate room for float."); - + $$.ptr = dmnsn_malloc(sizeof(double)); *(double *)$$.ptr = strtod($1, NULL); free($1); } -- cgit v1.2.3