title: Trying to use cython to pass a list from a python script to a C++ function, causes segmentation fault
body: <p>I'm trying to use Cython to pass an array from a Python script into a C++ function, modify it, then return the array from the Python script. I know that passing arrays using Cython is a challenge, and I'm wondering if it is clear to anyone where I have gone wrong in my implementation. I've included my .h, .cpp, .pxd, and .pyx files below.</p>
  <p>.h</p>
  <pre><code>#ifndef DUMMY_PROPAGATOR_H
  #define DUMMY_PROPAGATOR_H
  
  namespace dummy_namespace {
      class dummy_class {
          public:
              double t;
              std::vector&lt;double&gt; state;
              double physicalProperties;
              double forces;
              dummy_class();
              dummy_class(double t, std::vector&lt;double&gt; state, double physicalProperties, double forces);
              ~dummy_class();
              std::vector&lt;double&gt; prop_to(std::vector&lt;double&gt; state);
      };
  }
  
  #endif //DUMMY_PROPAGATOR_H
  </code></pre>
  <p>.cpp:</p>
  <pre><code>#include &quot;dummy_prop.h&quot;
  #include &lt;vector&gt;
  
  namespace dummy_namespace {
  
      dummy_class::dummy_class() {}
  
      dummy_class::dummy_class(double t, std::vector&lt;double&gt; state, double physicalProperties, double forces) {
          this-&gt;t = t;
          this-&gt;state = {};
          for(unsigned i = 0; i &lt; 14; i++) {
              this-&gt;state[i] = state[i];
          }
          this-&gt;physicalProperties = physicalProperties;
          this-&gt;forces = forces;
      }
  
      dummy_class::~dummy_class() {}
  
      std::vector&lt;double&gt; dummy_class::prop_to(std::vector&lt;double&gt; state) {
          std::vector&lt;double&gt; new_state = {};
          for(unsigned i = 0; i &lt; 14; i++) {
              new_state[i] = state[i];
          }
          return new_state;
      }
  }
  </code></pre>
  <p>.pxd</p>
  <pre><code>from cpython cimport array
  from libcpp.vector cimport vector
  cimport cython
  
  cdef extern from &quot;dummy_prop/dummy_prop.cpp&quot;:
      pass
  
  cdef extern from &quot;dummy_prop/dummy_prop.h&quot; namespace &quot;dummy_namespace&quot;:
      cdef cppclass dummy_class:
          dummy_class() except +
          dummy_class(double, vector[double], double, double) except +
          double t
          double physicalProperties 
          double forces
          vector[double] state
          vector[double] prop_to(vector[double]) except +
  </code></pre>
  <p>.pyx:</p>
  <pre><code># distutils: language = c++
  
  from dummy_prop cimport dummy_class
  from libcpp.vector cimport vector
  cimport cython
  
  cdef class prop_state:
      cdef dummy_class c_instance  # Hold a C++ instance which we're wrapping
  
      def __cinit__(self, double t, vector[double] state, double physicalProperties, double forces):
          self.c_instance = dummy_class(t, state, physicalProperties, forces)
  
      def get_prop_state(self, vector[double] state):
          cdef vector[double] new_state = self.c_instance.prop_to(state)
          return new_state
  </code></pre>