title: How do I write an extension type that wraps pre-allocated data?
body: <p>I have some data from a struct that has already been allocated and initialized. 
  I can guarantee that the data will not be freed during any of these objects lifetimes. How do I wrap this in a Python object in Cython? The following does <em>not</em> work, but I hope it explains my intent:</p>
  
  <pre><code>from libc.stdlib cimport malloc
  
  ctypedef struct Point:
      int x
      int y
  
  cdef class _MyWrapper:
      cdef Point* foo
      def __cinit__(self, Point* foo):
          self.foo = foo
  
  def create_eternal_MyWrapper(int x, int y):
      cdef Point* p
      p = &lt;Point*&gt;malloc(sizeof(Point))
      p.x = x
      p.y = y
      return _MyWrapper(p)
  </code></pre>
  
  <p>The output from running cython on this:</p>
  
  <pre><code>Error compiling Cython file:
  ------------------------------------------------------------
  ...
  def create_eternal_MyWrapper(int x, int y):
      cdef Point* p
      p = &lt;Point*&gt;malloc(sizeof(Point))
      p.x = x
      p.y = y
      return _MyWrapper(p)
                        ^
  ------------------------------------------------------------
  
  examplecy.pyx:17:23: Cannot convert 'Point *' to Python object
  </code></pre>