-
-
Notifications
You must be signed in to change notification settings - Fork 664
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
vendor/curl: Add comprehensive (not-so-minimal) libcurl bindings #4679
Conversation
Extract common HTTP method logic into do_method() and do_method_with() to reduce code duplication in request handling. This consolidates error handling and memory management while maintaining the existing public API.
Add post_string() wrapper that completes the set of string response handlers, providing consistent string handling across request types.
Simplify "Optional request configuration" documentation to match format used across other parameter descriptions.
- Ubuntu/Debian: `sudo apt install libcurl4-dev` | ||
- Fedora: `sudo dnf install libcurl-devel` | ||
- macOS: `brew install curl` | ||
- Windows: Download from [curl](https://curl.se/windows/) |
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.
For vendor, things should "just work", especially on Windows. So why does Windows not bundle with a .lib
already?
CURL :: distinct rawptr | ||
|
||
// CURL_GLOBAL_ALL combines all initialization flags. | ||
CURL_GLOBAL_ALL: i64 = 3 |
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.
Maybe remove the CURL_
prefix?
CURL_GLOBAL_ALL: i64 = 3 | ||
|
||
// CURLOPT represents options for a transfer. | ||
CURLOPT :: enum i32 { |
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.
Maybe remove the CURL
prefix?
// Error represents libcurl error codes. | ||
// | ||
// This maps directly to CURLcode error values from curl.h. | ||
Error :: enum { |
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.
Is this the correct size? Is this meant to be enum c.int
?
} | ||
|
||
// CURLINFO represents information retrieval options. | ||
CURLINFO :: enum i32 { |
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.
Is this meant to be c.int
?
CURL_GLOBAL_ALL: i64 = 3 | ||
|
||
// CURLOPT represents options for a transfer. | ||
CURLOPT :: enum i32 { |
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.
Is this meant to be c.int
?
|
||
// CURLOPT represents options for a transfer. | ||
CURLOPT :: enum i32 { | ||
// Basic options |
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.
Please adhere to the Odin conventions of using tabs for indentation.
// - userdata: User provided data pointer | ||
// | ||
// Returns: Number of bytes handled. | ||
Write_Callback :: #type proc "c" (data: rawptr, size: c.size_t, nmemb: c.size_t, userdata: rawptr) -> c.size_t |
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.
Please try to keep the original naming conventions and DO NOT change it to Odin's core
convention.
// Error represents libcurl error codes. | ||
// | ||
// This maps directly to CURLcode error values from curl.h. | ||
Error :: enum { |
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 know this wraps the other calls, but why not keep it the same? e.g. enum c.int
?
if ctx == nil do return false | ||
|
||
result: i32 | ||
when T == string { |
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.
This will fail with distinct
types.
Honestly, the PR has loads of styling issues and is not "minimal" in any sense. The general wrappers are not that great because they rely too much on parapoly and get numerous things wrong in the process too (the first thing being not understanding |
I am closing this PR because it would be quicker for me to write my own bindings than explain everything wrong with it and then hope they get fixed correctly. |
Thank you for the feedback. You're right - while the binding started minimal, it grew more complex As I need these bindings for my active projects, I'll continue maintenance here where I'll work on addressing these points. |
Add
minimalcomprehensive libcurl bindings providing a simple, memory-safe high-level API to interact with libcurl in Odin.Key features:
The implementation is based on curl.h version 8.11.1 and provides both low-level libcurl bindings and a high-level request API that follows Odin idioms.
Usage
Import the library:
Initialize before use:
Simple GET request:
Simple POST request:
GET with JSON parsing:
POST with JSON:
Examples
The examples/ directory contains:
basic.odin
typed.odin
ssl.odin
allocator.odin
Tracking_Allocator
All examples run successfully and have been tested with valgrind to confirm no memory leaks.
I hope this library is suitable for inclusion in the vendor collection. If not, maintenance will continue here. All suggestions for improvement are welcome, whether they highlight blockers or provide general recommendations.
Thank you for your consideration! :)