# define GC_IGNORE_WARN
#endif
+#ifndef GC_MAXIMUM_HEAP_SIZE
+# define GC_MAXIMUM_HEAP_SIZE 100 * 1024 * 1024
+# define GC_INITIAL_HEAP_SIZE GC_MAXIMUM_HEAP_SIZE / 20
+ /* Otherwise heap expansion aborts when deallocating large block. */
+ /* That's OK. We test this corner case mostly to make sure that */
+ /* it fails predictably. */
+#endif
+
#include "gc.h"
/*
* expected manner.
*/
+#define CHECK_ALLOC_FAILED(r, sz_str) \
+ do { \
+ if (NULL != (r)) { \
+ fprintf(stderr, \
+ "Size " sz_str " allocation unexpectedly succeeded\n"); \
+ exit(1); \
+ } \
+ } while (0)
+
#define GC_SWORD_MAX ((GC_signed_word)(((GC_word)-1) >> 1))
int main(void)
{
- void *r;
GC_INIT();
- GC_set_max_heap_size(100*1024*1024);
- /* Otherwise heap expansion aborts when deallocating large block. */
- /* That's OK. We test this corner case mostly to make sure that */
- /* it fails predictably. */
- GC_expand_hp(1024*1024*5);
- r = GC_MALLOC(GC_SWORD_MAX - 1024);
- if (NULL != r) {
- fprintf(stderr,
- "Size SWORD_MAX-1024 allocation unexpectedly succeeded\n");
- exit(1);
- }
- r = GC_MALLOC(GC_SWORD_MAX);
- if (NULL != r) {
- fprintf(stderr,
- "Size SWORD_MAX allocation unexpectedly succeeded\n");
- exit(1);
- }
- r = GC_MALLOC((GC_word)GC_SWORD_MAX + 1024);
- if (NULL != r) {
- fprintf(stderr,
- "Size SWORD_MAX+1024 allocation unexpectedly succeeded\n");
- exit(1);
- }
+ CHECK_ALLOC_FAILED(GC_MALLOC(GC_SWORD_MAX - 1024), "SWORD_MAX-1024");
+ CHECK_ALLOC_FAILED(GC_MALLOC(GC_SWORD_MAX), "SWORD_MAX");
+ CHECK_ALLOC_FAILED(GC_MALLOC((GC_word)GC_SWORD_MAX + 1024),
+ "SWORD_MAX+1024");
return 0;
}