I used SWIG to connect my C++ program with Python. From cFunctions.py I call C function named checkVal like following:
lib = cdll.LoadLibrary('./test.so')
xml_bytesTrx = bytearray(b'<xml>...</xml>')
a1 = (ctypes.c_byte*513)(*xml_bytesTrx)
class EFT_TRX(Structure):
_fields_ = [
("a2",c_ulong),
("a3",c_char*16),
("a4",c_char*4),
("a5",c_ushort),
("a6",c_char*41),
("a7",c_char*13),
("a8",c_char*21),
("a1",c_byte*513)
]
Trx = EFT_TRX(0,"0",'CHF',0,'4506445638161117',"123456123456","202020",
a1)
def check(arg1, arg2):
eftTransactionRes = lib.checkVal(arg1,arg2,Trx.a4,Trx.a5,
Trx.a6,Trx.a7,Trx.a8,
Trx.a1)
Trx.a3 = arg2
return eftTransactionRes
And in C header file (test.h) is defined like following:
long TEST_API checkVal(
_IN____ const unsigned long a2,
_INOUT_ char a3[16],
_IN____ const char a4[4],
_IN____ const unsigned short a5,
_IN____ const char a6[41],
_IN____ const char a7[13],
_IN____ const char a8[21],
_INOUT_ char a1[513]
);
Now I wrote a test Python code to call C functions (accessible from cFunctions.py). The issue is that , when I call "check" from my test code ( cFunctions.check(10,20) ) I reach it, but it never returns anything!
But if I call check from within cFunctions.py itself like this:
check(10,Trx.a2)
It returns the result. What am I doing wrong? Why check doesn't return anything when I'm calling it from my test.py ?
check, the first two arguments tolib.checkVal(a2,a3,Trx.a4...are called without Trx reference. Maybe in cFunctions.py a2 and a3 are properly defined but not in the test code. Also you make never use ofkulTrxTypeis this intended?