### 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
 ... ... @@ -34,12 +34,47 @@ /* xmalloc() & friends. */ void *xmalloc(size_t size); void *xcalloc(size_t num, size_t size); void *xrealloc(void *ptr, size_t size); char *xstrdup(const char *str); #define xfree(ptr) free(ptr) /** * Allocate n objects of a certain type */ #define XMALLOCN(type, n) ((type*)xmalloc(sizeof(type) * (n))) /** * Allocate n objects of a certain type and zero them */ #define XMALLOCNZ(type, n) ((type*)memset(xmalloc(sizeof(type) * (n)), 0, sizeof(type) * (n))) /** * Allocate one object of a certain type */ #define XMALLOC(type) XMALLOCN(type, 1) /** * Allocate one object of a certain type and zero it */ #define XMALLOCZ(type) XMALLOCNZ(type, 1) /** * Reallocate n objects of a certain type */ #define XREALLOC(ptr, type, n) ((type*)xrealloc(ptr, sizeof(type) * (n))) /** * Allocate an object with n elements of a flexible array member */ #define XMALLOCF(type, member, n) ((type*)xmalloc(offsetof(type, member) + sizeof(((type*)0)->member) * (n))) /** * Allocate an object with n elements of a flexible array member and zero the * whole object */ #define XMALLOCFZ(type, member, n) ((type*)memset(xmalloc(offsetof(type, member) + sizeof(((type*)0)->member) * (n)), 0, offsetof(type, member) + sizeof(((type*)0)->member) * (n))) /* Includes for alloca() */ #if defined(__FreeBSD__) ... ...
 ... ... @@ -41,12 +41,8 @@ struct _bipartite_t { bipartite_t *bipartite_new(int n_left, int n_right) { int i, size; bipartite_t *gr; size = n_left > 0 ? n_left - 1 : 0; gr = xmalloc(sizeof(*gr) + size * sizeof(void *)); memset(gr, 0, sizeof(*gr)); bipartite_t *gr = XMALLOCFZ(bipartite_t, adj, n_left); int i; gr->n_left = n_left; gr->n_right = n_right; ... ...
 ... ... @@ -46,8 +46,8 @@ int firm_gaussjordansolve(double *A, double *vec, int nsize) { int i, j, row, col, col2, biggest_r = 0, biggest_c = 0, t; double big, temp, sum; double *scramvec = xmalloc(nsize * sizeof(*scramvec)); int *x = xmalloc(nsize * sizeof(*x)); double *scramvec = XMALLOCN(double, nsize); int *x = XMALLOCN(int, nsize); int res = 0; #define _A(row,col) A[(row)*nsize + (col)] ... ...
 ... ... @@ -43,7 +43,7 @@ struct _gs_matrix_t { static INLINE void alloc_cols(row_col_t *row, int c_cols) { assert(c_cols > row->c_cols); row->c_cols = c_cols; row->cols = xrealloc(row->cols, c_cols * sizeof(*row->cols)); row->cols = XREALLOC(row->cols, col_val_t, c_cols); } static INLINE void alloc_rows(gs_matrix_t *m, int c_rows, int c_cols, int begin_init) { ... ... @@ -51,7 +51,7 @@ static INLINE void alloc_rows(gs_matrix_t *m, int c_rows, int c_cols, int begin_ assert(c_rows > m->c_rows); m->c_rows = c_rows; m->rows = xrealloc(m->rows, c_rows * sizeof(*m->rows)); m->rows = XREALLOC(m->rows, row_col_t, c_rows); for (i = begin_init; i < c_rows; ++i) { m->rows[i].c_cols = 0; ... ... @@ -64,8 +64,7 @@ static INLINE void alloc_rows(gs_matrix_t *m, int c_rows, int c_cols, int begin_ } gs_matrix_t *gs_new_matrix(int n_init_rows, int n_init_cols) { gs_matrix_t *res = xmalloc(sizeof(*res)); memset(res, 0, sizeof(*res)); gs_matrix_t *res = XMALLOCZ(gs_matrix_t); if (n_init_rows < 16) n_init_rows = 16; res->initial_col_increase = n_init_cols; ... ... @@ -117,7 +116,7 @@ void gs_matrix_trim_row_capacities(gs_matrix_t *m) { if (the_row->c_cols) { the_row->c_cols = the_row->n_cols; if (the_row->c_cols) the_row->cols = xrealloc(the_row->cols, the_row->c_cols * sizeof(*the_row->cols)); the_row->cols = XREALLOC(the_row->cols, col_val_t, the_row->c_cols); else xfree(the_row->cols); } ... ... @@ -281,7 +280,7 @@ void gs_matrix_export(const gs_matrix_t *m, double *nw, int size) void gs_matrix_dump(const gs_matrix_t *m, int a, int b, FILE *out) { int effective_rows = MIN(a, m->c_rows); int r, c, i; double *elems = xmalloc(b * sizeof(*elems)); double *elems = XMALLOCN(double, b); // The rows which have some content for (r=0; r < effective_rows; ++r) { ... ...
 ... ... @@ -95,7 +95,7 @@ #ifndef Alloc #include "xmalloc.h" #define Alloc(size) (HashSetEntry*) xmalloc((size) * sizeof(HashSetEntry)) #define Alloc(size) XMALLOCN(HashSetEntry, (size)) #define Free(ptr) free(ptr) #endif /* Alloc */ ... ...
 ... ... @@ -89,9 +89,7 @@ void hungarian_print_costmatrix(hungarian_problem_t *p) { */ hungarian_problem_t *hungarian_new(int rows, int cols, int width, int match_type) { int i; hungarian_problem_t *p = xmalloc(sizeof(*p)); memset(p, 0, sizeof(p)); hungarian_problem_t *p = XMALLOCZ(hungarian_problem_t); FIRM_DBG_REGISTER(p->dbg, "firm.hungarian"); ... ... @@ -207,15 +205,15 @@ int hungarian_solve(hungarian_problem_t* p, int *assignment, int *final_cost, in m = p->num_rows; n = p->num_cols; col_mate = xcalloc(p->num_rows, sizeof(col_mate)); unchosen_row = xcalloc(p->num_rows, sizeof(unchosen_row)); row_dec = xcalloc(p->num_rows, sizeof(row_dec)); slack_row = xcalloc(p->num_rows, sizeof(slack_row)); col_mate = XMALLOCNZ(int, p->num_rows); unchosen_row = XMALLOCNZ(int, p->num_rows); row_dec = XMALLOCNZ(int, p->num_rows); slack_row = XMALLOCNZ(int, p->num_rows); row_mate = xcalloc(p->num_cols, sizeof(row_mate)); parent_row = xcalloc(p->num_cols, sizeof(parent_row)); col_inc = xcalloc(p->num_cols, sizeof(col_inc)); slack = xcalloc(p->num_cols, sizeof(slack)); row_mate = XMALLOCNZ(int, p->num_cols); parent_row = XMALLOCNZ(int, p->num_cols); col_inc = XMALLOCNZ(int, p->num_cols); slack = XMALLOCNZ(int, p->num_cols); memset(assignment, -1, m * sizeof(assignment)); ... ...
 ... ... @@ -99,7 +99,7 @@ static void pqueue_sift_up(pqueue_t *q, unsigned pos) { } pqueue_t *new_pqueue(void) { pqueue_t *res = xmalloc(sizeof(*res)); pqueue_t *res = XMALLOC(pqueue_t); res->elems = NEW_ARR_F(pqueue_el_t, 0); return res; } ... ...
 ... ... @@ -188,7 +188,7 @@ SET * (PMANGLE(new)) (MANGLEP(cmp_fun) cmp, int nslots) { int i; SET *table = xmalloc(sizeof(*table)); SET *table = XMALLOC(SET); if (nslots > SEGMENT_SIZE * DIRECTORY_SIZE) nslots = DIRECTORY_SIZE; ... ...
 ... ... @@ -51,13 +51,6 @@ void *xmalloc(size_t size) { return res; } void *xcalloc(size_t num, size_t size) { void *res = calloc(num, size); if (!res) xnomem(); return res; } void *xrealloc(void *ptr, size_t size) { /* ANSI blesses realloc (0, x) but SunOS chokes on it */ void *res = ptr ? realloc (ptr, size) : malloc (size); ... ...
 ... ... @@ -37,7 +37,6 @@ #include "array_t.h" #include "irprog.h" #include "entity_t.h" #include "xmalloc.h" #include "analyze_irg_args.h" ... ...
 ... ... @@ -156,7 +156,7 @@ void compute_cdep(ir_graph *irg) { cdep_env env; free_cdep(irg); cdep_data = xmalloc(sizeof(*cdep_data)); cdep_data = XMALLOC(cdep_info); obstack_init(&cdep_data->obst); cdep_data->cdep_map = pmap_create(); ... ...
 ... ... @@ -632,7 +632,7 @@ static ir_entity **get_free_methods(int *length) /* Finally, transform the set into an array. */ *length = eset_count(free_set); arr = xmalloc(sizeof(ir_entity *) * (*length)); arr = XMALLOCN(ir_entity*, *length); for (i = 0, ent = eset_first(free_set); ent; ent = eset_next(free_set)) { arr[i++] = ent; } ... ...
 ... ... @@ -162,7 +162,7 @@ dfs_edge_kind_t dfs_get_edge_kind(const dfs_t *dfs, const void *a, const void *b dfs_t *dfs_new(const absgraph_t *graph_impl, void *graph_self) { dfs_t *res = xmalloc(sizeof(res)); dfs_t *res = XMALLOC(dfs_t); dfs_node_t *node; res->graph_impl = graph_impl; ... ... @@ -193,8 +193,8 @@ dfs_t *dfs_new(const absgraph_t *graph_impl, void *graph_self) classify_edges(res); assert(res->pre_num == res->post_num); res->pre_order = xmalloc(res->pre_num * sizeof(res->pre_order)); res->post_order = xmalloc(res->post_num * sizeof(res->post_order)); res->pre_order = XMALLOCN(dfs_node_t*, res->pre_num); res->post_order = XMALLOCN(dfs_node_t*, res->post_num); foreach_set (res->nodes, node) { assert(node->pre_num < res->pre_num); assert(node->post_num < res->post_num); ... ... @@ -251,7 +251,7 @@ static int node_level_cmp(const void *a, const void *b) void dfs_dump(const dfs_t *dfs, FILE *file) { dfs_node_t **nodes = xmalloc(dfs->pre_num * sizeof(nodes)); dfs_node_t **nodes = XMALLOCN(dfs_node_t*, dfs->pre_num); dfs_node_t *node; dfs_edge_t *edge; int i, n = 0; ... ...
 ... ... @@ -163,10 +163,9 @@ solve_lgs(gs_matrix_t *mat, double *x, int size) #ifdef COMPARE_AGAINST_GAUSSJORDAN { double *nw = xmalloc(size * size * sizeof(*nw)); double *nx = xmalloc(size * sizeof(*nx)); double *nw = XMALLOCN(double, size * size); double *nx = XMALLOCNZ(double, size); memset(nx, 0, size * sizeof(*nx)); gs_matrix_export(mat, nw, size); stat_ev_tim_push(); ... ... @@ -213,8 +212,7 @@ static void exec_freq_node_info(void *ctx, FILE *f, const ir_node *irn) ir_exec_freq *create_execfreq(ir_graph *irg) { ir_exec_freq *execfreq = xmalloc(sizeof(execfreq)); memset(execfreq, 0, sizeof(execfreq)); ir_exec_freq *execfreq = XMALLOCZ(ir_exec_freq); execfreq->set = new_set(cmp_freq, 32); memset(&execfreq->hook, 0, sizeof(execfreq->hook)); ... ... @@ -258,8 +256,7 @@ compute_execfreq(ir_graph * irg, double loop_weight) * => they can "flow" from start to end. */ dfs = dfs_new(&absgraph_irg_cfg_succ, irg); ef = xmalloc(sizeof(ef)); memset(ef, 0, sizeof(ef)); ef = XMALLOCZ(ir_exec_freq); ef->min_non_zero = HUGE_VAL; /* initialize with a reasonable large number. */ freqs = ef->set = new_set(cmp_freq, dfs_get_n_nodes(dfs)); ... ... @@ -275,7 +272,7 @@ compute_execfreq(ir_graph * irg, double loop_weight) size = dfs_get_n_nodes(dfs); mat = gs_new_matrix(size, size); x = xmalloc(size*sizeof(*x)); x = XMALLOCN(double, size); for (idx = dfs_get_n_nodes(dfs) - 1; idx >= 0; --idx) { ir_node *bb = (ir_node *) dfs_get_post_num_node(dfs, size - idx - 1); ... ...
 ... ... @@ -245,7 +245,7 @@ void heights_recompute(heights_t *h) heights_t *heights_new(ir_graph *irg) { heights_t *res = xmalloc(sizeof(res)); heights_t *res = XMALLOC(heights_t); phase_init(&res->ph, "heights", irg, PHASE_DEFAULT_GROWTH, irn_height_init, NULL); res->dump_handle = dump_add_node_info_callback(height_dump_cb, res); heights_recompute(res); ... ...
 ... ... @@ -676,7 +676,7 @@ void compute_doms(ir_graph *irg) { n_blocks = init_construction(irg, count_and_init_blocks_dom); /* Memory for temporary information. */ tdi_list = xcalloc(n_blocks, sizeof(tdi_list)); tdi_list = XMALLOCNZ(tmp_dom_info, n_blocks); /* We need the out data structure. */ assure_irg_outs(irg); ... ... @@ -815,7 +815,7 @@ void compute_postdoms(ir_graph *irg) { n_blocks = init_construction(irg, count_and_init_blocks_pdom); /* Memory for temporary information. */ tdi_list = xcalloc(n_blocks, sizeof(tdi_list)); tdi_list = XMALLOCNZ(tmp_dom_info, n_blocks); /* We need the out data structure. */ assure_irg_outs(irg); ... ...
 ... ... @@ -204,7 +204,7 @@ void compute_extbb(ir_graph *irg) { if (irg->extbb_obst) obstack_free(irg->extbb_obst, NULL); else irg->extbb_obst = xmalloc(sizeof(*irg->extbb_obst)); irg->extbb_obst = XMALLOC(struct obstack); obstack_init(irg->extbb_obst); env.obst = irg->extbb_obst; ... ...
 ... ... @@ -191,7 +191,7 @@ void compute_extbb_execfreqs(ir_graph *irg, ir_exec_freq *execfreqs) { obstack_free(irg->extbb_obst, NULL); } else { irg->extbb_obst = xmalloc(sizeof(*irg->extbb_obst)); irg->extbb_obst = XMALLOC(struct obstack); } obstack_init(irg->extbb_obst); ... ...
 ... ... @@ -244,7 +244,7 @@ static INLINE void compute_back_edge_chains(lv_chk_t *lv) lv_chk_t *lv_chk_new(ir_graph *irg, const dfs_t *dfs) { lv_chk_t *res = xmalloc(sizeof(res)); lv_chk_t *res = XMALLOC(lv_chk_t); struct obstack *obst; int i; ... ...
 ... ... @@ -474,7 +474,7 @@ void compute_irg_outs(ir_graph *irg) { n_out_edges = count_outs(irg); /* allocate memory for all out edges. */ irg->outs = xcalloc(n_out_edges, sizeof(irg->outs)); irg->outs = XMALLOCNZ(ir_def_use_edge, n_out_edges); #ifdef DEBUG_libfirm irg->n_outs = n_out_edges; #endif /* defined DEBUG_libfirm */ ... ... @@ -635,7 +635,7 @@ void compute_ip_outs(void) { } global_count = n_out_edges = count_ip_outs(); out_edges = xcalloc(n_out_edges, sizeof(out_edges)); out_edges = XMALLOCNZ(ir_node*, n_out_edges); set_irp_ip_outedges(out_edges); set_ip_outs(); } ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
{"ft_lang_label":"__label__en","ft_lang_prob":0.7307377,"math_prob":0.9941977,"size":358,"snap":"2022-40-2023-06","text_gpt3_token_len":89,"char_repetition_ratio":0.121468924,"word_repetition_ratio":0.2962963,"special_character_ratio":0.25139666,"punctuation_ratio":0.14285715,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99470043,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-02-06T10:12:29Z\",\"WARC-Record-ID\":\"<urn:uuid:4962ede8-39b9-4d01-9d4c-b0ab96bc8e40>\",\"Content-Length\":\"720345\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b2c145af-a4a5-47e5-b4a8-8a3422f4b367>\",\"WARC-Concurrent-To\":\"<urn:uuid:5a245ccf-d2af-45ec-8558-fcabe7c636be>\",\"WARC-IP-Address\":\"129.13.76.78\",\"WARC-Target-URI\":\"https://git.scc.kit.edu/zwinkau/libfirm/-/commit/e07b61c6ed5d198a484761f8a40a4f26520d964d\",\"WARC-Payload-Digest\":\"sha1:E7GBIUYALS2HYOIKO5PFSSFAAYNJ3VU4\",\"WARC-Block-Digest\":\"sha1:LS6QYLD7F4JVN6IAWD3MWW2CD2YW3WX4\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764500334.35_warc_CC-MAIN-20230206082428-20230206112428-00591.warc.gz\"}"}