Commit 9f580be227ab52566a0ad9f1f823208b765362d3

Authored by Loic Dachary
1 parent 7313600f
Exists in v2

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>
(cherry picked from commit 36008101d5fd1e3d19230828c0eb231869569893)
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;
... ... @@ -185,17 +186,17 @@ static void galois_init(int w)
185 186 {
186 187 if (w <= 0 || w > 32) {
187 188 fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
188   - exit(1);
  189 + assert(0);
189 190 }
190 191  
191 192 switch (galois_init_default_field(w)) {
192 193 case ENOMEM:
193 194 fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w);
194   - exit(1);
  195 + assert(0);
195 196 break;
196 197 case EINVAL:
197 198 fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
198   - exit(1);
  199 + assert(0);
199 200 break;
200 201 }
201 202 }
... ... @@ -234,12 +235,12 @@ void galois_change_technique(gf_t *gf, int w)
234 235 {
235 236 if (w <= 0 || w > 32) {
236 237 fprintf(stderr, "ERROR -- cannot support Galois field for w=%d\n", w);
237   - exit(1);
  238 + assert(0);
238 239 }
239 240  
240 241 if (!is_valid_gf(gf, w)) {
241 242 fprintf(stderr, "ERROR -- overriding with invalid Galois field for w=%d\n", w);
242   - exit(1);
  243 + assert(0);
243 244 }
244 245  
245 246 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"
... ... @@ -303,7 +304,7 @@ void jerasure_matrix_encode(int k, int m, int w, int *matrix,
303 304  
304 305 if (w != 8 && w != 16 && w != 32) {
305 306 fprintf(stderr, "ERROR: jerasure_matrix_encode() and w is not 8, 16 or 32\n");
306   - exit(1);
  307 + assert(0);
307 308 }
308 309  
309 310 for (i = 0; i < m; i++) {
... ... @@ -320,7 +321,7 @@ void jerasure_bitmatrix_dotprod(int k, int w, int *bitmatrix_row,
320 321  
321 322 if (size%(w*packetsize) != 0) {
322 323 fprintf(stderr, "jerasure_bitmatrix_dotprod - size%c(w*packetsize)) must = 0\n", '%');
323   - exit(1);
  324 + assert(0);
324 325 }
325 326  
326 327 bpptr = (dest_id < k) ? data_ptrs[dest_id] : coding_ptrs[dest_id-k];
... ... @@ -559,7 +560,7 @@ void jerasure_free_schedule_cache(int k, int m, int ***cache)
559 560  
560 561 if (m != 2) {
561 562 fprintf(stderr, "jerasure_free_schedule_cache(): m must equal 2\n");
562   - exit(1);
  563 + assert(0);
563 564 }
564 565  
565 566 for (e1 = 0; e1 < k+m; e1++) {
... ... @@ -581,7 +582,7 @@ void jerasure_matrix_dotprod(int k, int w, int *matrix_row,
581 582  
582 583 if (w != 1 && w != 8 && w != 16 && w != 32) {
583 584 fprintf(stderr, "ERROR: jerasure_matrix_dotprod() called and w is not 1, 8, 16 or 32\n");
584   - exit(1);
  585 + assert(0);
585 586 }
586 587  
587 588 init = 0;
... ... @@ -1359,12 +1360,12 @@ void jerasure_bitmatrix_encode(int k, int m, int w, int *bitmatrix,
1359 1360  
1360 1361 if (packetsize%sizeof(long) != 0) {
1361 1362 fprintf(stderr, "jerasure_bitmatrix_encode - packetsize(%d) %c sizeof(long) != 0\n", packetsize, '%');
1362   - exit(1);
  1363 + assert(0);
1363 1364 }
1364 1365 if (size%(packetsize*w) != 0) {
1365 1366 fprintf(stderr, "jerasure_bitmatrix_encode - size(%d) %c (packetsize(%d)*w(%d))) != 0\n",
1366 1367 size, '%', packetsize, w);
1367   - exit(1);
  1368 + assert(0);
1368 1369 }
1369 1370  
1370 1371 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 */
... ...