# HG changeset patch
# User dcoudert <david.coudert@inria.fr>
# Date 1356694568 -3600
# Node ID 59c3a848bdf197f4e443cf767423e5efa1b631f8
# Parent 386b880c3c51919efc089b5d710ffee3bbeaea84
trac #13875 -- Test memory allocation in distances_all_pairs
diff --git a/sage/graphs/distances_all_pairs.pyx b/sage/graphs/distances_all_pairs.pyx
a
|
b
|
|
91 | 91 | and ``None``. These case happens when the input is a disconnected graph, |
92 | 92 | or a non-strongly-connected digraph. |
93 | 93 | |
| 94 | - A memory error is raised when data structures allocation failed. This |
| 95 | could happen with large graphs on computers with low memory space. |
| 96 | |
94 | 97 | .. WARNING:: |
95 | 98 | |
96 | 99 | The function ``all_pairs_shortest_path_BFS`` has **no reason** to be |
… |
… |
|
159 | 162 | # The list of waiting vertices, the beginning and the end of the list |
160 | 163 | |
161 | 164 | cdef unsigned short * waiting_list = <unsigned short *> sage_malloc(n*sizeof(short)) |
| 165 | if waiting_list==NULL: |
| 166 | raise MemoryError() |
162 | 167 | cdef unsigned short waiting_beginning = 0 |
163 | 168 | cdef unsigned short waiting_end = 0 |
164 | 169 | |
165 | 170 | cdef int * degree = <int *> sage_malloc(n*sizeof(int)) |
| 171 | if degree==NULL: |
| 172 | sage_free(waiting_list) |
| 173 | raise MemoryError() |
166 | 174 | |
167 | 175 | cdef unsigned short source |
168 | 176 | cdef unsigned short v, u |
… |
… |
|
183 | 191 | c_distances = distances |
184 | 192 | else: |
185 | 193 | c_distances = <unsigned short *> sage_malloc( n * sizeof(unsigned short *)) |
186 | | |
| 194 | if c_distances==NULL: |
| 195 | sage_free(waiting_list) |
| 196 | sage_free(degree) |
| 197 | raise MemoryError() |
187 | 198 | cdef int * outneighbors |
188 | 199 | cdef int o_n_size |
189 | 200 | |
… |
… |
|
298 | 309 | |
299 | 310 | cdef int n = G.order() |
300 | 311 | cdef unsigned short * distances = <unsigned short *> sage_malloc(n*n*sizeof(unsigned short *)) |
| 312 | if distances==NULL: |
| 313 | raise MemoryError() |
301 | 314 | cdef unsigned short * predecessors = <unsigned short *> sage_malloc(n*n*sizeof(unsigned short *)) |
| 315 | if predecessors==NULL: |
| 316 | sage_free(distances) |
| 317 | raise MemoryError() |
302 | 318 | all_pairs_shortest_path_BFS(G, predecessors, distances, NULL) |
303 | 319 | |
304 | 320 | sage_free(distances) |
… |
… |
|
385 | 401 | |
386 | 402 | cdef int n = G.order() |
387 | 403 | cdef unsigned short * distances = <unsigned short *> sage_malloc(n*n*sizeof(unsigned short *)) |
| 404 | if distances==NULL: |
| 405 | raise MemoryError() |
388 | 406 | all_pairs_shortest_path_BFS(G, NULL, distances, NULL) |
389 | 407 | |
390 | 408 | return distances |
… |
… |
|
502 | 520 | return {}, {} |
503 | 521 | |
504 | 522 | cdef unsigned short * distances = <unsigned short *> sage_malloc(n*n*sizeof(unsigned short *)) |
| 523 | if distances==NULL: |
| 524 | raise MemoryError() |
505 | 525 | cdef unsigned short * c_distances = distances |
506 | 526 | cdef unsigned short * predecessor = <unsigned short *> sage_malloc(n*n*sizeof(unsigned short *)) |
| 527 | if predecessor==NULL: |
| 528 | sage_free(distances) |
| 529 | raise MemoryError() |
507 | 530 | cdef unsigned short * c_predecessor = predecessor |
508 | 531 | |
509 | 532 | all_pairs_shortest_path_BFS(G, predecessor, distances, NULL) |
… |
… |
|
557 | 580 | cdef int n = G.order() |
558 | 581 | |
559 | 582 | cdef unsigned short * ecc = <unsigned short *> sage_malloc(n*sizeof(unsigned short *)) |
| 583 | if ecc==NULL: |
| 584 | raise MemoryError() |
560 | 585 | cdef unsigned short * distances = <unsigned short *> sage_malloc(n*n*sizeof(unsigned short *)) |
| 586 | if distances==NULL: |
| 587 | sage_free(ecc) |
| 588 | raise MemoryError() |
561 | 589 | all_pairs_shortest_path_BFS(G, NULL, distances, ecc) |
562 | 590 | sage_free(distances) |
563 | 591 | |
… |
… |
|
876 | 904 | |
877 | 905 | # init dist |
878 | 906 | t_dist = <unsigned short *> sage_malloc(n*n*sizeof(short)) |
| 907 | if t_dist==NULL: |
| 908 | raise MemoryError() |
879 | 909 | dist = <unsigned short **> sage_malloc(n*sizeof(short *)) |
| 910 | if dist==NULL: |
| 911 | sage_free(t_dist) |
| 912 | raise MemoryError() |
880 | 913 | dist[0] = t_dist |
881 | 914 | for 1 <= i< n: |
882 | 915 | dist[i] = dist[i-1] + n |
… |
… |
|
890 | 923 | if paths: |
891 | 924 | # init prec |
892 | 925 | t_prec = <unsigned short *> sage_malloc(n*n*sizeof(short)) |
| 926 | if t_prec==NULL: |
| 927 | sage_free(t_dist) |
| 928 | sage_free(dist) |
| 929 | raise MemoryError() |
893 | 930 | prec = <unsigned short **> sage_malloc(n*sizeof(short *)) |
| 931 | if prec==NULL: |
| 932 | sage_free(t_dist) |
| 933 | sage_free(dist) |
| 934 | sage_free(t_prec) |
| 935 | raise MemoryError() |
894 | 936 | prec[0] = t_prec |
895 | 937 | for 1 <= i< n: |
896 | 938 | prec[i] = prec[i-1] + n |
diff --git a/sage/graphs/hyperbolicity.pyx b/sage/graphs/hyperbolicity.pyx
a
|
b
|
|
936 | 936 | # We compute the distances and store the results in a 2D array, and |
937 | 937 | # the diameter |
938 | 938 | _distances_ = c_distances_all_pairs(H) |
939 | | if _distances_ == NULL: |
940 | | raise MemoryError |
941 | 939 | distances = <unsigned short **>sage_malloc(sizeof(unsigned short *)*N) |
942 | 940 | if distances == NULL: |
943 | 941 | sage_free(_distances_) |