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
Add support for ssize_t #50978
Comments
ctypes currently has a datatype c_size_t which corresponds to size_t in |
Would you like to work on a patch? |
I can give it a shot if you give me a rough idea where I have to make |
Find where c_size_t is defined: in Lib/ctypes/init.py |
Ok, apparently the lines that define c_size_t are these: if sizeof(c_uint) == sizeof(c_void_p):
c_size_t = c_uint
elif sizeof(c_ulong) == sizeof(c_void_p):
c_size_t = c_ulong
elif sizeof(c_ulonglong) == sizeof(c_void_p):
c_size_t = c_ulonglong (side remark: wouldn't a simple c_size_t = c_void_p do exactly the same Unfortunately I have no real idea how to come up with something similar |
You don't want to do c_size_t = c_void_p because that will prevent type checking. We want c_size_t to be integers; setting it to c_void_p will accept other values. The lines that define c_size_t are doing a sizeof check to determine how many bits the CPU supports, and c_size_t should represent unsigned integers [1]. On a 16-bit machine: c_size_t = c_uint Now, ssize_t is like size_t, except that it is signed [2]. So if I am not mistaken, all we have to do is: if sizeof(c_uint) == sizeof(c_void_p):
c_size_t = c_uint
c_ssize_t = c_int
elif sizeof(c_ulong) == sizeof(c_void_p):
c_size_t = c_ulong
c_ssize_t = c_long
elif sizeof(c_ulonglong) == sizeof(c_void_p):
c_size_t = c_ulonglong
c_ssize_t = c_longlong Patch attached with documentation and unit test. [1] - http://www.gnu.org/software/libc/manual/html_node/Important-Data-Types.html |
committed in r78544. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: