msg_host_t host_master = NULL;
msg_process_t process = NULL;
xbt_dynar_t host_dynar = MSG_hosts_as_dynar();
- char** hostname_list = malloc(sizeof(char*) * xbt_dynar_length(host_dynar));
+ char** hostname_list = xbt_malloc(sizeof(char*) * xbt_dynar_length(host_dynar));
xbt_dynar_foreach(host_dynar, i, host) {
process = MSG_process_create("slave", slave, NULL, host);
msg_host_t host = NULL;
msg_host_t host_master = NULL;
xbt_dynar_t host_dynar = MSG_hosts_as_dynar();
- char** hostname_list = malloc(sizeof(char*) * xbt_dynar_length(host_dynar));
+ char** hostname_list = xbt_malloc(sizeof(char*) * xbt_dynar_length(host_dynar));
xbt_dynar_foreach(host_dynar, i, host) {
MSG_process_create("slave", slave, NULL, host);
XBT_DEBUG("luaopen_simgrid *****");
/* Get the command line arguments from the lua interpreter */
- char **argv = malloc(sizeof(char *) * LUA_MAX_ARGS_COUNT);
+ char **argv = xbt_malloc(sizeof(char *) * LUA_MAX_ARGS_COUNT);
int argc = 1;
argv[0] = (char *) "/usr/bin/lua"; /* Lie on the argv[0] so that the stack dumping facilities find the right binary. FIXME: what if lua is not in that location? */
const char *sn = instr_node_name (s);
const char *dn = instr_node_name (d);
int len = strlen(sn)+strlen(dn)+1;
- char *name = (char*)malloc(len * sizeof(char));
+ char *name = (char*)xbt_malloc(len * sizeof(char));
snprintf (name, len, "%s%s", sn, dn);
void create_jed_event(jed_event_t *event, char *name, double start_time,
double end_time, const char *type) {
- *event = (jed_event_t) calloc(1, sizeof(s_jed_event_t));
+ *event = xbt_new0(s_jed_event_t,1);
(*event)->name = xbt_strdup(name);
(*event)->start_time = start_time;
void jed_simgrid_create_container(jed_simgrid_container_t *container, char *name) {
xbt_assert( name != NULL );
- *container = (jed_simgrid_container_t)calloc(1,sizeof(s_jed_simgrid_container_t));
+ *container = xbt_new0(s_jed_simgrid_container_t,1);
(*container)->name = xbt_strdup(name);
(*container)->is_lowest = 0;
(*container)->container_children = xbt_dynar_new(sizeof(jed_simgrid_container_t), NULL);
// printf(">>> start=%d end=%d\n", start, end);
- subset = (jed_res_subset_t)calloc(1,sizeof(s_jed_res_subset_t));
+ subset = xbt_new0(s_jed_res_subset_t,1);
subset->start_idx = start;
subset->nres = end-start+1;
subset->parent = parent;
}
nb_ids = xbt_dynar_length(id_list);
- id_ar = (int*)calloc(nb_ids, sizeof(int));
+ id_ar = xbt_new0(int,nb_ids);
xbt_dynar_foreach(id_list, iter, id_str) {
id_ar[iter] = atoi(id_str);
}
}
void jed_create_jedule(jedule_t *jedule) {
- *jedule = (jedule_t)calloc(1,sizeof(s_jedule_t));
+ *jedule = xbt_new0(s_jedule_t,1);
host2_simgrid_parent_container = xbt_dict_new_homogeneous(NULL);
container_name2container = xbt_dict_new_homogeneous(NULL);
(*jedule)->jedule_meta_info = xbt_dict_new_homogeneous(NULL);
if(wait(&status) < 0)
perror("wait");
if(WIFSIGNALED(status) && WCOREDUMP(status)){
- char *core_name = malloc(20);
+ char *core_name = xbt_malloc(20);
sprintf(core_name,"core_%d", pair);
rename("core", core_name);
free(core_name);
SD_task_t file = NULL;
char *name_tail=agnameof(agtail(edge));
char *name_head=agnameof(aghead(edge));
- char *name = malloc((strlen(name_head)+strlen(name_tail)+6)*sizeof(char));
+ char *name = xbt_malloc((strlen(name_head)+strlen(name_tail)+6)*sizeof(char));
sprintf(name, "%s->%s", name_tail, name_head);
double size = dot_parse_double(agget(edge, (char *) "size"));
XBT_DEBUG("size : %e, get size : %s", size, agget(edge, (char *) "size"));
SD_task_t file;
char *name_tail=agnameof(agtail(edge));
char *name_head=agnameof(aghead(edge));
- char *name = malloc((strlen(name_head)+strlen(name_tail)+6)*sizeof(char));
+ char *name = xbt_malloc((strlen(name_head)+strlen(name_tail)+6)*sizeof(char));
sprintf(name, "%s->%s", name_tail, name_head);
double size = dot_parse_double(agget(edge, (char *) "size"));
XBT_DEBUG("size : %e, get size : %s", size, agget(edge, (char *) "size"));
if(datatype->has_subtype == 1){
// This part handles the problem of non-contiguous memory
old_buf = buf;
- buf = malloc(count*smpi_datatype_size(datatype));
+ buf = xbt_malloc(count*smpi_datatype_size(datatype));
if (flags & SEND) {
subtype->serialize(old_buf, buf, count, datatype->substruct);
}
if(request->old_type->has_subtype == 0){
oldbuf = request->buf;
if (oldbuf){
- request->buf = malloc(request->size);
+ request->buf = xbt_malloc(request->size);
memcpy(request->buf,oldbuf,request->size);
}
}
s_smpi_mpi_vector_t* type_c = (s_smpi_mpi_vector_t*)sendtype;
- void * buf_tmp = malloc(count * type_c->size_oldtype);
+ void * buf_tmp = xbt_malloc(count * type_c->size_oldtype);
subtype->serialize( sendbuf, buf_tmp,1, subtype);
subtype = recvtype->substruct;
} else if (*min_usage == usage) {
if(saturated_constraint_set->pos == saturated_constraint_set->size) { // realloc the size
saturated_constraint_set->size *= 2;
- saturated_constraint_set->data = realloc(saturated_constraint_set->data, (saturated_constraint_set->size) * sizeof(int));
+ saturated_constraint_set->data = xbt_realloc(saturated_constraint_set->data, (saturated_constraint_set->size) * sizeof(int));
}
saturated_constraint_set->data[saturated_constraint_set->pos] = cnst_light_num;
saturated_constraint_set->pos++;
src_id, dst_id, links, nb_link);
/* Build the list of gtnets link IDs */
- gtnets_links = (int *) calloc(nb_link, sizeof(int));
+ gtnets_links = xbt_new0(int, nb_link);
i = 0;
xbt_dynar_foreach(links, cursor, link) {
gtnets_links[i++] = link->id;
#include "xbt/RngStream.h"
+#include "xbt/sysdep.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
RngStream g;
size_t len;
- g = (RngStream) malloc (sizeof (struct RngStream_InfoState));
+ g = (RngStream) xbt_malloc (sizeof (struct RngStream_InfoState));
if (g == NULL) {
printf ("RngStream_CreateStream: No more memory\n\n");
exit (EXIT_FAILURE);
}
if (name) {
len = strlen (name);
- g->name = (char *) malloc ((len + 1) * sizeof (char));
+ g->name = (char *) xbt_malloc ((len + 1) * sizeof (char));
strncpy (g->name, name, len + 1);
} else
g->name = 0;
exit (EXIT_FAILURE);
}
- g = (RngStream) malloc (sizeof (struct RngStream_InfoState));
+ g = (RngStream) xbt_malloc (sizeof (struct RngStream_InfoState));
if (g == NULL) {
printf ("RngStream_CopyStream: No more memory\n\n");
exit (EXIT_FAILURE);
static void good_example(void)
{
- global_context_t *global_context = malloc(sizeof(global_context_t));
+ global_context_t *global_context = xbt_malloc(sizeof(global_context_t));
/* GOOD_EXAMPLE */
{ /*01 */
if (count > size) {
H->size = (size << 1) + 1;
H->items =
- (void *) realloc(H->items,
+ (void *) xbt_realloc(H->items,
(H->size) * sizeof(struct xbt_heap_item));
}
if (H->count < size >> 2 && size > 16) {
size = (size >> 1) + 1;
H->items =
- (void *) realloc(items,
+ (void *) xbt_realloc(items,
size * sizeof(struct xbt_heap_item));
H->size = size;
}
str_l = portable_vsnprintf(NULL, (size_t) 0, fmt, ap);
va_end(ap);
assert(str_l >= 0); /* possible integer overflow if str_m > INT_MAX */
- *ptr = (char *) malloc(str_m = (size_t) str_l + 1);
+ *ptr = (char *) xbt_malloc(str_m = (size_t) str_l + 1);
if (*ptr == NULL) {
errno = ENOMEM;
str_l = -1;
va_end(ap2);
}
assert(str_l >= 0); /* possible integer overflow if str_m > INT_MAX */
- *ptr = (char *) malloc(str_m = (size_t) str_l + 1);
+ *ptr = (char *) xbt_malloc(str_m = (size_t) str_l + 1);
if (*ptr == NULL) {
errno = ENOMEM;
str_l = -1;
/* if str_m is 0, no buffer is allocated, just set *ptr to NULL */
if (str_m == 0) { /* not interested in resulting string, just return size */
} else {
- *ptr = (char *) malloc(str_m);
+ *ptr = (char *) xbt_malloc(str_m);
if (*ptr == NULL) {
errno = ENOMEM;
str_l = -1;
/* if str_m is 0, no buffer is allocated, just set *ptr to NULL */
if (str_m == 0) { /* not interested in resulting string, just return size */
} else {
- *ptr = (char *) malloc(str_m);
+ *ptr = (char *) xbt_malloc(str_m);
if (*ptr == NULL) {
errno = ENOMEM;
str_l = -1;
//if substring was not found add the entire string
if (NULL == q) {
v = strlen(p);
- to_push = malloc(v + 1);
+ to_push = xbt_malloc(v + 1);
memcpy(to_push, p, v);
to_push[v] = '\0';
xbt_dynar_push(res, &to_push);
done = 1;
} else {
//get the appearance
- to_push = malloc(q - p + 1);
+ to_push = xbt_malloc(q - p + 1);
memcpy(to_push, p, q - p);
//add string terminator
to_push[q - p] = '\0';
xbt_strbuff_t xbt_strbuff_new(void)
{
- xbt_strbuff_t res = malloc(sizeof(s_xbt_strbuff_t));
- res->data = malloc(512);
+ xbt_strbuff_t res = xbt_malloc(sizeof(s_xbt_strbuff_t));
+ res->data = xbt_malloc(512);
res->size = 512;
xbt_strbuff_empty(res);
return res;
*/
XBT_INLINE xbt_strbuff_t xbt_strbuff_new_from(const char *ctn)
{
- xbt_strbuff_t res = malloc(sizeof(s_xbt_strbuff_t));
+ xbt_strbuff_t res = xbt_malloc(sizeof(s_xbt_strbuff_t));
res->data = xbt_strdup(ctn);
res->used = res->size = strlen(ctn);
return res;
if (needed_space > b->size) {
b->size = MAX(minimal_increment + b->used, needed_space);
- b->data = realloc(b->data, b->size);
+ b->data = xbt_realloc(b->data, b->size);
}
strcpy(b->data + b->used, toadd);
b->used += addlen;
// XBT_DEBUG("Too short (by %d chars; %d chars left in area)",val_len- (end_subst-beg_subst), b->size - b->used);
if (newused > b->size) {
/* We have to realloc the data area before (because b->size is too small). We have to update our pointers, too */
- char *newdata = realloc(b->data,
+ char *newdata = xbt_realloc(b->data,
b->used + MAX(minimal_increment,
tooshort));
int offset = newdata - b->data;