title: Cython Function giving segmentation Fault when calling from Python
body: <p>So i'm trying to make a script which will clone some value in a 2d- Matrix and since the matrix could be huge, i'm using cython btw i'm new to cython. Here's the code</p>
  <pre class="lang-py prettyprint-override"><code>from cpython cimport *
  
  def cloningNodes(matrix,toClone):
      cdef Py_ssize_t matrixSize=PyList_Size(matrix),cloneSize=PyList_Size(toClone),newSize=matrixSize+cloneSize,i,j
      output=PyList_New(newSize)
      for i in range(matrixSize):
          PyList_SET_ITEM(output,i,
              &lt;object&gt;PyList_GET_ITEM(matrix,i))
          for j in range(cloneSize):
              currentRow=&lt;object&gt;PyList_GET_ITEM(output,i)
              PyList_Append(currentRow,&lt;object&gt;PyList_GET_ITEM(
                      &lt;object&gt;PyList_GET_ITEM(matrix,i),PyLong_AsSsize_t(&lt;object&gt;PyList_GET_ITEM(toClone,j))
                  )
              )
      for i in range(cloneSize):
          PyList_SET_ITEM(output,i+matrixSize,&lt;object&gt;PyList_GET_ITEM(output,PyLong_AsSsize_t(&lt;object&gt;PyList_GET_ITEM(toClone,i))))
      return output
  </code></pre>
  <p>After Compiling and calling this module with</p>
  <pre class="lang-py prettyprint-override"><code>from MODULE_NAME import cloningNodes
  cloningNodes([[1,2],[2,1]],[1])
  </code></pre>
  <p>it's giving me segmentation Fault(CoreDumped)
  Can anyone tell me why is this giving Segmentation Fault along with any minor improvements you could think of.</p>
  <p>Edit: Btw i tried to put a print statement before return output and it seems like the list is created without a problem but there's some problem while returning the list.</p>