-
Notifications
You must be signed in to change notification settings - Fork 98
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
Rewrite usbrelay_py with ctypes #97
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Paul Chan <[email protected]>
Paul, |
Please also note, there are some very recent changes to the libusbrelay.c and libusbrelay_py.c which bumped the library versions. |
Tested the PR locally. Worked fine with one module. Segfaults with 2.
It could be because of changes to libusbrelay made recently. |
Hi Darryl,
Paul: Sorry I mixed up the terms cffi with ctypes. The code in this PR is actually written with Python ctypes. Below page provide a quick introduction to ctypes and cffi.
Paul: I use usbrelay in a test environment running Ubuntu but the env. is actually not tied to a particular Ubuntu version or Python (minor) version. Without ctypes binding, we need to build one python package for one Python version - e.g. Python 3.5, Python 3.8 and Python 3.9 that is inconvenient. It would be better to have python-usbrelay from apt and usbrelay_py from PyPI directly installable. Use of ctypes simplifies the code and make usbrelay immediately available to any Python 2 or Python 3 versions provided that the prerequisite libffi is installed in the system (and ctypes supported in CPython and Pypy since Python 2.5).
Paul: See the next one about dependency.
Paul: Do you mean the installation dependency like prerequisite libffi ? BTW, I can start a new PR to avoid cffi in the branch name for clarity, if necessary. |
I only has one ucreatefun relay to test with. Can we build a debug usbrelay.so for test purposes ? like by returning some fixed HID return values for API/Python tests. |
I'll see if I can get one done today. |
Did a little debugging It's segfaulting on second iteration so I checked that the address pointer was incrementing correctly.
|
Found that the struct pack = 1 needs to be commented out so that it uses native alignment For the moment, wouldn't it be better to create a test library that just returns an array of values and prove you can iterate through the array? |
Signed-off-by: Paul Chan [email protected]