libusbx/libusbx — pull request #128 by swestrup (2013-08-08 21:48:25+00:00)
Title: Make libusbx accept an optional policy structure that specifies how logging and/or memory allocation work.

This is my 'policy' fork of libusbx (originally it was a fork of libusb). I had not originally planned to submit this code back to libusb, but as the pace of development work on libusbx is so much faster than on libusb, I'm finding maintaining a fork to be major pain, so I've done a bunch of code clean up, and am submitting the result.

This fork was created for my work with drivers that need USB support. These drivers often need custom memory allocators and/or custom logging systems, and so I added an extra 'policy' option to libusb_init and called the result libusb_init_full. A policy structure is intended to be a simple interface to specify alternative logging and/or memory allocation methods on a per-context basis. It could easily be expanded to provide policies for other facilities, if needed.

My original hope had been that the introduction of libusb_init_full would be the only major API change, but it turns out there are numerous places where convenient structure-allocation functions are provided, and they all had to be modified so they could know which allocator they were using.

I tried to ensure that my code would compile under Android as well as Linux, but I have no access to a Windows development environment, and so decided not to touch Windows-specific files. As a result this branch definitely breaks Windows support.

I don't actually expect this branch to be accepted without major work, as I had to make a number of design decisions while working on this that are not necessarily going to be the same as those the main developers would make. However, I am willing to put in the effort to be able to merge this fork with back with the original.

I look forward to your feedback.