Accessing libfantom.so from Python (pyfantom) in Linux
Posted: 26 Sep 2012, 08:01
Hi John,
I've remember your interest in pyfantom for Linux, I've updated pyfantom to be able to run on Linux and Windows, though it has not been tested at all.
http://pyfantom.ni.fr.eu.org/
I've compiled libfantom.so and related utilities with debugging enabled on 64-bit Fedora 17 from BricxCC SVN Rev. 623. spirittest can access the NXT correctly.
However, when I tried using pyfantom to access the libfantom.so library using the Python ctypes interface, it is crashing badly.
It crashes when trying to access a global variable fNXTViaUSB. I'm not sure if this is due to any differences between Pascal generated libraries and C generated libraries or not. Is there anyone have experience with multi-language object code who can comment on this issue?
I've remember your interest in pyfantom for Linux, I've updated pyfantom to be able to run on Linux and Windows, though it has not been tested at all.
http://pyfantom.ni.fr.eu.org/
I've compiled libfantom.so and related utilities with debugging enabled on 64-bit Fedora 17 from BricxCC SVN Rev. 623. spirittest can access the NXT correctly.
Code: Select all
$ spirittest -listbricks
0016531A1E5D=USB0::0X0694::0X0002::0016531A1E5D::RAW
Code: Select all
$ gdb python pyfantom.py
GNU gdb (GDB) Fedora (7.4.50.20120120-50.fc17)
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/bin/python...(no debugging symbols found)...done.
"/home/rpmbuilder/rpmbuild/BUILD/pyfantom/pyfantom.py" is not a core dump: File format not recognized
Missing separate debuginfos, use: debuginfo-install python-2.7.3-7.2.fc17.x86_64
(gdb) run pyfantom.py
Starting program: /usr/bin/python pyfantom.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Detaching after fork from child process 1667.
Running on Linux Platform
Detaching after fork from child process 1669.
Detaching after fork from child process 1671.
Detaching after fork from child process 1675.
Detaching after fork from child process 1677.
Found Fantom Library ( libfantom.so )
Load Library Done
Retrieving list of NXT objects
warning: Range for type <error type> has invalid bounds 0..-121
Program received signal SIGSEGV, Segmentation fault.
GETNXT (this=0xf7fe4160, STATUS=8294160) at bricktools/fantomfpc.pas:3283
3283 if fNXTViaUSB then
(gdb) bt
#0 GETNXT (this=0xf7fe4160, STATUS=8294160) at bricktools/fantomfpc.pas:3283
#1 0x00007fffefb8d9e6 in NFANTOM100_INXTITERATOR_GETNXT (
NXTITERHANDLE=4160635232, STATUS=0) at bricktools/fantomfpc.pas:838
#2 0x00000038f9e05e90 in ffi_call_unix64 () from /lib64/libffi.so.5
#3 0x00000038f9e058a0 in ffi_call () from /lib64/libffi.so.5
#4 0x00007ffff18a9bd0 in _ctypes_callproc ()
from /usr/lib64/python2.7/lib-dynload/_ctypes.so
#5 0x00007ffff18a33dd in ?? ()
from /usr/lib64/python2.7/lib-dynload/_ctypes.so
#6 0x000000390da49a7e in PyObject_Call () from /lib64/libpython2.7.so.1.0
#7 0x000000390dad93e3 in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0
#8 0x000000390dadcd51 in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0
#9 0x000000390dadcd51 in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0
#10 0x000000390daddb1f in PyEval_EvalCodeEx () from /lib64/libpython2.7.so.1.0
#11 0x000000390daddbf2 in PyEval_EvalCode () from /lib64/libpython2.7.so.1.0
#12 0x000000390daf6b9a in ?? () from /lib64/libpython2.7.so.1.0
#13 0x000000390daf7992 in PyRun_FileExFlags () from /lib64/libpython2.7.so.1.0
#14 0x000000390daf83ab in PyRun_SimpleFileExFlags ()
from /lib64/libpython2.7.so.1.0
#15 0x000000390db09882 in Py_Main () from /lib64/libpython2.7.so.1.0
#16 0x00000038f7621735 in __libc_start_main () from /lib64/libc.so.6
#17 0x00000000004006f1 in _start ()
(gdb) list
3278 function TNxtIterator.getNXT(var status: integer): TNxt;
3279 begin
3280 Result := nil;
3281 if status < kStatusNoError then Exit;
3282 Result := TNxt.Create;
3283 if fNXTViaUSB then
3284 begin
3285 Result.fPort := GetUSBResString(fDev, fDevHandle);
3286 Result.fCheckver := False;
3287 Result.fDev := fDev;
(gdb) print Result
$1 = (^TNXT = class ) 0x7ffff7ff4180
(gdb) print fNXTViaUSB
Cannot access memory at address 0xf7fe418c
(gdb)