Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Usage of xbt_new0 instead calloc
authorcherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 11 Jan 2008 10:16:41 +0000 (10:16 +0000)
committercherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 11 Jan 2008 10:16:41 +0000 (10:16 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5193 48e7efb5-ca39-0410-a469-dd3cf9ba447f

12 files changed:
examples/msg/masterslave/masterslave_bypass.c
examples/msg/masterslave/masterslave_failure.c
examples/msg/masterslave/masterslave_forwarder.c
examples/msg/parallel_task/parallel_task.c
examples/msg/sendrecv/sendrecv.c
examples/simdag/sd_test2.c
examples/xbt/sem_sched.c
src/xbt/swag.c
testsuite/surf/lmm_usage.c
testsuite/surf/maxmin_bench.c
testsuite/xbt/graphxml_usage.c
testsuite/xbt/heap_bench.c

index 10d40ec..5769ff6 100644 (file)
@@ -197,7 +197,7 @@ int master(int argc, char *argv[])
   {                  /*  Task creation */
     char sprintf_buffer[64];
 
-    todo = calloc(number_of_tasks, sizeof(m_task_t));
+    todo = xbt_new0(m_task_t,number_of_tasks);
 
     for (i = 0; i < number_of_tasks; i++) {
       sprintf(sprintf_buffer, "Task_%d", i);
@@ -207,7 +207,7 @@ int master(int argc, char *argv[])
 
   {                  /* Process organisation */
     slaves_count = argc - 4;
-    slaves = calloc(slaves_count, sizeof(m_host_t));
+    slaves = xbt_new0(m_host_t,slaves_count);
     
     for (i = 4; i < argc; i++) {
       slaves[i-4] = MSG_get_host_by_name(argv[i]);
index ee1a615..57502fa 100644 (file)
@@ -47,7 +47,7 @@ int master(int argc, char *argv[])
 
   {                  /* Process organisation */
     slaves_count = argc - 4;
-    slaves = calloc(slaves_count, sizeof(m_host_t));
+    slaves = xbt_new0(m_host_t,slaves_count);
     
     for (i = 4; i < argc; i++) {
       slaves[i-4] = MSG_get_host_by_name(argv[i]);
@@ -66,7 +66,7 @@ int master(int argc, char *argv[])
 
   for (i = 0; i < number_of_tasks; i++) {
     m_task_t task = MSG_task_create("Task", task_comp_size, task_comm_size, 
-                                   calloc(1,sizeof(double)));
+                                   xbt_new0(double,1));
     int a;
     *((double*) task->data) = MSG_get_clock();
     
index e3a44db..c3179a0 100644 (file)
@@ -49,7 +49,7 @@ int master(int argc, char *argv[])
   {                  /*  Task creation */
     char sprintf_buffer[64];
 
-    todo = calloc(number_of_tasks, sizeof(m_task_t));
+    todo = xbt_new0(m_task_t,number_of_tasks);
 
     for (i = 0; i < number_of_tasks; i++) {
       sprintf(sprintf_buffer, "Task_%d", i);
@@ -59,7 +59,7 @@ int master(int argc, char *argv[])
 
   {                  /* Process organisation */
     slaves_count = argc - 4;
-    slaves = calloc(slaves_count, sizeof(m_host_t));
+    slaves = xbt_new0(m_host_t,slaves_count);
     
     for (i = 4; i < argc; i++) {
       slaves[i-4] = MSG_get_host_by_name(argv[i]);
@@ -129,7 +129,7 @@ int forwarder(int argc, char *argv[])
 
   {                  /* Process organisation */
     slaves_count = argc - 1;
-    slaves = calloc(slaves_count, sizeof(m_host_t));
+    slaves = xbt_new0(m_host_t,slaves_count);
     
     for (i = 1; i < argc; i++) {
       slaves[i-1] = MSG_get_host_by_name(argv[i]);
index 5e5acad..1dcf7e6 100644 (file)
@@ -32,8 +32,8 @@ int test(int argc, char *argv[])
   slaves_count = MSG_get_host_number();
   slaves = MSG_get_host_table();
 
-  computation_amount = calloc(slaves_count,sizeof(double));
-  communication_amount = calloc(slaves_count*slaves_count,sizeof(double));
+  computation_amount = xbt_new0(double,slaves_count);
+  communication_amount = xbt_new0(double,slaves_count*slaves_count);
   
   for(i=0;i<slaves_count;i++) 
     computation_amount[i]=task_comp_size;
index 5fa6f67..22720ab 100644 (file)
@@ -40,7 +40,7 @@ int sender(int argc,char *argv[] )
 
   INFO0("sender");
  
-  host = calloc(1, sizeof(m_host_t));
+  /*host = xbt_new0(m_host_t,1);*/
     
   INFO1("host = %s", argv[1]);
   
index 4466757..e625b58 100644 (file)
@@ -98,7 +98,7 @@ int main(int argc, char **argv) {
   PtoPcomm2_hosts[1] = hosts[2];
  
   /* parallel task without intra communications (1 sec duration) */
-  ParComp_wocomm_table = (double*) calloc (25, sizeof(double));
+  ParComp_wocomm_table = xbt_new0(double,25);
 
   for (i=0; i<5;i++){
     ParComp_wocomm_hosts[i]=hosts[i];
@@ -107,8 +107,8 @@ int main(int argc, char **argv) {
   /* redistribution within a cluster (small latencies) */
   /* each host send (4*2.5Mb =) 10Mb */
   /* bandwidth is shared between 5 flows (0.05sec duration) */
-  IntraRedist_cost = (double*) calloc (5, sizeof(double));
-  IntraRedist_table = (double*) calloc (25, sizeof(double));
+  IntraRedist_cost = xbt_new0(double,5);
+  IntraRedist_table = xbt_new0(double,25);
   for (i=0;i<5;i++){
     for (j=0;j<5;j++){
       if (i==j) 
@@ -124,7 +124,7 @@ int main(int argc, char **argv) {
   
   /* parallel task with intra communications */
   /* Computation domination (1 sec duration) */
-  ParComp_wcomm1_table = (double*) calloc (25, sizeof(double));
+  ParComp_wcomm1_table = xbt_new0(double,25);
   
   for (i=0; i<5;i++){
     ParComp_wcomm1_hosts[i]=hosts[i];
@@ -141,8 +141,8 @@ int main(int argc, char **argv) {
   
   /* inter cluster redistribution (big latency on the backbone) */
   /* (0.5sec duration without latency impact)*/
-  InterRedist_cost = (double*) calloc (10, sizeof(double));
-  InterRedist_table = (double*) calloc (100, sizeof(double));
+  InterRedist_cost = xbt_new0(double,10);
+  InterRedist_table = xbt_new0(double,100);
   for (i=0;i<5;i++){
     InterRedist_table[i*10+i+5] = 1250000.; /* 10Mb */
   }
@@ -150,7 +150,7 @@ int main(int argc, char **argv) {
   /* parallel task with intra communications */
   /* Communication domination (0.1 sec duration) */
   
-  ParComp_wcomm2_table = (double*) calloc (25, sizeof(double));
+  ParComp_wcomm2_table = xbt_new0(double,25);
   
   for (i=0; i<5;i++){
     ParComp_wcomm2_hosts[i]=hosts[i+5];
index 2afe336..6549403 100644 (file)
@@ -125,7 +125,7 @@ main(int argc, char* argv[])
                exit(EXIT_FAILURE);\r
        }\r
        \r
-       __argv = (char**)calloc(MAX_ARGS,sizeof(char*));\r
+       __argv = xbt_new0(char*,MAX_ARGS);\r
        \r
        for(i = 0; i < MAX_ARGS; i++)\r
        {\r
@@ -221,7 +221,7 @@ void unschedule(ctx_t c)
 ctx_t \r
 ctx_new(job_t job)\r
 {\r
-       ctx_t ctx = (ctx_t)calloc(1,sizeof(s_ctx_t));\r
+       ctx_t ctx = xbt_new0(s_ctx_t,1);\r
        ctx->index = ++__next_ctx_ID;\r
        ctx->begin = xbt_os_sem_init(0);\r
        ctx->end = xbt_os_sem_init(0);\r
@@ -260,7 +260,7 @@ sched_new(int size)
                return NULL;\r
        }\r
        \r
-       sched = (sched_t)calloc(1,sizeof(s_sched_t));\r
+       sched = xbt_new0(s_sched_t,1);\r
        \r
        if(!sched)\r
        {\r
@@ -268,7 +268,7 @@ sched_new(int size)
                return NULL;\r
        }\r
                \r
-       sched->ctxs = (ctx_t*)calloc(size,sizeof(ctx_t));\r
+       sched->ctxs = xbt_new0(ctx_t,size);\r
        \r
        if(!(sched->ctxs))\r
        {\r
@@ -403,7 +403,7 @@ job_new(pfn_func_t func, int argc, char** argv)
        int i;\r
        \r
        /* todo check the parameters */\r
-       job = (job_t)calloc(1,sizeof(s_job_t));\r
+       job = xbt_new0(s_job_t,1);\r
        \r
        if(!job)\r
        {\r
@@ -411,7 +411,7 @@ job_new(pfn_func_t func, int argc, char** argv)
                return NULL;\r
        }\r
        \r
-       job->argv = (char**)calloc(argc,sizeof(char*));\r
+       job->argv = xbt_new0(char*,argc);\r
        \r
        if(!(job->argv))\r
        {\r
index 873724b..67319cc 100644 (file)
@@ -243,8 +243,8 @@ XBT_TEST_UNIT("basic",test_swag_basic,"Basic usage") {
   shmurtz_t obj1, obj2, obj;
   xbt_swag_t setA,setB;
 
-  obj1 = calloc(1,sizeof(s_shmurtz_t));
-  obj2 = calloc(1,sizeof(s_shmurtz_t));
+  obj1 = xbt_new0(s_shmurtz_t,1);
+  obj2 = xbt_new0(s_shmurtz_t,1);
 
   obj1->name="Obj 1";
   obj2->name="Obj 2";
index 3fe0ddb..346d073 100644 (file)
@@ -306,12 +306,12 @@ void test3(method_t method)
 
     1, 1, 1, 1, 1
   };
-
-  A = (double **) calloc(links + 5, sizeof(double));
+       
+  /*A = xbt_new0(double*, links + 5);*/
+  A = xbt_new0(double*, links + 5);
 
   for (i = 0; i < links + 5; i++) {
-    A[i] = (double *) calloc(flows + 5, sizeof(double));
-
+    A[i] = xbt_new0(double, flows + 5);
     for (j = 0; j < flows + 5; j++) {
       A[i][j] = 0.0;
 
@@ -402,12 +402,12 @@ void test3(method_t method)
 
 
 
-  tmp_name = (char **) calloc(31, sizeof(char *));
+  tmp_name = xbt_new0(char *,31);
 
   /*
    * Creates the constraints
    */
-  tmp_cnst = calloc(15, sizeof(lmm_constraint_t));
+  tmp_cnst = xbt_new0(lmm_constraint_t,15);
   for (i = 0; i < 15; i++) {
     tmp_name[i] = bprintf("C_%03d", i);
     tmp_cnst[i] = lmm_constraint_new(Sys, (void *) tmp_name[i], B[i]);
@@ -417,7 +417,7 @@ void test3(method_t method)
   /*
    * Creates the variables
    */
-  tmp_var = calloc(16, sizeof(lmm_variable_t));
+  tmp_var = xbt_new0(lmm_variable_t,16);
   for (j = 0; j < 16; j++) {
     tmp_name[i + j] = bprintf("X_%03d", j);
     tmp_var[j] =
index e23d4b7..6c0e34c 100644 (file)
@@ -36,9 +36,9 @@ void test(int nb_cnst, int nb_var, int nb_elem);
 void test(int nb_cnst, int nb_var, int nb_elem)
 {
   lmm_system_t Sys = NULL;
-  lmm_constraint_t *cnst = calloc(nb_cnst, sizeof(lmm_constraint_t));
-  lmm_variable_t *var = calloc(nb_var, sizeof(lmm_variable_t));
-  int *used = calloc(nb_cnst, sizeof(int));
+  lmm_constraint_t *cnst = xbt_new0(lmm_constraint_t,nb_cnst);
+  lmm_variable_t *var = xbt_new0(lmm_variable_t,nb_var);
+  int *used = xbt_new0(int,nb_cnst);
   int i, j, k;
 
   Sys = lmm_system_new();
index 3930ca7..f0e63f9 100644 (file)
@@ -76,7 +76,7 @@ void test(char *graph_file)
 
     INFO0("---- Dumping Edge lengths ----");
     adj = xbt_graph_get_length_matrix(graph);
-    buf = calloc(n * 20, sizeof(char));
+    buf = xbt_new0(char,n * 20);
     for (i = 0; i < n; i++) {
       for (j = 0; j < n; j++) {
        sprintf(buf + strlen(buf), "%le\t", adj[i * n + j]);
@@ -94,7 +94,7 @@ void test(char *graph_file)
   
     INFO0("---- Testing Shortest Paths ----");
     route = xbt_graph_shortest_paths(graph);
-    buf = calloc(n * 40, sizeof(char));
+    buf = xbt_new0(char,n * 40);
     for (i = 0; i < n; i++) {
       for (j = 0; j < n; j++) {
        if (route[i * n + j])
index a18402b..cfeff7d 100644 (file)
@@ -48,7 +48,7 @@ int compare_double(const void *a, const void *b)
 void test_heap_validity(int size)
 {
   xbt_heap_t heap = xbt_heap_new(size, NULL);
-  double *tab = (double*)calloc(size,sizeof(double));
+  double *tab = xbt_new0(double,size);
 
   int i;