title: Cython memoryviews: wrapping c function with array parameter to pass numpy array
body: <p>I am trying to use Cython to wrap c function with an array parameter (<code>quick_sort()</code>), so I can pass a numpy array to it. I've searched the documentation, SO and web for a working, minimal example but didn't find it. I've tried several possibilities but without any progress, so please help me to figure it out. Here are my files:</p>
  <p><strong>quicksort.c</strong></p>
  <pre><code>#include &lt;stdio.h&gt;
  
  void quick_sort (int* a, int n) {
      int i, j, p, t;
      if (n &lt; 2)
          return;
      p = a[n / 2];
      for (i = 0, j = n - 1;; i++, j--) {
          while (a[i] &lt; p)
              i++;
          while (p &lt; a[j])
              j--;
          if (i &gt;= j)
              break;
          t = a[i];
          a[i] = a[j];
          a[j] = t;
      }
      quick_sort(a, i);
      quick_sort(a + i, n - i);
  }
  </code></pre>
  <p><strong>quicksort.h</strong></p>
  <pre><code>void quick_sort (int* a, int n);
  </code></pre>
  <p><strong>quicksort.pxd</strong></p>
  <pre><code>cdef extern from &quot;quicksort.h&quot;:
      void quick_sort (int[:] a, int n)
  </code></pre>
  <p><strong>cy_quicksort.pyx</strong></p>
  <pre><code>cimport quicksort
  
  def quicksort_c(int[:] a):
      quicksort.quick_sort(a, a.size)
  </code></pre>
  <p><strong>setup.py</strong></p>
  <pre><code>from distutils.core import setup
  from Cython.Build import cythonize
  
  setup(
      name='quicksort cython',
      ext_modules=cythonize(&quot;*.pyx&quot;),
  )
  </code></pre>
  <p>When I'm running <code>python setup.py build_ext --inplace</code> command, it returns the following error:</p>
  <pre><code>cy_quicksort.c:1362:14: error: passing '__Pyx_memviewslice' to parameter of
        incompatible type 'int *'
    quick_sort(__pyx_v_a, __pyx_t_3);
               ^~~~~~~~~
  ./quicksort.h:1:23: note: passing argument to parameter 'a' here
  void quick_sort (int* a, int n);
  </code></pre>
  <p>What I want to achieve is to compile this and be able to run for example:</p>
  <pre><code>import numpy as np
  from cy_quicksort import quicksort_c
  a = np.array(range(9, 0, -1), dtype=np.int32)
  quicksort_c(a)
  </code></pre>
  <p>Thanks in advance for Your time!</p>
  <hr />
  <h3>Edit:</h3>
  <p>After changes suggested by DavidW in <strong>quicksort.pxd</strong>, <strong>cy_quicksort.pyx</strong> and changing the <strong>setup.py</strong> file into the following form, it's working as intended.</p>
  <p><strong>setup.py</strong></p>
  <pre><code>from distutils.core import setup
  from Cython.Build import cythonize
  from distutils.extension import Extension
  
  sourcefiles = ['cy_quicksort.pyx', 'quicksort.c']
  
  extensions = [Extension(&quot;cy_quicksort&quot;, sourcefiles)]
  
  setup(
      ext_modules = cythonize(extensions)
  )
  </code></pre>