I am trying to extend my python code by creating a c++ module. I am able to import my c++ code by calling 'import my_code' in python with no problem. My issue occurs when I try to return the PyObject. I want to take a vector *settled_nodes_vector that I have created from my c++ code and write the data from that vector as binary data to a buffer and return that buffer. Right now I am doing this:
PyBuffer_FromReadWriteMemory((void *) settled_nodes_vector->data(), settled_nodes_vector->size() * sizeof(result_node)));
and when I call the following in python
>>> import my_module
>>> result = my_module.make_buffer()
>>> result
<read-write buffer ptr 0x7fae708c5010, size 20335840 at 0x7fae899577b0>
>>> len(result)
20335840
>>> result[0]
92121 Segmentation fault (core dumped) python -i
So my question is how is it that I can't index my information in my result when it is a non-zero length.