Skip to content

Commit 4da78cc

Browse files
committed
fixed all build errors
1 parent fd108eb commit 4da78cc

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/runtime/gc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ void markObject(Obj* object) {
6161
if (vm.grayCapacity < vm.grayCount + 1) {
6262
vm.grayCapacity = GROW_CAPACITY(vm.grayCapacity);
6363
vm.grayStack = (Obj**)realloc(vm.grayStack, sizeof(Obj*) * vm.grayCapacity);
64-
// If allocation fails here, we are in trouble. For a toy GC, exit(1) is "fine".
65-
if (vm.grayStack == NULL) exit(1);
64+
if (vm.grayStack == NULL) {
65+
fprintf(stderr, "Fatal: Out of memory for gray stack.\n");
66+
exit(1);
67+
}
6668
}
6769

6870
vm.grayStack[vm.grayCount++] = object;
@@ -200,7 +202,7 @@ static void markRoots() {
200202
static void traceReferences() {
201203
while (vm.grayCount > 0) {
202204
Obj* object = vm.grayStack[--vm.grayCount];
203-
blackenObject(object);
205+
if (object != NULL) blackenObject(object);
204206
}
205207
}
206208

src/runtime/vm_helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ bool call(ObjClosure *closure, int argCount, VM *vm) {
7474
return false;
7575
}
7676

77-
if (vm->frameCount == 64) {
77+
if (vm->frameCount == FRAMES_MAX) {
7878
runtimeError(vm, "Stack overflow.");
7979
return false;
8080
}

0 commit comments

Comments
 (0)