PageRenderTime 11ms CodeModel.GetById 7ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

/vendor/gc/tests/huge_test.c

http://github.com/feyeleanor/RubyGoLightly
C | 45 lines | 31 code | 5 blank | 9 comment | 8 complexity | a14a6118cea66b8eb6f3a76497f0f61b MD5 | raw file
 1#include <stdlib.h>
 2#include <limits.h>
 3#include <stdio.h>
 4#include <gc.h>
 5
 6/*
 7 * Check that very large allocation requests fail.  "Success" would usually
 8 * indicate that the the size was somehow converted to a negative
 9 * number.  Clients shouldn't do this, but we should fail in the
10 * expected manner.
11 */
12
13
14main()
15{
16    GC_INIT();
17
18    GC_set_max_heap_size(100*1024*1024);
19    	/* Otherwise heap expansion aborts when deallocating large block. */
20        /* That's OK.  We test this corner case mostly to make sure that  */
21        /* it fails predictably.					  */
22    GC_expand_hp(1024*1024*5);
23    if (sizeof(long) == sizeof(void *)) {
24        void *r = GC_MALLOC(LONG_MAX-1024);
25	if (0 != r) {
26	    fprintf(stderr,
27	    	    "Size LONG_MAX-1024 allocation unexpectedly succeeded\n");
28	    exit(1);
29	}
30        r = GC_MALLOC(LONG_MAX);
31	if (0 != r) {
32	    fprintf(stderr,
33	            "Size LONG_MAX allocation unexpectedly succeeded\n");
34	    exit(1);
35	}
36        r = GC_MALLOC((size_t)LONG_MAX + 1024);
37	if (0 != r) {
38	    fprintf(stderr,
39	    	    "Size LONG_MAX+1024 allocation unexpectedly succeeded\n");
40	    exit(1);
41	}
42    }
43    return 0;
44}
45