Skip to content

Commit f6c7d80

Browse files
committed
More gc preserves
1 parent 05a895a commit f6c7d80

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

‎src/client.jl‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ function make_input_stream(ctx)
1212
input_stream = aws_input_stream_new_from_cursor(ctx.client.allocator, FieldRef(ctx, :body_byte_cursor))
1313
elseif ctx.request.body isa AbstractVector{UInt8}
1414
ctx.request_body = ctx.request.body
15-
ctx.body_byte_cursor = aws_byte_cursor(sizeof(ctx.request.body), pointer(ctx.request.body))
16-
input_stream = aws_input_stream_new_from_cursor(ctx.client.allocator, FieldRef(ctx, :body_byte_cursor))
15+
GC.@preserve ctx.request_body begin
16+
ctx.body_byte_cursor = aws_byte_cursor(sizeof(ctx.request_body), pointer(ctx.request_body))
17+
input_stream = aws_input_stream_new_from_cursor(ctx.client.allocator, FieldRef(ctx, :body_byte_cursor))
18+
end
1719
elseif ctx.request.body isa Union{AbstractDict, NamedTuple}
1820
# add application/x-www-form-urlencoded content-type header if not already present
1921
if !hasheader(headers, "content-type")
@@ -33,17 +35,21 @@ function make_input_stream(ctx)
3335
end
3436
# we set the request.body to the Form bytes in order to gc-preserve them
3537
ctx.request_body = read(ctx.request.body)
36-
ctx.body_byte_cursor = aws_byte_cursor(sizeof(ctx.request_body), pointer(ctx.request_body))
37-
input_stream = aws_input_stream_new_from_cursor(ctx.client.allocator, FieldRef(ctx, :body_byte_cursor))
38+
GC.@preserve ctx.request_body begin
39+
ctx.body_byte_cursor = aws_byte_cursor(sizeof(ctx.request_body), pointer(ctx.request_body))
40+
input_stream = aws_input_stream_new_from_cursor(ctx.client.allocator, FieldRef(ctx, :body_byte_cursor))
41+
end
3842
elseif ctx.request.body isa IO
3943
# we set the request.body to the IO bytes in order to gc-preserve them
4044
bytes = readavailable(ctx.request.body)
4145
while !eof(ctx.request.body)
4246
append!(bytes, readavailable(ctx.request.body))
4347
end
4448
ctx.request_body = bytes
45-
ctx.body_byte_cursor = aws_byte_cursor(sizeof(ctx.request_body), pointer(ctx.request_body))
46-
input_stream = aws_input_stream_new_from_cursor(ctx.client.allocator, FieldRef(ctx, :body_byte_cursor))
49+
GC.@preserve ctx.request_body begin
50+
ctx.body_byte_cursor = aws_byte_cursor(sizeof(ctx.request_body), pointer(ctx.request_body))
51+
input_stream = aws_input_stream_new_from_cursor(ctx.client.allocator, FieldRef(ctx, :body_byte_cursor))
52+
end
4753
else
4854
throw(ArgumentError("request body must be a string, vector of UInt8, or IO"))
4955
end
@@ -155,7 +161,7 @@ function c_on_setup(conn, error_code, ctx_ptr)
155161
ctx.request_options = Ref(aws_http_make_request_options(
156162
1,
157163
request,
158-
pointer_from_objref(ctx),
164+
ctx_ptr,
159165
on_response_headers[],
160166
on_response_header_block_done[],
161167
on_response_body[],

0 commit comments

Comments
 (0)