I’d like to map an int value pbs_errno declared as a global in the library libtorque.so using ctypes.
Currently I can load the library like so:
from ctypes import *
libtorque = CDLL("libtorque.so")
and have successfully mapped a bunch of the functions. However, for error checking purposes many of them set the pbs_errno variable so I need access to that as well. However if I try to access it I get:
>>> pytorque.libtorque.pbs_errno <_FuncPtr object at 0x9fc690>
Of course, it’s not a function pointer and attempting to call it results in a seg fault.
It’s declared as int pbs_errno; in the main header and extern int pbs_errno; in the API header files.
Objdump shows the symbol as:
00000000001294f8 g DO .bss 0000000000000004 Base pbs_errno
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
There’s a section in the ctypes docs about accessing values exported in dlls:
http://docs.python.org/library/ctypes.html#accessing-values-exported-from-dlls
e.g.
def pbs_errno():
return c_int.in_dll(libtorque, "pbs_errno")
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0