Commit e07b61c6 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

Good day and welcome to the FIRM XMALLOC*() macros. These macros are provided...

Good day and welcome to the FIRM XMALLOC*() macros.  These macros are provided for the type safety and convenience of the IPD research facility personnel.  The time is 15:32.  Check xmalloc.h for details.

[r22494]
parent 325f4d96
......@@ -48,7 +48,6 @@
#include "irtools.h"
#include "opt_polymorphy.h"
#include "irmemory.h"
#include "xmalloc.h"
#include "irphase_t.h"
#include "irgopt.h"
#include "debug.h"
......
......@@ -472,7 +472,7 @@ void dead_node_elimination(ir_graph *irg) {
graveyard_obst = irg->obst;
/* A new obstack, where the reachable nodes will be copied to. */
rebirth_obst = xmalloc(sizeof(*rebirth_obst));
rebirth_obst = XMALLOC(struct obstack);
irg->obst = rebirth_obst;
obstack_init(irg->obst);
irg->last_node_idx = 0;
......@@ -663,7 +663,7 @@ static void dead_node_subst_hook(void *context, ir_graph *irg, ir_node *old, ir_
* Make a new Survive DCE environment.
*/
survive_dce_t *new_survive_dce(void) {
survive_dce_t *res = xmalloc(sizeof(res[0]));
survive_dce_t *res = XMALLOC(survive_dce_t);
obstack_init(&res->obst);
res->places = pmap_create();
res->new_places = NULL;
......@@ -1068,8 +1068,8 @@ int inline_method(ir_node *call, ir_graph *called_graph) {
arity = get_Block_n_cfgpreds(end_bl); /* arity = n_exc + n_ret */
n_res = get_method_n_ress(get_Call_type(call));
res_pred = xmalloc(n_res * sizeof(*res_pred));
cf_pred = xmalloc(arity * sizeof(*res_pred));
res_pred = XMALLOCN(ir_node*, n_res);
cf_pred = XMALLOCN(ir_node*, arity);
set_irg_current_block(irg, post_bl); /* just to make sure */
......@@ -1209,9 +1209,9 @@ int inline_method(ir_node *call, ir_graph *called_graph) {
n_exc++;
}
}
main_end_bl = get_irg_end_block(irg);
main_end_bl = get_irg_end_block(irg);
main_end_bl_arity = get_irn_arity(main_end_bl);
end_preds = xmalloc((n_exc + main_end_bl_arity) * sizeof(*end_preds));
end_preds = XMALLOCN(ir_node*, n_exc + main_end_bl_arity);
for (i = 0; i < main_end_bl_arity; ++i)
end_preds[i] = get_irn_n(main_end_bl, i);
......@@ -2012,8 +2012,7 @@ static ir_graph **create_irg_list(void) {
compute_callgraph();
last_irg = 0;
irgs = xmalloc(n_irgs * sizeof(*irgs));
memset(irgs, 0, sizeof(n_irgs * sizeof(*irgs)));
irgs = XMALLOCNZ(ir_graph*, n_irgs);
callgraph_walk(NULL, callgraph_walker, NULL);
assert(n_irgs == last_irg);
......
......@@ -52,7 +52,6 @@
#include "irloop_t.h"
#include "array.h"
#include "firmstat.h"
#include "xmalloc.h"
#include "error.h"
/** The debug handle. */
......
......@@ -51,7 +51,6 @@
#include "irtools.h"
#include "irgmod.h"
#include "array_t.h"
#include "xmalloc.h"
/**
* This struct contains the information quadruple for a Call, which we need to
......
......@@ -32,7 +32,6 @@
#include "ircons_t.h"
#include "irnode_t.h"
#include "irgmod.h"
#include "xmalloc.h"
#define set_bit(n) (returns[(n) >> 3] |= 1 << ((n) & 7))
#define get_bit(n) (returns[(n) >> 3] & (1 << ((n) & 7)))
......
......@@ -406,8 +406,7 @@ static path_t *find_path(ir_node *sel, unsigned len) {
if (! is_Sel(pred)) {
/* we found the root */
res = xmalloc(sizeof(*res) + (len - 1) * sizeof(res->path));
res = XMALLOCF(path_t, path, len);
res->path_len = len;
} else
res = find_path(pred, len);
......
......@@ -47,7 +47,6 @@
#include "irouts.h"
#include "irhooks.h"
#include "ircons_t.h"
#include "xmalloc.h"
DEBUG_ONLY(static firm_dbg_module_t *dbg);
......
......@@ -60,9 +60,7 @@ static int int_cmp_fun(const void *elt, const void *key) {
* create a new distribution table
*/
distrib_tbl_t *stat_new_distrib_tbl(pset_cmp_fun cmp_func, distrib_hash_fun hash_func) {
distrib_tbl_t *res;
res = xmalloc(sizeof(*res));
distrib_tbl_t *res = XMALLOC(distrib_tbl_t);
obstack_init(&res->cnts);
......
......@@ -1299,15 +1299,13 @@ static void update_graph_stat_2(graph_entry_t *global, graph_entry_t *graph)
* Register a dumper.
*/
static void stat_register_dumper(const dumper_t *dumper) {
dumper_t *p = xmalloc(sizeof(*p));
dumper_t *p = XMALLOC(dumper_t);
if (p) {
memcpy(p, dumper, sizeof(*p));
memcpy(p, dumper, sizeof(*p));
p->next = status->dumper;
p->status = status;
status->dumper = p;
}
p->next = status->dumper;
p->status = status;
status->dumper = p;
/* FIXME: memory leak */
} /* stat_register_dumper */
......@@ -2186,8 +2184,7 @@ void firm_init_stat(unsigned enable_options)
if (! (enable_options & FIRMSTAT_ENABLED))
return;
status = xmalloc(sizeof(*status));
memset(status, 0, sizeof(*status));
status = XMALLOCZ(stat_info_t);
/* enable statistics */
status->stat_options = enable_options & FIRMSTAT_ENABLED ? enable_options : 0;
......
......@@ -802,7 +802,7 @@ static void pattern_output(const char *fname) {
/* creates a dumper */
dump = new_vcg_dumper(fname, 100);
pattern_arr = xmalloc(sizeof(*pattern_arr) * count);
pattern_arr = XMALLOCN(pattern_entry_t*, count);
for (i = 0, entry = pset_first(status->pattern_hash);
entry && i < count;
entry = pset_next(status->pattern_hash), ++i) {
......
......@@ -132,8 +132,7 @@ new_rd_entity(dbg_info *db, ir_type *owner, ident *name, ir_type *type)
assert(!id_contains_char(name, ' ') && "entity name should not contain spaces");
res = xmalloc(sizeof(*res));
memset(res, 0, sizeof(*res));
res = XMALLOCZ(ir_entity);
res->kind = k_entity;
res->name = name;
......@@ -267,7 +266,7 @@ copy_entity_own(ir_entity *old, ir_type *new_owner) {
assert(get_type_state(new_owner) != layout_fixed);
if (old->owner == new_owner) return old;
newe = xmalloc(sizeof(*newe));
newe = XMALLOC(ir_entity);
memcpy(newe, old, sizeof(*newe));
newe->owner = new_owner;
if (is_Class_type(new_owner)) {
......@@ -289,7 +288,7 @@ copy_entity_name(ir_entity *old, ident *new_name) {
assert(old && old->kind == k_entity);
if (old->name == new_name) return old;
newe = xmalloc(sizeof(*newe));
newe = XMALLOC(ir_entity);
memcpy(newe, old, sizeof(*newe));
newe->name = new_name;
newe->ld_name = NULL;
......
......@@ -47,9 +47,7 @@ tp_op *
new_tpop(tp_opcode code, ident *name, unsigned flags, size_t attr_size,
const tp_op_ops *ops)
{
tp_op *res;
res = xmalloc(sizeof(*res));
tp_op *res = XMALLOC(tp_op);
res->code = code;
res->name = name;
res->flags = flags;
......
......@@ -1191,10 +1191,10 @@ ir_type *new_d_type_method(ident *name, int n_param, int n_res, dbg_info *db) {
res->flags |= tf_layout_fixed;
res->size = get_mode_size_bytes(mode_P_code);
res->attr.ma.n_params = n_param;
res->attr.ma.params = xcalloc(n_param, sizeof(res->attr.ma.params[0]));
res->attr.ma.params = XMALLOCNZ(tp_ent_pair, n_param);
res->attr.ma.value_params = NULL;
res->attr.ma.n_res = n_res;
res->attr.ma.res_type = xcalloc(n_res, sizeof(res->attr.ma.res_type[0]));
res->attr.ma.res_type = XMALLOCNZ(tp_ent_pair, n_res);
res->attr.ma.value_ress = NULL;
res->attr.ma.variadicity = variadicity_non_variadic;
res->attr.ma.first_variadic_param = -1;
......@@ -1233,11 +1233,11 @@ ir_type *clone_type_method(ir_type *tp, ident *prefix) {
res->assoc_type = tp->assoc_type;
res->size = tp->size;
res->attr.ma.n_params = n_params;
res->attr.ma.params = xcalloc(n_params, sizeof(res->attr.ma.params[0]));
res->attr.ma.params = XMALLOCN(tp_ent_pair, n_params);
memcpy(res->attr.ma.params, tp->attr.ma.params, n_params * sizeof(res->attr.ma.params[0]));
res->attr.ma.value_params = tp->attr.ma.value_params;
res->attr.ma.n_res = n_res;
res->attr.ma.res_type = xcalloc(n_res, sizeof(res->attr.ma.res_type[0]));
res->attr.ma.res_type = XMALLOCN(tp_ent_pair, n_res);
memcpy(res->attr.ma.res_type, tp->attr.ma.res_type, n_res * sizeof(res->attr.ma.res_type[0]));
res->attr.ma.value_ress = tp->attr.ma.value_ress;
res->attr.ma.variadicity = tp->attr.ma.variadicity;
......@@ -1597,9 +1597,9 @@ ir_type *new_d_type_array(ident *name, int n_dimensions, ir_type *element_type,
res = new_type(type_array, NULL, name, db);
res->attr.aa.n_dimensions = n_dimensions;
res->attr.aa.lower_bound = xcalloc(n_dimensions, sizeof(*res->attr.aa.lower_bound));
res->attr.aa.upper_bound = xcalloc(n_dimensions, sizeof(*res->attr.aa.upper_bound));
res->attr.aa.order = xcalloc(n_dimensions, sizeof(*res->attr.aa.order));
res->attr.aa.lower_bound = XMALLOCNZ(ir_node*, n_dimensions);
res->attr.aa.upper_bound = XMALLOCNZ(ir_node*, n_dimensions);
res->attr.aa.order = XMALLOCNZ(int, n_dimensions);
current_ir_graph = get_const_code_irg();
unk = new_Unknown(mode_Iu);
......
......@@ -1487,7 +1487,7 @@ unsigned char fc_sub_bits(const fp_value *value, unsigned num_bits, unsigned byt
/* this is used to cache the packed version of the value */
static char *packed_value = NULL;
if (packed_value == NULL) packed_value = xmalloc(value_size);
if (packed_value == NULL) packed_value = XMALLOCN(char, value_size);
if (value != NULL)
pack(value, packed_value);
......
......@@ -1472,8 +1472,8 @@ void init_strcalc(int precision) {
calc_buffer_size = (precision / 2);
max_value_size = (precision / 4);
calc_buffer = xmalloc(calc_buffer_size+1 * sizeof(char));
output_buffer = xmalloc(bit_pattern_size+1 * sizeof(char));
calc_buffer = XMALLOCN(char, calc_buffer_size + 1);
output_buffer = XMALLOCN(char, bit_pattern_size + 1);
DEBUGPRINTF(("init strcalc: \n\tPRECISION: %d\n\tCALC_BUFFER_SIZE = %d\n\tMAX_VALUE_SIZE = %d\n\tbuffer pointer: %p\n", precision, calc_buffer_size, max_value_size, calc_buffer));
}
......
......@@ -1525,7 +1525,7 @@ char *get_tarval_bitpattern(tarval *tv) {
int i, j, pos = 0;
int n = get_mode_size_bits(tv->mode);
int bytes = (n + 7) / 8;
char *res = xmalloc((n + 1) * sizeof(char));
char *res = XMALLOCN(char, n + 1);
unsigned char byte;
for(i = 0; i < bytes; i++) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment