title: Calling Python functions from inline C with scipy.weave
body: <p>Can I call a python function from inline C code (using weave)?</p>
  
  <p>Motivation:
  I have a bit of code that I'd like to optimize, and I've identified the bottleneck in one function. After my usual tricks, I usually turn to <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.weave.inline.html" rel="noreferrer">scipy.weave.inline</a> for optimization. Unfortunately, in this case, my function is calling another python function in an inner loop. I've made sure that the inner function isn't causing the speed issue, and I really don't want to have to write it in C as well.</p>
  
  <p>Minimal Example:</p>
  
  <pre><code>from weave import inline
  
  def foo(x):
      return x*2
  
  def bar():
      a = 0
      for i in xrange(10):
          a += foo(i)
      return a
  
  def bar_weave():
      code = """
      int a = 0;
      for (int i=0;i&lt;10;++i){
          a += foo(i);  //&lt;&lt;-- what I'd like to do, but doesn't work
      }
      return_val = a;"""
      return inline(code,['foo'])
  
  print bar()
  print bar_weave()
  </code></pre>