Commit 36008101d5fd1e3d19230828c0eb231869569893

Authored by Loic Dachary
1 parent c94348f7
Exists in master

use assert(0) instead of exit(1)

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>
Showing 3 changed files with 28 additions and 25 deletions   Show diff stats
src/galois.c
... ... @@ -48,6 +48,7 @@
48 48 #include <stdlib.h>
49 49 #include <string.h>
50 50 #include <errno.h>
  51 +#include <assert.h>
51 52  
52 53 #include "galois.h"
53 54  
... ... @@ -78,25 +79,25 @@ gf_t* galois_init_field(int w,
78 79  
79 80 if (w <= 0 || w > 32) {
80 81 fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
81   - exit(1);
  82 + assert(0);
82 83 }
83 84  
84 85 gfp = (gf_t *) malloc(sizeof(gf_t));
85 86 if (!gfp) {
86 87 fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w);
87   - exit(1);
  88 + assert(0);
88 89 }
89 90  
90 91 scratch_size = gf_scratch_size(w, mult_type, region_type, divide_type, arg1, arg2);
91 92 if (!scratch_size) {
92 93 fprintf(stderr, "ERROR -- cannot get scratch size for base field w=%d\n", w);
93   - exit(1);
  94 + assert(0);
94 95 }
95 96  
96 97 scratch_memory = malloc(scratch_size);
97 98 if (!scratch_memory) {
98 99 fprintf(stderr, "ERROR -- cannot get scratch memory for base field w=%d\n", w);
99   - exit(1);
  100 + assert(0);
100 101 }
101 102  
102 103 if(!gf_init_hard(gfp,
... ... @@ -111,7 +112,7 @@ gf_t* galois_init_field(int w,
111 112 scratch_memory))
112 113 {
113 114 fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
114   - exit(1);
  115 + assert(0);
115 116 }
116 117  
117 118 gfp_is_composite[w] = 0;
... ... @@ -130,25 +131,25 @@ gf_t* galois_init_composite_field(int w,
130 131  
131 132 if (w <= 0 || w > 32) {
132 133 fprintf(stderr, "ERROR -- cannot init composite field for w=%d\n", w);
133   - exit(1);
  134 + assert(0);
134 135 }
135 136  
136 137 gfp = (gf_t *) malloc(sizeof(gf_t));
137 138 if (!gfp) {
138 139 fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w);
139   - exit(1);
  140 + assert(0);
140 141 }
141 142  
142 143 scratch_size = gf_scratch_size(w, GF_MULT_COMPOSITE, region_type, divide_type, degree, 0);
143 144 if (!scratch_size) {
144 145 fprintf(stderr, "ERROR -- cannot get scratch size for composite field w=%d\n", w);
145   - exit(1);
  146 + assert(0);
146 147 }
147 148  
148 149 scratch_memory = malloc(scratch_size);
149 150 if (!scratch_memory) {
150 151 fprintf(stderr, "ERROR -- cannot get scratch memory for composite field w=%d\n", w);
151   - exit(1);
  152 + assert(0);
152 153 }
153 154  
154 155 if(!gf_init_hard(gfp,
... ... @@ -163,7 +164,7 @@ gf_t* galois_init_composite_field(int w,
163 164 scratch_memory))
164 165 {
165 166 fprintf(stderr, "ERROR -- cannot init default composite field for w=%d\n", w);
166   - exit(1);
  167 + assert(0);
167 168 }
168 169 gfp_is_composite[w] = 1;
169 170 return gfp;
... ... @@ -197,17 +198,17 @@ static void galois_init(int w)
197 198 {
198 199 if (w <= 0 || w > 32) {
199 200 fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
200   - exit(1);
  201 + assert(0);
201 202 }
202 203  
203 204 switch (galois_init_default_field(w)) {
204 205 case ENOMEM:
205 206 fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w);
206   - exit(1);
  207 + assert(0);
207 208 break;
208 209 case EINVAL:
209 210 fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
210   - exit(1);
  211 + assert(0);
211 212 break;
212 213 }
213 214 }
... ... @@ -246,12 +247,12 @@ void galois_change_technique(gf_t *gf, int w)
246 247 {
247 248 if (w <= 0 || w > 32) {
248 249 fprintf(stderr, "ERROR -- cannot support Galois field for w=%d\n", w);
249   - exit(1);
  250 + assert(0);
250 251 }
251 252  
252 253 if (!is_valid_gf(gf, w)) {
253 254 fprintf(stderr, "ERROR -- overriding with invalid Galois field for w=%d\n", w);
254   - exit(1);
  255 + assert(0);
255 256 }
256 257  
257 258 if (gfp_array[w] != NULL) {
... ...
src/jerasure.c
... ... @@ -47,6 +47,7 @@
47 47 #include <stdio.h>
48 48 #include <stdlib.h>
49 49 #include <string.h>
  50 +#include <assert.h>
50 51  
51 52 #include "galois.h"
52 53 #include "jerasure.h"
... ... @@ -311,7 +312,7 @@ void jerasure_matrix_encode(int k, int m, int w, int *matrix,
311 312  
312 313 if (w != 8 && w != 16 && w != 32) {
313 314 fprintf(stderr, "ERROR: jerasure_matrix_encode() and w is not 8, 16 or 32\n");
314   - exit(1);
  315 + assert(0);
315 316 }
316 317  
317 318 for (i = 0; i < m; i++) {
... ... @@ -328,7 +329,7 @@ void jerasure_bitmatrix_dotprod(int k, int w, int *bitmatrix_row,
328 329  
329 330 if (size%(w*packetsize) != 0) {
330 331 fprintf(stderr, "jerasure_bitmatrix_dotprod - size%c(w*packetsize)) must = 0\n", '%');
331   - exit(1);
  332 + assert(0);
332 333 }
333 334  
334 335 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)
567 568  
568 569 if (m != 2) {
569 570 fprintf(stderr, "jerasure_free_schedule_cache(): m must equal 2\n");
570   - exit(1);
  571 + assert(0);
571 572 }
572 573  
573 574 for (e1 = 0; e1 < k+m; e1++) {
... ... @@ -589,7 +590,7 @@ void jerasure_matrix_dotprod(int k, int w, int *matrix_row,
589 590  
590 591 if (w != 1 && w != 8 && w != 16 && w != 32) {
591 592 fprintf(stderr, "ERROR: jerasure_matrix_dotprod() called and w is not 1, 8, 16 or 32\n");
592   - exit(1);
  593 + assert(0);
593 594 }
594 595  
595 596 init = 0;
... ... @@ -1456,12 +1457,12 @@ void jerasure_bitmatrix_encode(int k, int m, int w, int *bitmatrix,
1456 1457  
1457 1458 if (packetsize%sizeof(long) != 0) {
1458 1459 fprintf(stderr, "jerasure_bitmatrix_encode - packetsize(%d) %c sizeof(long) != 0\n", packetsize, '%');
1459   - exit(1);
  1460 + assert(0);
1460 1461 }
1461 1462 if (size%(packetsize*w) != 0) {
1462 1463 fprintf(stderr, "jerasure_bitmatrix_encode - size(%d) %c (packetsize(%d)*w(%d))) != 0\n",
1463 1464 size, '%', packetsize, w);
1464   - exit(1);
  1465 + assert(0);
1465 1466 }
1466 1467  
1467 1468 for (i = 0; i < m; i++) {
... ...
src/reed_sol.c
... ... @@ -47,6 +47,7 @@
47 47 #include <stdio.h>
48 48 #include <stdlib.h>
49 49 #include <string.h>
  50 +#include <assert.h>
50 51  
51 52 #include <gf_complete.h>
52 53 #include "galois.h"
... ... @@ -107,7 +108,7 @@ void reed_sol_galois_w08_region_multby_2(char *region, int nbytes)
107 108 if (!gf_init_hard(&GF08, 8, GF_MULT_BYTWO_b, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT,
108 109 prim08, 0, 0, NULL, NULL)) {
109 110 fprintf(stderr, "Error: Can't initialize the GF for reed_sol_galois_w08_region_multby_2\n");
110   - exit(1);
  111 + assert(0);
111 112 }
112 113 }
113 114 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)
123 124 if (!gf_init_hard(&GF16, 16, GF_MULT_BYTWO_b, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT,
124 125 prim16, 0, 0, NULL, NULL)) {
125 126 fprintf(stderr, "Error: Can't initialize the GF for reed_sol_galois_w16_region_multby_2\n");
126   - exit(1);
  127 + assert(0);
127 128 }
128 129 }
129 130 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)
139 140 if (!gf_init_hard(&GF32, 32, GF_MULT_BYTWO_b, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT,
140 141 prim32, 0, 0, NULL, NULL)) {
141 142 fprintf(stderr, "Error: Can't initialize the GF for reed_sol_galois_w32_region_multby_2\n");
142   - exit(1);
  143 + assert(0);
143 144 }
144 145 }
145 146 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)
223 224 if (j >= rows) { /* This should never happen if rows/w are correct */
224 225 fprintf(stderr, "reed_sol_big_vandermonde_distribution_matrix(%d,%d,%d) - couldn't make matrix\n",
225 226 rows, cols, w);
226   - exit(1);
  227 + assert(0);
227 228 }
228 229  
229 230 /* If necessary, swap rows */
... ...