Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes printObject() under DEBUG_STRESS_GC. #392

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions c/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ static void freeObject(Obj* object) {
case OBJ_STRING: {
ObjString* string = (ObjString*)object;
FREE_ARRAY(char, string->chars, string->length + 1);
string->chars = NULL;
FREE(ObjString, object);
break;
}
Expand Down
14 changes: 12 additions & 2 deletions c/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,22 @@ void printObject(Value value) {
//< Methods and Initializers not-yet
//> Closures not-yet
case OBJ_CLOSURE:
printf("<fn %s>", AS_CLOSURE(value)->function->name->chars);
if (AS_CLOSURE(value)->function &&
AS_CLOSURE(value)->function->name &&
AS_CLOSURE(value)->function->name->chars) {
printf("<fn %s>", AS_CLOSURE(value)->function->name->chars);
} else {
printf("<fn uninit%ju>", (uintmax_t)(uintptr_t)AS_CLOSURE(value));
}
break;
//< Closures not-yet
//> Calls and Functions not-yet
case OBJ_FUNCTION:
printf("<fn %s>", AS_FUNCTION(value)->name->chars);
if (AS_FUNCTION(value)->name) {
printf("<fn %s>", AS_FUNCTION(value)->name->chars);
} else {
printf("<fn uninit%ju>", (uintmax_t)(uintptr_t)AS_FUNCTION(value));
}
break;
//< Calls and Functions not-yet
//> Classes and Instances not-yet
Expand Down