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

update signature for hash_foreach value #17

Merged
merged 4 commits into from
Sep 13, 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
17 changes: 14 additions & 3 deletions sdk/ext/ovirtsdk4c/ov_http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ limitations under the License.
#include "ov_http_response.h"
#include "ov_http_transfer.h"

/* thread.c (export) */
extern int ruby_thread_has_gvl_p(void);

/* Class: */
VALUE ov_http_client_class;

Expand Down Expand Up @@ -490,12 +493,20 @@ static int ov_http_client_debug_function(CURL* handle, curl_infotype type, char*
/* Get the pointer to the transfer: */
ov_http_transfer_ptr(transfer, transfer_ptr);

/* Execute the debug code with the global interpreter lock acquired, as it needs to call Ruby methods: */
/* The global interpreter lock may be acquired or not, so we need to check and either call the task directly
or else call it after acquiring the lock. Note that the `ruby_thread_has_gvl_p` function that we use to
check if the GVL is acquired is marked as experimental, and not defined in `thread.h`, so it may be
removed at any time, but I didn't find any other way to check if the GVL is acquired. */
context.client = transfer_ptr->client;
context.type = type;
context.data = data;
context.size = size;
rb_thread_call_with_gvl(ov_http_client_debug_task, &context);
if (ruby_thread_has_gvl_p()) {
ov_http_client_debug_task(&context);
}
else {
rb_thread_call_with_gvl(ov_http_client_debug_task, &context);
}
return 0;
}

Expand Down Expand Up @@ -998,7 +1009,7 @@ static void ov_http_client_prepare_handle(ov_http_client_object* client_ptr, ov_

/* Set the headers: */
if (!NIL_P(request_ptr->headers)) {
rb_hash_foreach(request_ptr->headers, ov_http_client_add_header, (VALUE) headers);
rb_hash_foreach(request_ptr->headers, (int (*)(VALUE, VALUE, VALUE)) ov_http_client_add_header, (VALUE) headers);
}
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, *headers);

Expand Down