fix more GC bugs

This commit is contained in:
2023-08-29 23:21:52 -05:00
committed by cpunch
parent d41126e75f
commit 6a47c82179
10 changed files with 57 additions and 47 deletions

View File

@@ -8,7 +8,7 @@
#include "cvalue.h"
// realloc wrapper
void *cosmoM_reallocate(CState *state, void *buf, size_t oldSize, size_t newSize)
void *cosmoM_reallocate(CState *state, void *buf, size_t oldSize, size_t newSize, bool isGC)
{
if (buf == NULL)
oldSize = 0;
@@ -34,18 +34,20 @@ void *cosmoM_reallocate(CState *state, void *buf, size_t oldSize, size_t newSize
return NULL;
}
if (isGC) {
#ifdef GC_STRESS
if (!(cosmoM_isFrozen(state)) && newSize > oldSize) {
cosmoM_collectGarbage(state);
}
if (!(cosmoM_isFrozen(state)) && newSize > oldSize) {
cosmoM_collectGarbage(state);
}
# ifdef GC_DEBUG
else {
printf("GC event ignored! state frozen! [%d]\n", state->freezeGC);
}
else {
printf("GC event ignored! state frozen! [%d]\n", state->freezeGC);
}
# endif
#else
cosmoM_checkGarbage(state, 0);
cosmoM_checkGarbage(state, 0);
#endif
}
// if NULL is passed, realloc() acts like malloc()
void *newBuf = realloc(buf, newSize);
@@ -206,8 +208,8 @@ static void markObject(CState *state, CObj *obj)
return;
// we can use cosmoM_growarray because we lock the GC when we entered in cosmoM_collectGarbage
cosmoM_growarray(state, CObj *, state->grayStack.array, state->grayStack.count,
state->grayStack.capacity);
cosmoM_growArrayNonGC(state, CObj *, state->grayStack.array, state->grayStack.count,
state->grayStack.capacity);
state->grayStack.array[state->grayStack.count++] = obj;
}