ctypes

How to run a Fortran script with ctypes?

How to run a Fortran script with ctypes? Question: First of all I have no experience coding with fortran. I am trying to run a fortran code with python ctypes. I used the command gfortran -shared -g -o test.so test.f90 to convert my test.f90 file (code below) to test.so. After reading C function called from …

Total answers: 1

How can I improve performance of this Fortran code interfacing with Python?

How can I improve performance of this Fortran code interfacing with Python? Question: I am studying the possibility to interface Fortran code to be used in Python. I know of f2py but, since I did not succeed in using it with external libraries (such as lapack), I reverted to use ctypes. I have everything working, …

Total answers: 1

Using memory sanitizer (asan) on C/C++ library loaded to python with ctypes

Using memory sanitizer (asan) on C/C++ library loaded to python with ctypes Question: I have C++ library compiled with AddressSanitizer(asan) using g++ and cmake: SET( AXULIARY_COMPILE_FLAGS "-g -Og -fsanitize=address -fno-omit-frame-pointer") this works very well when running stand-alone C/C++ executable program. But I’m unable to make it work when loaded as shared/dynamic library (.so) into python …

Total answers: 1

Python Invalid arguments using ctypes when calling SetProcessInformation

Python Invalid arguments using ctypes when calling SetProcessInformation Question: I’m trying to set a process in Eco QOS mode (windows specific, allows power saving for a process, see here) with the SetProcessInformation windows API function. My final goal will be to enable the eco QOS for all the process I launch with subprocess.popen() function that …

Total answers: 1

ctypes character pointers with same byte string points same location

ctypes character pointers with same byte string points same location Question: I am creating two ctypes character pointers with same byte string via: import ctypes as ct var1 = ct.c_char_p(b’.’*80) var2 = ct.c_char_p(b’.’*80) # how I check the values: api = ct.CDLL(‘api.dll’) api.function1(var1, var2) # values of the vars are changed after running the above …

Total answers: 2

How is that pandas is faster than pure C in the groupby operation?

How is that pandas is faster than pure C in the groupby operation? Question: I have an nparray of x,y pairs with shape (n,2), and knowing for certain that for each x there are multiple values of y , I wanted to calculate the average value of y for each unique x. It occurred to …

Total answers: 1

python ctypes memory read stops at first zero integer

python ctypes memory read stops at first zero integer Question: To all ctypes experts: I am running this code in Python to read 0x400 entries from memory. Unfortunately the returned list only contains ~20 entries. It seems to stop reading at the first entry with the value equal to 0. read_buffer = (ctypes.c_char * buffsize)() …

Total answers: 1

How to pass references of declared variables to C function in python using ctypes

How to pass references of declared variables to C function in python using ctypes Question: I would like to call a C function from python. This C function is void, thus the "return parameters" (data I want to change) are defined as pointers in the C function’s definition. The function in C looks like this …

Total answers: 2