title: C++ method demands reference, can't get Cython to provide one
body: <p>I am interfacing Python to a C++ library called Bullet Physics, via Cython. I have quite a bit of it working but one issue is vexing me. Here is an example of a problem that occurs in multiple contexts.</p>
  
  <p>A Bullet Physics .h file declares a method, which I copy and incorporate into my cdefs like this:</p>
  
  <pre><code>cdef cppclass btSliderConstraint:
      btSliderConstraint *btSliderConstraint(btRigidBody&amp; rbA, btRigidBody&amp; rbB, const btTransform&amp; frameInA, const btTransform&amp; frameInB, bool useLinearReferenceFrameA)
  </code></pre>
  
  <p>The problem is how to specify the rbA and rbB <em>references</em> (the &amp; rbA and &amp; rbB) in a Cython call to this method . I have lots of pointers to btRigidBody objects floating around, but the declaration of this method demands the arguments be <em>references</em> (unless I am mistaken). </p>
  
  <p>If I try to just supply pointers to btRigidBody objects for rbA and rbB, the cython compiler complains, fairly understandably, with:</p>
  
  <pre><code>Error compiling Cython file:
  ------------------------------------------------------------
      cdef btRigidBody *b1
      cdef btRigidBody *b2
      # bs.bodies is an array of pointers to btRigidBody objects, nbi and ji1 are integer indices
      b1 = bs.bodies[nbi]
      b2 = bs.bodies[ji1]
      motor = new btSliderConstraint(b1, b2, tra, trb, 1);
                                          ^
  ------------------------------------------------------------
  
  fun4.pyx:922:41: Cannot assign type 'btRigidBody *' to 'btRigidBody'
  </code></pre>
  
  <p>None of my attempts to cast or dereference or the like have made this work. It seems like this is easy to do in plain C++ but in Cython nothing I've tried seems to work.</p>
  
  <p>If I were able to simply declare a variable of type btRigidBody, like this:</p>
  
  <p>cdef btRigidBody rbA</p>
  
  <p>then I am confident I could pass that as an argument and the compiler would not complain. I do this in other contexts and it works. However, I do not want to do this here because I already have a pointer to the object that I want to pass as the argument, and also, doing things this way would require that a "nullarity constructor" exist for the btRigidBody object and the library does not provide a constructor that takes no arguments, and I do not want to make modifications to the library for reasons of maintainability.</p>
  
  <p>So, how can I convert the pointers to a btRigidBody objects that I have, to btRigidBody references that I need, in Cython?</p>
  
  <p>Edit:</p>
  
  <p>The obvious use of * to dereference the pointer does not work in Cython (though I think it would work in C++). In Cython it gives a slew of confusing errors:</p>
  
  <pre><code>Error compiling Cython file:
  ------------------------------------------------------------
  ...
      cdef btRigidBody *b1
      cdef btRigidBody *b2
      # bs.bodies is an array of pointers to btRigidBody objects, nbi and ji1 are integer indices
      b1 = bs.bodies[nbi]
      b2 = bs.bodies[ji1]
      motor = new btSliderConstraint(*b1, *b2, tra, trb, 1);
                                   ^
  ------------------------------------------------------------
  
  fun4.pyx:922:34: Non-trivial keyword arguments and starred arguments not allowed in cdef functions.
  
  Error compiling Cython file:
  ------------------------------------------------------------
  ...
      cdef btRigidBody *b1
      cdef btRigidBody *b2
      # bs.bodies is an array of pointers to btRigidBody objects, nbi and ji1 are integer indices
      b1 = bs.bodies[nbi]
      b2 = bs.bodies[ji1]
      motor = new btSliderConstraint(*b1, *b2, tra, trb, 1);
                                       ^
  ------------------------------------------------------------
  
  fun4.pyx:922:38: Cannot convert 'btRigidBody *' to Python object
  
  Error compiling Cython file:
  ------------------------------------------------------------
  ...
      cdef btRigidBody *b1
      cdef btRigidBody *b2
      # bs.bodies is an array of pointers to btRigidBody objects, nbi and ji1 are integer indices
      b1 = bs.bodies[nbi]
      b2 = bs.bodies[ji1]
      motor = new btSliderConstraint(*b1, *b2, tra, trb, 1);
                                            ^
  ------------------------------------------------------------
  
  fun4.pyx:922:43: Cannot convert 'btRigidBody *' to Python object
  
  Error compiling Cython file:
  ------------------------------------------------------------
  ...
      cdef btRigidBody *b1
      cdef btRigidBody *b2
      # bs.bodies is an array of pointers to btRigidBody objects, nbi and ji1 are integer indices
      b1 = bs.bodies[nbi]
      b2 = bs.bodies[ji1]
      motor = new btSliderConstraint(*b1, *b2, tra, trb, 1);
                                                 ^
  ------------------------------------------------------------
  
  fun4.pyx:922:48: Cannot convert 'btTransform' to Python object
  
  Error compiling Cython file:
  ------------------------------------------------------------
  ...
      cdef btRigidBody *b1
      cdef btRigidBody *b2
      # bs.bodies is an array of pointers to btRigidBody objects, nbi and ji1 are integer indices
      b1 = bs.bodies[nbi]
      b2 = bs.bodies[ji1]
      motor = new btSliderConstraint(*b1, *b2, tra, trb, 1);
                                                      ^
  ------------------------------------------------------------
  
  fun4.pyx:922:53: Cannot convert 'btTransform' to Python object
  
  Error compiling Cython file:
  ------------------------------------------------------------
  ...
      cdef btRigidBody *b1
      cdef btRigidBody *b2
      # bs.bodies is an array of pointers to btRigidBody objects, nbi and ji1 are integer indices
      b1 = bs.bodies[nbi]
      b2 = bs.bodies[ji1]
      motor = new btSliderConstraint(*b1, *b2, tra, trb, 1);
                                   ^
  ------------------------------------------------------------
  
  fun4.pyx:922:34: Cannot convert Python object to 'btSliderConstraint *'
  
  Error compiling Cython file:
  ------------------------------------------------------------
  ...
      cdef btRigidBody *b1
      cdef btRigidBody *b2
      # bs.bodies is an array of pointers to btRigidBody objects, nbi and ji1 are integer indices
      b1 = bs.bodies[nbi]
      b2 = bs.bodies[ji1]
      motor = new btSliderConstraint(*b1, *b2, tra, trb, 1);
                                   ^
  ------------------------------------------------------------
  
  fun4.pyx:922:34: Storing unsafe C derivative of temporary Python reference
  </code></pre>