]> git-server-git.apps.pok.os.sepia.ceph.com Git - jerasure.git/commitdiff
use assert(0) instead of exit(1)
authorLoic Dachary <ldachary@redhat.com>
Mon, 15 Dec 2014 11:08:37 +0000 (12:08 +0100)
committerLoic Dachary <ldachary@redhat.com>
Mon, 15 Dec 2014 11:08:37 +0000 (12:08 +0100)
When a fatal error (unaligned memory etc.) is detected, jerasure
should assert(3) instead of exit(3) to give a chance to the calling
program to catch the exception and display a stack trace. Although it is
possible for gdb to display the stack trace and break on exit, libraries
are not usually expected to terminate the calling program in this way.

Signed-off-by: Loic Dachary <loic@dachary.org>
src/galois.c
src/jerasure.c
src/reed_sol.c

index 6dc4282ed122b996185686531d7276349941f69a..cd9faa8ee8302c1c8daed45c3761c40c108f0d57 100644 (file)
@@ -48,6 +48,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <assert.h>
 
 #include "galois.h"
 
@@ -78,25 +79,25 @@ gf_t* galois_init_field(int w,
 
   if (w <= 0 || w > 32) {
     fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
-    exit(1);
+    assert(0);
   }
 
   gfp = (gf_t *) malloc(sizeof(gf_t));
   if (!gfp) {
     fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w);
-    exit(1);
+    assert(0);
   }
 
   scratch_size = gf_scratch_size(w, mult_type, region_type, divide_type, arg1, arg2);
   if (!scratch_size) {
     fprintf(stderr, "ERROR -- cannot get scratch size for base field w=%d\n", w);
-    exit(1);
+    assert(0);
   }
 
   scratch_memory = malloc(scratch_size);
   if (!scratch_memory) {
     fprintf(stderr, "ERROR -- cannot get scratch memory for base field w=%d\n", w);
-    exit(1);
+    assert(0);
   }
 
   if(!gf_init_hard(gfp,
@@ -111,7 +112,7 @@ gf_t* galois_init_field(int w,
                    scratch_memory))
   {
     fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
-    exit(1);
+    assert(0);
   }
 
   gfp_is_composite[w] = 0;
@@ -130,25 +131,25 @@ gf_t* galois_init_composite_field(int w,
   
   if (w <= 0 || w > 32) {
     fprintf(stderr, "ERROR -- cannot init composite field for w=%d\n", w);
-    exit(1);
+    assert(0);
   }
   
   gfp = (gf_t *) malloc(sizeof(gf_t));
   if (!gfp) {
     fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w);
-    exit(1);
+    assert(0);
   }
 
   scratch_size = gf_scratch_size(w, GF_MULT_COMPOSITE, region_type, divide_type, degree, 0);
   if (!scratch_size) {
     fprintf(stderr, "ERROR -- cannot get scratch size for composite field w=%d\n", w);
-    exit(1);
+    assert(0);
   }
 
   scratch_memory = malloc(scratch_size);
   if (!scratch_memory) {
     fprintf(stderr, "ERROR -- cannot get scratch memory for composite field w=%d\n", w);
-    exit(1);
+    assert(0);
   }
 
   if(!gf_init_hard(gfp,
@@ -163,7 +164,7 @@ gf_t* galois_init_composite_field(int w,
                    scratch_memory))
   {
     fprintf(stderr, "ERROR -- cannot init default composite field for w=%d\n", w);
-    exit(1);
+    assert(0);
   }
   gfp_is_composite[w] = 1;
   return gfp;
@@ -197,17 +198,17 @@ static void galois_init(int w)
 {
   if (w <= 0 || w > 32) {
     fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
-    exit(1);
+    assert(0);
   }
 
   switch (galois_init_default_field(w)) {
   case ENOMEM:
     fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w);
-    exit(1);
+    assert(0);
     break;
   case EINVAL:
     fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
-    exit(1);
+    assert(0);
     break;
   }
 }
@@ -246,12 +247,12 @@ void galois_change_technique(gf_t *gf, int w)
 {
   if (w <= 0 || w > 32) {
     fprintf(stderr, "ERROR -- cannot support Galois field for w=%d\n", w);
-    exit(1);
+    assert(0);
   }
 
   if (!is_valid_gf(gf, w)) {
     fprintf(stderr, "ERROR -- overriding with invalid Galois field for w=%d\n", w);
-    exit(1);
+    assert(0);
   }
 
   if (gfp_array[w] != NULL) {
index d8c1179deaecbcb546cd6a8b2c9bb85425f5e874..6874a8a563afae5b8c03b65fd4e682a63f5a490a 100644 (file)
@@ -47,6 +47,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 
 #include "galois.h"
 #include "jerasure.h"
@@ -311,7 +312,7 @@ void jerasure_matrix_encode(int k, int m, int w, int *matrix,
   
   if (w != 8 && w != 16 && w != 32) {
     fprintf(stderr, "ERROR: jerasure_matrix_encode() and w is not 8, 16 or 32\n");
-    exit(1);
+    assert(0);
   }
 
   for (i = 0; i < m; i++) {
@@ -328,7 +329,7 @@ void jerasure_bitmatrix_dotprod(int k, int w, int *bitmatrix_row,
 
   if (size%(w*packetsize) != 0) {
     fprintf(stderr, "jerasure_bitmatrix_dotprod - size%c(w*packetsize)) must = 0\n", '%');
-    exit(1);
+    assert(0);
   }
 
   bpptr = (dest_id < k) ? data_ptrs[dest_id] : coding_ptrs[dest_id-k];
@@ -567,7 +568,7 @@ void jerasure_free_schedule_cache(int k, int m, int ***cache)
 
   if (m != 2) {
     fprintf(stderr, "jerasure_free_schedule_cache(): m must equal 2\n");
-    exit(1);
+    assert(0);
   }
 
   for (e1 = 0; e1 < k+m; e1++) {
@@ -589,7 +590,7 @@ void jerasure_matrix_dotprod(int k, int w, int *matrix_row,
 
   if (w != 1 && w != 8 && w != 16 && w != 32) {
     fprintf(stderr, "ERROR: jerasure_matrix_dotprod() called and w is not 1, 8, 16 or 32\n");
-    exit(1);
+    assert(0);
   }
 
   init = 0;
@@ -1456,12 +1457,12 @@ void jerasure_bitmatrix_encode(int k, int m, int w, int *bitmatrix,
 
   if (packetsize%sizeof(long) != 0) {
     fprintf(stderr, "jerasure_bitmatrix_encode - packetsize(%d) %c sizeof(long) != 0\n", packetsize, '%');
-    exit(1);
+    assert(0);
   }
   if (size%(packetsize*w) != 0) {
     fprintf(stderr, "jerasure_bitmatrix_encode - size(%d) %c (packetsize(%d)*w(%d))) != 0\n", 
          size, '%', packetsize, w);
-    exit(1);
+    assert(0);
   }
 
   for (i = 0; i < m; i++) {
index c0dfe83832a7ee816260c9a9959d32f3bdc500fe..82edacb3c2ce2cf63e01a37cadb576a06a14d921 100644 (file)
@@ -47,6 +47,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 
 #include <gf_complete.h>
 #include "galois.h"
@@ -107,7 +108,7 @@ void reed_sol_galois_w08_region_multby_2(char *region, int nbytes)
     if (!gf_init_hard(&GF08, 8, GF_MULT_BYTWO_b, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT,
                       prim08, 0, 0, NULL, NULL)) {
       fprintf(stderr, "Error: Can't initialize the GF for reed_sol_galois_w08_region_multby_2\n");
-      exit(1);
+      assert(0);
     }
   }
   GF08.multiply_region.w32(&GF08, region, region, 2, nbytes, 0);
@@ -123,7 +124,7 @@ void reed_sol_galois_w16_region_multby_2(char *region, int nbytes)
     if (!gf_init_hard(&GF16, 16, GF_MULT_BYTWO_b, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT,
                       prim16, 0, 0, NULL, NULL)) {
       fprintf(stderr, "Error: Can't initialize the GF for reed_sol_galois_w16_region_multby_2\n");
-      exit(1);
+      assert(0);
     }
   }
   GF16.multiply_region.w32(&GF16, region, region, 2, nbytes, 0);
@@ -139,7 +140,7 @@ void reed_sol_galois_w32_region_multby_2(char *region, int nbytes)
     if (!gf_init_hard(&GF32, 32, GF_MULT_BYTWO_b, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT,
                       prim32, 0, 0, NULL, NULL)) {
       fprintf(stderr, "Error: Can't initialize the GF for reed_sol_galois_w32_region_multby_2\n");
-      exit(1);
+      assert(0);
     }
   }
   GF32.multiply_region.w32(&GF32, region, region, 2, nbytes, 0);
@@ -223,7 +224,7 @@ int *reed_sol_big_vandermonde_distribution_matrix(int rows, int cols, int w)
     if (j >= rows) {   /* This should never happen if rows/w are correct */
       fprintf(stderr, "reed_sol_big_vandermonde_distribution_matrix(%d,%d,%d) - couldn't make matrix\n", 
              rows, cols, w);
-      exit(1);
+      assert(0);
     }
  
     /* If necessary, swap rows */