Skip to content

Commit

Permalink
fix(http): Bad collected flag usage
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed May 25, 2024
1 parent 7c5ebbf commit c69bd5a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4510,8 +4510,10 @@ fn dot(self: *Self, can_assign: bool, callee: Ast.Node.Index) Error!Ast.Node.Ind

if (can_assign and try self.match(.Equal)) {
components[dot_node].Dot.member_kind = .Value;
const expr = try self.expression(false);
components = self.ast.nodes.items(.components); // ptr might have been invalidated
components[dot_node].Dot.value_or_call_or_enum = .{
.Value = try self.expression(false),
.Value = expr,
};
} else if (try self.match(.LeftParen)) {
// `call` will look to the parent node for the function definition
Expand Down
14 changes: 11 additions & 3 deletions src/lib/buzz_http.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub export fn HttpClientDeinit(ctx: *api.NativeCtx) c_int {

pub export fn HttpClientSend(ctx: *api.NativeCtx) c_int {
const userdata = ctx.vm.bz_peek(3).bz_valueToUserData();
const client = @as(*http.Client, @ptrCast(@alignCast(@as(*anyopaque, @ptrFromInt(userdata)))));
const client: *http.Client = @ptrCast(@alignCast(@as(*anyopaque, @ptrFromInt(userdata))));

var len: usize = 0;
const method_str = api.ObjEnumInstance.bz_getEnumCaseValue(ctx.vm.bz_peek(2)).bz_valueToString(&len);
Expand All @@ -55,8 +55,16 @@ pub export fn HttpClientSend(ctx: *api.NativeCtx) c_int {
const header_values = ctx.vm.bz_peek(0);
var headers = std.ArrayList(http.Header).init(api.VM.allocator);
var next_header_key = api.Value.Null;
var next_header_value = api.ObjMap.bz_mapNext(ctx.vm, header_values, &next_header_key);
while (next_header_key.val != api.Value.Null.val) : (next_header_value = api.ObjMap.bz_mapNext(ctx.vm, header_values, &next_header_key)) {
var next_header_value = api.ObjMap.bz_mapNext(
ctx.vm,
header_values,
&next_header_key,
);
while (next_header_key.val != api.Value.Null.val) : (next_header_value = api.ObjMap.bz_mapNext(
ctx.vm,
header_values,
&next_header_key,
)) {
var key_len: usize = 0;
const key = next_header_key.bz_valueToString(&key_len);
var value_len: usize = 0;
Expand Down
4 changes: 3 additions & 1 deletion src/lib/http.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export object Request {

fun wait() > Response !> HttpError, errors.InvalidArgumentError, HttpParseError {
if (this.collected) {
return error.RequestCollected;
throw HttpError.RequestCollected;
}

if (this.response != null) {
Expand Down Expand Up @@ -255,6 +255,8 @@ export object Request {
return;
}

this.collected = true;

if (this.request -> request) {
HttpRequestDeinit(request);
}
Expand Down

0 comments on commit c69bd5a

Please sign in to comment.