diff options
author | Chris Dickens <christopher.a.dickens@gmail.com> | 2020-02-26 15:55:10 -0800 |
---|---|---|
committer | Chris Dickens <christopher.a.dickens@gmail.com> | 2020-02-26 15:55:10 -0800 |
commit | 281ca64c8ac9b9ee6ec72f2b776016aa98e964ba (patch) | |
tree | 896ad067c8c31f24adbf47a00470efe49e0f76cd /libusb/os/windows_winusb.h | |
parent | 0e8f3997bd7b11390e9ec7b7de7eb31f403c1c83 (diff) | |
download | libusb-281ca64c8ac9b9ee6ec72f2b776016aa98e964ba.tar.gz |
core: Introduce accessor functions for structure private data
The backend private data for the internal library structures has been
accessed through a zero-length os_priv array of type unsigned char.
This approach had two particular disadvantages:
1) A special attribute was needed on the 'os_priv' member to ensure
that the field was properly aligned to a natural pointer alignment.
The support needed for this is not available in every compiler.
2) Each access to the private data areas required an explicit cast
from unsigned char to the type required by the backend.
This change reworks the way the private data is accessed by the
backends. New accessor functions return the private data as a void
pointer type, removing the need for an explicit cast (except for Haiku,
which is C++). The special alignment attribute trickery is also replaced
by simple pointer arithmetic.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Diffstat (limited to 'libusb/os/windows_winusb.h')
-rw-r--r-- | libusb/os/windows_winusb.h | 43 |
1 files changed, 16 insertions, 27 deletions
diff --git a/libusb/os/windows_winusb.h b/libusb/os/windows_winusb.h index 74d0e08..9f6eb9b 100644 --- a/libusb/os/windows_winusb.h +++ b/libusb/os/windows_winusb.h @@ -199,54 +199,43 @@ struct hid_device_priv { uint8_t string_index[3]; // man, prod, ser }; -static inline struct winusb_device_priv *_device_priv(struct libusb_device *dev) -{ - return (struct winusb_device_priv *)dev->os_priv; -} - static inline struct winusb_device_priv *winusb_device_priv_init(struct libusb_device *dev) { - struct winusb_device_priv *p = _device_priv(dev); + struct winusb_device_priv *priv = usbi_get_device_priv(dev); int i; - p->apib = &usb_api_backend[USB_API_UNSUPPORTED]; - p->sub_api = SUB_API_NOTSET; + priv->apib = &usb_api_backend[USB_API_UNSUPPORTED]; + priv->sub_api = SUB_API_NOTSET; for (i = 0; i < USB_MAXINTERFACES; i++) { - p->usb_interface[i].apib = &usb_api_backend[USB_API_UNSUPPORTED]; - p->usb_interface[i].sub_api = SUB_API_NOTSET; + priv->usb_interface[i].apib = &usb_api_backend[USB_API_UNSUPPORTED]; + priv->usb_interface[i].sub_api = SUB_API_NOTSET; } - return p; + return priv; } static inline void winusb_device_priv_release(struct libusb_device *dev) { - struct winusb_device_priv *p = _device_priv(dev); + struct winusb_device_priv *priv = usbi_get_device_priv(dev); int i; - free(p->dev_id); - free(p->path); - if ((dev->num_configurations > 0) && (p->config_descriptor != NULL)) { + free(priv->dev_id); + free(priv->path); + if ((dev->num_configurations > 0) && (priv->config_descriptor != NULL)) { for (i = 0; i < dev->num_configurations; i++) { - if (p->config_descriptor[i] == NULL) + if (priv->config_descriptor[i] == NULL) continue; - free((UCHAR *)p->config_descriptor[i] - USB_DESCRIPTOR_REQUEST_SIZE); + free((UCHAR *)priv->config_descriptor[i] - USB_DESCRIPTOR_REQUEST_SIZE); } } - free(p->config_descriptor); - free(p->hid); + free(priv->config_descriptor); + free(priv->hid); for (i = 0; i < USB_MAXINTERFACES; i++) { - free(p->usb_interface[i].path); - free(p->usb_interface[i].endpoint); + free(priv->usb_interface[i].path); + free(priv->usb_interface[i].endpoint); } } -static inline struct winusb_device_handle_priv *_device_handle_priv( - struct libusb_device_handle *handle) -{ - return (struct winusb_device_handle_priv *)handle->os_priv; -} - // used to match a device driver (including filter drivers) against a supported API struct driver_lookup { char list[MAX_KEY_LENGTH + 1]; // REG_MULTI_SZ list of services (driver) names |