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

[BUG] Unsupported ctypes for getinfo to work #407

Open
ringus1 opened this issue Oct 8, 2024 · 3 comments
Open

[BUG] Unsupported ctypes for getinfo to work #407

ringus1 opened this issue Oct 8, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@ringus1
Copy link

ringus1 commented Oct 8, 2024

Describe the bug
Some CurlInfo constants can't be retrieved seemingly because types are not supported, such as curl_off_t.

Raw CURL command

> curl --compressed -so /dev/null http://www.whatsmyip.org/http-compression-test/ -w '%{size_download}'
256

Python attempt

> import curl_cffi

> curl = curl_cffi.Curl()
> curl.setopt(curl_cffi.CurlOpt.URL, "http://www.whatsmyip.org/http-compression-test/")
> curl.setopt(curl_cffi.CurlOpt.ACCEPT_ENCODING, 'gzip')
> curl.perform()

> curl.getinfo(curl_cffi.CurlInfo.SIZE_DOWNLOAD_T)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.12/site-packages/curl_cffi/curl.py", line 243, in getinfo
    c_value = ffi.new(ret_option[option & 0xF00000])
                      ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
KeyError: 6291456

Some more insight

> from curl_cffi._wrapper import ffi, lib
> ffi.getctype("long")
'long'
> ffi.getctype("char")
'char'
> ffi.getctype("curl_off_t")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ffi.error: undefined type name
curl_off_t

Expected behavior
CurlInfo options can be retrieved via Curl.getinfo

Versions

  • OS: linux x64
  • certifi==2024.8.30
  • cffi==1.17.1
  • curl_cffi==0.7.2
  • pycparser==2.22
  • typing_extensions==4.12.2
@ringus1 ringus1 added the bug Something isn't working label Oct 8, 2024
@ringus1 ringus1 changed the title [BUG] [BUG] Unsupported ctypes for getinfo to work Oct 8, 2024
@lexiforest
Copy link
Owner

To expose the curl_off_t type, we need to include typedefs from curl/system.h in ffi.cdef().

@lexiforest lexiforest added enhancement New feature or request and removed bug Something isn't working labels Oct 8, 2024
@usedev
Copy link
Contributor

usedev commented Oct 22, 2024

curl_off_t looks like a long

curl.getinfo(curl_cffi.CurlInfo.SIZE_DOWNLOAD_T)
ret_option = {
    0x100000: "char**",
    0x200000: "long*",
    0x300000: "double*",
    0x400000: "struct curl_slist **",
    0x500000: "long*",
    0x600000: "long*"
}
ret_cast_option = {
    0x100000: ffi.string,
    0x200000: int,
    0x300000: float,
    0x500000: int,
    0x600000: int,
}

@lexiforest
Copy link
Owner

I tried to add the typedef to cdef, but it does not work as documented, perhaps it's the more realistic way to do this.

curl_off_t looks like a long

curl.getinfo(curl_cffi.CurlInfo.SIZE_DOWNLOAD_T)
ret_option = {
    0x100000: "char**",
    0x200000: "long*",
    0x300000: "double*",
    0x400000: "struct curl_slist **",
    0x500000: "long*",
    0x600000: "long*"
}
ret_cast_option = {
    0x100000: ffi.string,
    0x200000: int,
    0x300000: float,
    0x500000: int,
    0x600000: int,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants