title: convert python object to cython pointer
body: <p>I'm trying to expose c++ classes to python using cython. I wrote their definitions in *.pxd file and implemented a wrappers in *.pyx files. But I got stuck trying to pass to a function pointer to the extension type. Here is simplified example.</p>
  
  <p><strong>foo.pyx</strong></p>
  
  <pre class="lang-cython prettyprint-override"><code>from c_foo cimport cFoo
  cdef class Foo:
      cdef cFoo* _impl
  </code></pre>
  
  <p><strong>c_foo_holder.pxd</strong></p>
  
  <pre class="lang-c prettyprint-override"><code>cdef extern from "FooHolder.h":
      cdef cppclass cFooHolder:
          cFooHolder(cFoo* foo)    
  </code></pre>
  
  <p><strong>foo_holder.pyx</strong></p>
  
  <pre class="lang-cython prettyprint-override"><code>from c_foo_holder cimport cFooHolder
  from c_foo cimport cFoo
  
  cdef class FooHolder:
      cdef cFooHolder* _impl
      def __init__(self, foo):
          self._impl = new cFooHolder(&lt;cFoo*&gt;(foo._impl)) # error here    
  </code></pre>
  
  <p>But on the last line I get error "<strong>Python objects cannot be cast to pointers of primitive types</strong>". I also tried several other approaches, but nothing worked:</p>
  
  <pre class="lang-cython prettyprint-override"><code># error: 'Foo' is not a type identifier 
  from foo import Foo
  def __init__(self, Foo foo):
      self._impl = new cFooHolder(foo._impl)
  
  # error: 'Foo' is not a type identifier 
  def __init__(self, foo):
     self._impl = new cFooHolder(&lt;Foo&gt;(foo)._impl)
  </code></pre>