summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2023-01-03 12:51:05 +0300
committerIvan Maidanski <ivmai@mail.ru>2023-01-03 13:11:20 +0300
commit98200e4fff00d243c9bc65591ee794eaab1b6b48 (patch)
treea08eac6bbf952dc55e84e1133da489d59087bc52 /tests
parent4cc216cfbf75bf8f3cab3434cb3c46117c2dcd12 (diff)
downloadbdwgc-98200e4fff00d243c9bc65591ee794eaab1b6b48.tar.gz
Fix allocated objects count increment in alloc8bytes of gctest
* tests/gctest.c [!GC_PTHREADS] (alloc8bytes): Define a function instead of a macro; increment atomic_count. * tests/gctest.c [GC_PTHREADS && !SMALL_CONFIG && !GC_DEBUG] (alloc8bytes): Return NULL (intead of fail) if out of memory. * tests/gctest.c (alloc_small): Do not increment atomic_count here; define p local variable; call CHECK_OUT_OF_MEMORY(p) instead of direct checking of p and fail.
Diffstat (limited to 'tests')
-rw-r--r--tests/gctest.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/tests/gctest.c b/tests/gctest.c
index a9958abd..066c5c11 100644
--- a/tests/gctest.c
+++ b/tests/gctest.c
@@ -1133,13 +1133,16 @@ void chktree(tn *t, int n)
chktree(t -> rchild, n-1);
}
-
#if defined(GC_PTHREADS)
-pthread_key_t fl_key;
+ pthread_key_t fl_key;
+#endif
void * alloc8bytes(void)
{
-# if defined(SMALL_CONFIG) || defined(GC_DEBUG)
+# ifndef GC_PTHREADS
+ AO_fetch_and_add1(&atomic_count);
+ return GC_MALLOC_ATOMIC(8);
+# elif defined(SMALL_CONFIG) || defined(GC_DEBUG)
AO_fetch_and_add1(&collectable_count);
return GC_MALLOC(8);
# else
@@ -1150,7 +1153,7 @@ void * alloc8bytes(void)
my_free_list_ptr = (void **)pthread_getspecific(fl_key);
if (my_free_list_ptr == 0) {
my_free_list_ptr = GC_NEW_UNCOLLECTABLE(void *);
- CHECK_OUT_OF_MEMORY(my_free_list_ptr);
+ if (NULL == my_free_list_ptr) return NULL;
AO_fetch_and_add1(&uncollectable_count);
if (pthread_setspecific(fl_key, my_free_list_ptr) != 0) {
GC_printf("pthread_setspecific failed\n");
@@ -1160,7 +1163,7 @@ void * alloc8bytes(void)
my_free_list = *my_free_list_ptr;
if (my_free_list == 0) {
my_free_list = GC_malloc_many(8);
- CHECK_OUT_OF_MEMORY(my_free_list);
+ if (NULL == my_free_list) return NULL;
}
next = GC_NEXT(my_free_list);
GC_PTR_STORE_AND_DIRTY(my_free_list_ptr, next);
@@ -1170,10 +1173,6 @@ void * alloc8bytes(void)
# endif
}
-#else
-# define alloc8bytes() GC_MALLOC_ATOMIC(8)
-#endif
-
#include "gc/gc_inline.h"
void test_tinyfl(void)
@@ -1196,11 +1195,9 @@ void alloc_small(int n)
int i;
for (i = 0; i < n; i += 8) {
- if (alloc8bytes() == 0) {
- GC_printf("Out of memory\n");
- FAIL;
- }
- AO_fetch_and_add1(&atomic_count);
+ void *p = alloc8bytes();
+
+ CHECK_OUT_OF_MEMORY(p);
}
}