implemented Setup.hs to build boehm cpp libs and install them;
[hs-boehmgc.git] / gc-7.2 / tests / huge_test.c
1
2 #include <stdlib.h>
3 #include <limits.h>
4 #include <stdio.h>
5
6 #ifndef GC_IGNORE_WARN
7   /* Ignore misleading "Out of Memory!" warning (which is printed on    */
8   /* every GC_MALLOC(LONG_MAX) call) by defining this macro before      */
9   /* "gc.h" inclusion.                                                  */
10 # define GC_IGNORE_WARN
11 #endif
12
13 #include "gc.h"
14
15 /*
16  * Check that very large allocation requests fail.  "Success" would usually
17  * indicate that the size was somehow converted to a negative
18  * number.  Clients shouldn't do this, but we should fail in the
19  * expected manner.
20  */
21
22 int main(void)
23 {
24     GC_INIT();
25
26     GC_set_max_heap_size(100*1024*1024);
27         /* Otherwise heap expansion aborts when deallocating large block. */
28         /* That's OK.  We test this corner case mostly to make sure that  */
29         /* it fails predictably.                                          */
30     GC_expand_hp(1024*1024*5);
31     if (sizeof(long) == sizeof(void *)) {
32         void *r = GC_MALLOC(LONG_MAX-1024);
33         if (0 != r) {
34             fprintf(stderr,
35                     "Size LONG_MAX-1024 allocation unexpectedly succeeded\n");
36             exit(1);
37         }
38         r = GC_MALLOC(LONG_MAX);
39         if (0 != r) {
40             fprintf(stderr,
41                     "Size LONG_MAX allocation unexpectedly succeeded\n");
42             exit(1);
43         }
44         r = GC_MALLOC((size_t)LONG_MAX + 1024);
45         if (0 != r) {
46             fprintf(stderr,
47                     "Size LONG_MAX+1024 allocation unexpectedly succeeded\n");
48             exit(1);
49         }
50     }
51     return 0;
52 }