summaryrefslogtreecommitdiffstats
path: root/dimension/common.rules
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 /dimension/common.rules
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 'dimension/common.rules')
-rw-r--r--dimension/common.rules17
1 files changed, 3 insertions, 14 deletions
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);
}