-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Conversation
@@ -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)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
As per https://curl.se/libcurl/c/CURLOPT_CAINFO_BLOB.html
For some reason this was working completely fine when I ran on macOS, but then I tried running the same thing on linux and would always get return code 43 (bad arg).