-
Notifications
You must be signed in to change notification settings - Fork 1.3k
adafruit_bus_device-in-core crashes with non-busio objects #3856
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
Comments
@gamblor21 We should check the type of the incoming object and raise an error if it won't work. That will prevent the crash. In the longer term and under a compile flag, we can have the C code either recognize bitbangio or use the Python mechanics for the call. |
I think I know how to do that (or where to look to figure it out). I'll try to understand how the other bus-like objects work but if I catch someone on discord one day probably could be explained quickly if time works for that. |
Feel free to mention me when you have time. We can also coordinate a time too. |
To reject things with the wrong type, you can simply check that the type is the desired one, similar to this code in canio:
To make it work with busio and bitbangio (core implementation) you can just check the object's type and make a decision, similar to this code in displayio:
To work with the pure python implementation adafruit_bitbangio, you need to arrange to call back into Python using mp_load_method+mp_call_method_n_kw, similar to this example from _pixelbuf:
|
could we do a duck-typing thing where we just look in the type's dictionary for the operations we want? |
I understand the 3 methods you suggested @jepler. The first one is probably pretty quick to do, the second I'd have to figure out how to test bitbangio (core). Would the third with pure python fix all the problems? Would that result in a slow down for having this all in the core (the original point?). I understand in the theory of what you're suggestion @dhalbert but I'm thinking that will take me a bit longer to figure out. I should be around on discord for the next bit if someone wants to discuss it. |
The third suggestion is how duck typing is implemented in the core (to the best of my knowledge)—in that case, it calls the |
I was able to play and get duck typing working. But see two possibilities
As I can see it the first option will be a smaller code base, but may be slower with known bus types. The second option will be a larger addition size wise to the core code but may be faster for the known bus types. |
My impulse would be to do the simpler thing first, which is doing the duck typing approach ONLY. If it's measurably slower in a reasonable real world situation, then consider adding back the direct call method for busio object types only. |
1 works for me too. It'll still be faster than the python impl I expect. |
Fixed in #3936 |
Uh oh!
There was an error while loading. Please reload this page.
The out-of-core
adafruit_bus_device
can handle any kind of bus-like object (for instance,bitbangio.I2C
andadafruit_bitbangio.I2C
). The new in-coreadafruit_bus_device
can only handlebusio.I2C
, and crashes hard on other object types.We could consider temporarily disabling the built-in module until this problem can be resolved.
The text was updated successfully, but these errors were encountered: