[ad_1]
I have a problem with my python code.
I have a function in c that return an array of int. As following :
int* prochepoints_tabu (Client* points, int size, int distmax){
//instructions
int* path;
for (int i = 1; i < nsize; i++){
path[i] = res[i].number;
}
return path;
}
Then I called this function in python as following :
class CA(Structure):
_fields_ = [('number', c_int),
('x',c_int),
('y',c_int)]
ca_list = []
newlist = nodes.copy()
newlist.pop('0')
for key, el in newlist.items():
ca = CA()
ca.number = int(key)
ca.x = el[0]
ca.y = el[1]
ca_list.append(ca)
ca_array = (CA * len(ca_list))(*ca_list)
distmax = c_int(vehicles[8]['charged'])
cap = c_int(vehicles[8]['capacity'])
res =(CA * len(vehicles))()
dll = CDLL('./functions.so')
dll.prochepoints_tabu.argtypes = [POINTER(CA), c_int, c_int]
dll.prochepoints_tabu.restype = POINTER(c_int)
path = dll.prochepoints_tabu(ca_array, len(ca_array), vehicles[1]['charged'])
And when I compile this program I’ve this message of error :
” path = dll.prochepoints_tabu(ca_array, len(ca_array), vehicles[1][‘charged’])
OSError: exception: access violation writing 0x0000000000000004″
Thus, how can I return an array in python from C without knowing his size, because I want to store this array in python
Thank you very much for your help
[ad_2]