I'm working on a cffi testing demo, and when I try to run the python tester file, it returns the following error: TypeError: initializer for ctype 'Car *' appears indeed to be 'Car *', but the types are different (check that you are not e.g. mixing up different ffi instances)
The car.h file defines the C structure Car and is shown here:
/*Class definition for car*/
typedef struct {
char make[32];
char model[32];
char year[32];
char color[32];
} Car;
Here is the python file using cffi that I'm trying to use to test the C code.
import unittest
import cffi
import importlib
ffi=cffi.FFI()
def load(filename):
#load source code
source = open('../src/' + filename + '.c').read()
includes = open('../include/' + filename + '.h').read()
#pass source code to CFFI
ffi.cdef(includes)
ffi.set_source(filename + '_', source)
ffi.compile()
#import and return resulting module
module = importlib.import_module(filename + '_')
return module.lib
class carTest(unittest.TestCase):
def test_setMake(self):
module = load('car')
myCar = ffi.new('Car *',
["Honda", "Civic", "1996", "Black"])
make = ("char []", "Honda")
self.assertEqual(module.setMake(myCar, make),
car)
if __name__ == '__main__':
unittest.main()
Any advice on this issue would be very welcome. I feel like I've gone over it a hundred times.
Thanks in advance