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

Conversation

shnupta
Copy link
Contributor

@shnupta shnupta commented Oct 24, 2024

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).

@@ -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.

Copy link
Owner

@jiacai2050 jiacai2050 left a comment

Choose a reason for hiding this comment

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

LGTM

@jiacai2050 jiacai2050 merged commit 3a590c7 into jiacai2050:main Oct 25, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants