Ticket #85 (new enhancement)
Opened 2 years ago
Last modified 6 weeks ago
Use size_t instead of int in transfer functions
| Reported by: | www.google.com/accounts/o8/id?id=aitoawlbfa_iwnmgtqit6eck5vjmkejlybqinoe | Owned by: | |
|---|---|---|---|
| Milestone: | 2.0 | Component: | libusb-1.1 |
| Keywords: | size_t | Cc: | |
| Blocked By: | Blocks: |
Description
The POSIX read and write functions let you specify the number of bytes to transfer as a size_t. These functions return a ssize_t indicating how much bytes were read or written. (The signed type is needed to allow negative error codes.)
As explained in the mailinglist thread, I would like to propose that the libusb transfer functions also use these size_t types instead of ints. Concretely I propose:
ssize_t libusb_control_transfer (...,size_t wLength,...)
int libusb_bulk_transfer (...,size_t length, size_t * transferred,...)
int libusb_interrupt_transfer (...,size_t length, size_t * transferred,...)
Note that the libusb_get_device_list function already returns a ssize_t to indicate the number of devices in the list or an error code.
I'm not familiar enough with the asynchronous API but I suppose that it can also use size_t types instead of ints.
Change History
comment:1 Changed 2 years ago by segher
comment:2 Changed 2 years ago by stuge
libusb-1.1 is tentatively intended to change ABI and API, so this is on the right component. Anyway, it's all in the future.
comment:3 Changed 2 years ago by rogueresearch
I would like to see this change too.
With the Mac OS X ABI, 'int' is always 32 bit, but 'size_t' is 32 bit for 32 bit apps and 64 bit for 64 bit apps. As a result, libusb is truncating 64 bit values to 32, which at best causes compiler warnings, and at worst results in actual truncation and incorrect behaviour.
comment:4 Changed 6 weeks ago by hjelmn
- Milestone set to 2.0
I still don't think it's worth making an ABI change for this, not until
a major version change anyway (that would be 2.0).
Is there ever a situation in practice where "int" isn't big enough?