title: PyPy cpyext: any documentation? how to use? PyThreadState_Get error?
body: <p>I have read (<a href="http://morepypy.blogspot.de/2010/04/using-cpython-extension-modules-with.html" rel="noreferrer">here</a>) that PyPy has support for CPython extension modules via cpyext.</p>
  
  <p>I haven't found any cpyext documentation. Is there any?</p>
  
  <p>How do I use it?</p>
  
  <p>From the source code (e.g. <a href="https://bitbucket.org/pypy/pypy/src/default/pypy/module/cpyext/api.py?at=default" rel="noreferrer">here</a>), I figured out that to load my <code>leveldb.so</code> module, I probably have to do this:</p>
  
  <pre><code>import cpyext
  cpyext.load_module("leveldb.so","leveldb")
  </code></pre>
  
  <p>However, this crashes with this error:</p>
  
  <pre><code>Fatal Python error: PyThreadState_Get: no current thread
  </code></pre>
  
  <p>I noticed in the backtrace that it calls the functions from my CPython, not from PyPy:</p>
  
  <pre><code>Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
  0   libsystem_kernel.dylib          0x00007fff8b3e4d46 __kill + 10
  1   libsystem_c.dylib               0x00007fff927a9df0 abort + 177
  2   org.python.python               0x0000000104692eaa Py_FatalError + 49
  3   org.python.python               0x0000000104691370 PyThreadState_Get + 28
  4   org.python.python               0x000000010468cf16 Py_InitModule4_64 + 58
  5   leveldb.so                      0x00000001027e0881 initleveldb + 49 (leveldb_ext.cc:59)
  6   pypy                            0x0000000100f59bb3 PyLong_CheckExact + 55379
  7   pypy                            0x0000000100f6e7c7 PyLong_CheckExact + 140391
  ....
  </code></pre>