Skip to content
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

OverflowError: Python int too large to convert to C long #1

Closed
pmermoz opened this issue Jun 25, 2013 · 5 comments
Closed

OverflowError: Python int too large to convert to C long #1

pmermoz opened this issue Jun 25, 2013 · 5 comments

Comments

@pmermoz
Copy link

pmermoz commented Jun 25, 2013

I get this exception (v1.1 and also in your last Jun 25 checkin):


Traceback (most recent call last):
File "/home/pi/sprinklermory/scheduler.py", line 90, in run
if a_rain_sensor.rain_detected and a_rain_sensor.watering_percent > watering_percent_from_rain_sensor:
File "/home/pi/sprinklermory/rainsensor.py", line 135, in rain_detected
rain_detected = ioserver.get_input_value(self.input_index)
File "/home/pi/sprinklermory/ioserver.py", line 123, in get_input_value
state = _pfd.input_pins[inputIndex].value;
File "/usr/local/lib/python3.2/dist-packages/pifacecommon/core.py", line 190, in value
return 1 ^ super().value
File "/usr/local/lib/python3.2/dist-packages/pifacecommon/core.py", line 170, in value
self.board_num)
File "/usr/local/lib/python3.2/dist-packages/pifacecommon/core.py", line 319, in read_bit
value = read(address, board_num)
File "/usr/local/lib/python3.2/dist-packages/pifacecommon/core.py", line 368, in read
op, addr, data = spisend((devopcode, address, 0)) # data byte is not used
File "/usr/local/lib/python3.2/dist-packages/pifacecommon/core.py", line 411, in spisend
ioctl(spidev_fd, iomsg, ctypes.addressof(transfer))

OverflowError: Python int too large to convert to C long

It's pretty random, but get it after a while.

The exception seem to appear when ctypes.addressof(transfer) return a very big number that fit only in an unsigned int. I believe ctypes.addressof is not necessary here but I'm not familiar with ctypes yet.
I get a fix that seem to works:

diff --git a/pifacecommon/core.py b/pifacecommon/core.py
index c1d5577..9584f0f 100644
--- a/pifacecommon/core.py
+++ b/pifacecommon/core.py
@@ -408,7 +408,7 @@ def spisend(bytes_to_send):

  # send the spi command (with a little help from asm-generic
 iomsg = _IOW(SPI_IOC_MAGIC, 0, ctypes.c_char * ctypes.sizeof(transfer))
  • ioctl(spidev_fd, iomsg, ctypes.addressof(transfer))
  • ioctl(spidev_fd, iomsg, transfer)
    return ctypes.string_at(rbuffer, ctypes.sizeof(rbuffer))
@tompreston
Copy link
Member

Could you run with that fix for a while and see if it errors again? I'll try and get to the bottom of this! Thanks.

@tompreston
Copy link
Member

Ok, I've merged a fix into the testing branch. It's not a direct fix but I've implemented the SPI transfer more closely to how you're supposed to do it in C. Hopefully, by letting the the include file do the heavy lifting the bug should disappear! Let me know how you get on. I'll merge it into master later today, if there aren't any issues.

@pmermoz
Copy link
Author

pmermoz commented Jun 26, 2013

You have a typo in linux_spi_spidev.py.
line 3
from asm_generic_ioctl import _IOR, _IOW, _IOC_SIZEBITS
is missing a dot before "asm_generic_ioctl", like:
from .asm_generic_ioctl import _IOR, _IOW, _IOC_SIZEBITS

The problem was detected at the install of pifacedigitalio (see bellow). But because pifacedigitalio downloaded locally the master branch of pifacecommon, the install finished, but without the fix...
I fixed the typo and going to test the fix.

cd pifacedigitalio
sudo ./install.sh
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.2/dist-packages/pifacecommon/init.py", line 23, in
from .core import (
File "/usr/local/lib/python3.2/dist-packages/pifacecommon/core.py", line 25, in
from .linux_spi_spidev import spi_ioc_transfer, SPI_IOC_MESSAGE
File "/usr/local/lib/python3.2/dist-packages/pifacecommon/linux_spi_spidev.py", line 3, in
from asm_generic_ioctl import _IOR, _IOW, _IOC_SIZEBITS
ImportError: No module named asm_generic_ioctl
Downloading pifacecommon...
Cloning into 'pifacecommon'...
remote: Counting objects: 172, done.
remote: Compressing objects: 100% (87/87), done.
remote: Total 172 (delta 97), reused 159 (delta 84)
Receiving objects: 100% (172/172), 48.68 KiB, done.
Resolving deltas: 100% (97/97), done.
The spi rules file already exists.
Exiting...
The gpio rules file already exists.
Exiting...
Installing pifacecommon...
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/pifacecommon
copying pifacecommon/init.py -> build/lib/pifacecommon
copying pifacecommon/asm_generic_ioctl.py -> build/lib/pifacecommon
copying pifacecommon/interrupts.py -> build/lib/pifacecommon
copying pifacecommon/core.py -> build/lib/pifacecommon
running install_lib
copying build/lib/pifacecommon/init.py -> /usr/local/lib/python3.2/dist-packages/pifacecommon
copying build/lib/pifacecommon/asm_generic_ioctl.py -> /usr/local/lib/python3.2/dist-packages/pifacecommon
copying build/lib/pifacecommon/interrupts.py -> /usr/local/lib/python3.2/dist-packages/pifacecommon
copying build/lib/pifacecommon/core.py -> /usr/local/lib/python3.2/dist-packages/pifacecommon
byte-compiling /usr/local/lib/python3.2/dist-packages/pifacecommon/init.py to init.cpython-32.pyc
byte-compiling /usr/local/lib/python3.2/dist-packages/pifacecommon/asm_generic_ioctl.py to asm_generic_ioctl.cpython-32.pyc
byte-compiling /usr/local/lib/python3.2/dist-packages/pifacecommon/interrupts.py to interrupts.cpython-32.pyc
byte-compiling /usr/local/lib/python3.2/dist-packages/pifacecommon/core.py to core.cpython-32.pyc
running install_egg_info
Removing /usr/local/lib/python3.2/dist-packages/pifacecommon-1.1.egg-info
Writing /usr/local/lib/python3.2/dist-packages/pifacecommon-1.1.egg-info
Done!

@tompreston
Copy link
Member

Ah, I fixed that on my local copy but I haven't updated it. Everything seems to work for me but since I don't really know how to replicate the error your in a better position to test it. I'll upload my changes to the testing branch in merge it into master by the end of the week if all goes well.

@pmermoz
Copy link
Author

pmermoz commented Jun 27, 2013

I do not have error with the last fix.
Thanks

@pmermoz pmermoz closed this as completed Jun 27, 2013
tompreston pushed a commit that referenced this issue Apr 30, 2020
reflect changelog to current version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants