Skip to content

Commit

Permalink
test/self_oom: Remove const cast
Browse files Browse the repository at this point in the history
(cherry picked from commit 6e5fd79)
Signed-off-by: LIU Hao <[email protected]>
  • Loading branch information
lhmouse committed Nov 9, 2024
1 parent 040c04f commit a765e87
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions test/self_oom.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@
* LICENSE.TXT as a whole. The GCC Runtime Library Exception applies
* to this file. */

#define __MCF_XGLOBALS_IMPORT
#define __MCF_XGLOBALS_INLINE __MCF_GNU_INLINE
#define __MCF_XGLOBALS_READONLY
#include "../mcfgthread/xglobals.h"
#include <assert.h>
#include <stdio.h>
#include <windows.h>

#if defined __CYGWIN__
int
main(void)
{
return 77;
}
#else // __CYGWIN__

#define NTHREADS 64U
static HANDLE threads[NTHREADS];

Expand All @@ -29,15 +40,10 @@ thread_proc(void* arg)
int
main(void)
{
#if defined __CYGWIN__
return 77;
#else
const uint32_t heap_capacity = 1048576; // 1 MB
volatile HANDLE* const heap = (volatile HANDLE*) &__MCF_crt_heap;

// replace global heap
*heap = HeapCreate(0, 0, heap_capacity);
assert(*heap);
const uint32_t heap_capacity = 1048576;
__MCF_crt_heap = HeapCreate(0, 0, heap_capacity);
assert(&__MCF_crt_heap);

// allocate until oom
for(uint32_t i = 0; i < heap_capacity / 16; ++i)
Expand All @@ -55,5 +61,6 @@ main(void)
CloseHandle(threads[k]);
fprintf(stderr, "main wait finished: %d\n", (int)k);
}
#endif
}

#endif // __CYGWIN__

0 comments on commit a765e87

Please sign in to comment.