Skip to content

Commit

Permalink
Minor updates for oversight invalid state
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfriend99 committed Oct 6, 2024
1 parent 803867e commit ee4fced
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
20 changes: 17 additions & 3 deletions libs/http/request.b
Original file line number Diff line number Diff line change
Expand Up @@ -1216,11 +1216,17 @@ class HttpRequest {
return http_response
}

@to_string() {
/**
* Returns the request as a string.
*/
to_string() {
return '<HttpRequest method=${self.method}, path=${self.path}>'
}

@to_json() {
/**
* Returns the request as a JSON object.
*/
to_json() {
return {
request_uri: self.request_uri,
path: self.path,
Expand All @@ -1230,8 +1236,16 @@ class HttpRequest {
headers: self.headers,
queries: self.queries,
cookies: self.cookies,
body: self.body,
body: to_string(self.body),
}
}

@to_string() {
return self.to_string()
}

@to_json() {
return self.to_json()
}
}

22 changes: 18 additions & 4 deletions libs/http/response.b
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,18 @@ class HttpResponse {
self.headers.set('Content-Type', mimetype)
}

@to_string() {
/**
* Returns the response details in a string
*/
to_string() {
return '<HttpResponse status: ${self.status}, version: ${self.version}, time_taken:' +
' ${self.time_taken}, redirects: ${self.redirects}, responder: ${self.responder}>'
' ${self.time_taken}, redirects: ${self.redirects}, responder: ${self.responder}>'
}

@to_json() {
/**
* Returns the response as a JSON object
*/
to_json() {
return {
status: self.status,
version: self.version,
Expand All @@ -243,7 +249,15 @@ class HttpResponse {
responder: self.responder,
headers: self.headers,
cookies: self.cookies,
body: self.body
body: self.body,
}
}

@to_string() {
return self.to_string()
}

@to_json() {
return self.to_json()
}
}
10 changes: 10 additions & 0 deletions src/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,15 @@ void free_objects(b_vm *vm) {
vm->gray_stack = NULL;
}

void free_error_stacks(b_vm *vm) {
for(int index = vm->error_top - vm->errors; index < ERRORS_MAX && vm->errors[index] != NULL; index++) {
if(vm->errors[index]) {
free(vm->errors[index]);
vm->errors[index] = NULL;
}
}
}

void collect_garbage(b_vm *vm) {
#if defined(DEBUG_GC) && DEBUG_GC
printf("-- gc begins\n");
Expand All @@ -414,6 +423,7 @@ void collect_garbage(b_vm *vm) {
table_remove_whites(vm, &vm->strings);
table_remove_whites(vm, &vm->modules);
sweep(vm);
free_error_stacks(vm);

vm->next_gc = vm->bytes_allocated * GC_HEAP_GROWTH_FACTOR;
vm->mark_value = !vm->mark_value;
Expand Down

0 comments on commit ee4fced

Please sign in to comment.