module_shim.tmpl 522 B

123456789101112131415161718
  1. #include <Python.h>
  2. PyMODINIT_FUNC
  3. PyInit_{modname}(void)
  4. {{
  5. PyObject *tmp;
  6. if (!(tmp = PyImport_ImportModule("{libname}"))) return NULL;
  7. Py_DECREF(tmp);
  8. void *init_func = PyCapsule_Import("{libname}.init_{full_modname}", 0);
  9. if (!init_func) {{
  10. return NULL;
  11. }}
  12. return ((PyObject *(*)(void))init_func)();
  13. }}
  14. // distutils sometimes spuriously tells cl to export CPyInit___init__,
  15. // so provide that so it chills out
  16. PyMODINIT_FUNC PyInit___init__(void) {{ return PyInit_{modname}(); }}