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

fix terrible type converting, close #342 #343

Merged
merged 5 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions curl_cffi/curl.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ def setopt(self, option: CurlOpt, value: Any) -> int:
0: "int*",
10000: "char*",
20000: "void*",
30000: "int*", # offset type
30000: "int64_t*", # offset type
}
# print("option", option, "value", value)

# Convert value
value_type = input_option.get(int(option / 10000) * 10000)
if value_type == "int*":
c_value = ffi.new("int*", value)
if value_type == "int*" or value_type == "int64_t*":
c_value = ffi.new(value_type, value)
elif option == CurlOpt.WRITEDATA:
c_value = ffi.new_handle(value)
self._write_handle = c_value
Expand Down
4 changes: 4 additions & 0 deletions ffi/shim.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "shim.h"

#define INTEGER_OPTION_MAX 10000
#define POINTER_OPTION_MAX 30000
qishipai marked this conversation as resolved.
Show resolved Hide resolved

int _curl_easy_setopt(void* curl, int option, void* parameter) {
// printf("****** hijack test begins: \n");
Expand All @@ -12,5 +13,8 @@ int _curl_easy_setopt(void* curl, int option, void* parameter) {
if (option < INTEGER_OPTION_MAX) {
return (int)curl_easy_setopt(curl, (CURLoption)option, *(int*)parameter);
}
if (option >= POINTER_OPTION_MAX) {
qishipai marked this conversation as resolved.
Show resolved Hide resolved
return (int)curl_easy_setopt(curl, (CURLoption)option, *(curl_off_t*)parameter);
}
return (int)curl_easy_setopt(curl, (CURLoption)option, parameter);
}
Loading