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

Pass address of ca blob to setopt #19

Merged
merged 1 commit into from
Oct 25, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/Easy.zig
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ pub fn setCommonOpts(self: Self) !void {
.len = bundle.items.len,
.flags = c.CURL_BLOB_NOCOPY,
};
try checkCode(c.curl_easy_setopt(self.handle, c.CURLOPT_CAINFO_BLOB, blob));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this is not the right solution.

If we pass a pointer here, after setCommonOpts blob will be freed, and the pointer will be a dangling pointer?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give more context how we can reproduce your issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry didn't give more details, was a bit late here. I'll make a small reproducible example this weekend.

Curl internally copies the struct we pass to it so it doesn't dangle https://github.com/curl/curl/blob/b8c12634fce509673f8eda657e9a2222890707c1/lib/setopt.c#L81

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying, it seems the examples used in docs also pass in pointer.

So it's zig to convert struct to pointer automatically before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked what the signature of the translated C code is but the type must coalesce to both a pointer and struct.

My guess is some sort of anytype (I'm still pretty new to zig so should verify this)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the CI pass, I will merge it now.

You can update here when you figure out how it works before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as an update I haven't managed to figure out why this works on macOS but not on my raspberry pi, and won't look into it any further. The curl_easy_setopt is variadic. Somehow on macOS it's happy to take our blob struct and pass the pointer to curl whereas when compiled for linux it's not.

Copy link
Owner

@jiacai2050 jiacai2050 Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for update.

pub extern fn curl_easy_setopt(curl: ?*CURL, option: CURLoption, ...) CURLcode;

For anyone interested, this is what zig translate-c output.

try checkCode(c.curl_easy_setopt(self.handle, c.CURLOPT_CAINFO_BLOB, &blob));
}
try checkCode(c.curl_easy_setopt(self.handle, c.CURLOPT_TIMEOUT_MS, self.timeout_ms));
try checkCode(c.curl_easy_setopt(self.handle, c.CURLOPT_USERAGENT, self.user_agent.ptr));
Expand Down
Loading