File: module_shim.tmpl

package info (click to toggle)
python-librt 0.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 524 kB
  • sloc: ansic: 8,544; cpp: 478; python: 216; makefile: 8
file content (21 lines) | stat: -rw-r--r-- 670 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <Python.h>

PyMODINIT_FUNC
PyInit_{modname}(void)
{{
    PyObject *tmp;
    if (!(tmp = PyImport_ImportModule("{libname}"))) return NULL;
    PyObject *capsule = PyObject_GetAttrString(tmp, "init_{full_modname}");
    Py_DECREF(tmp);
    if (capsule == NULL) return NULL;
    void *init_func = PyCapsule_GetPointer(capsule, "{libname}.init_{full_modname}");
    Py_DECREF(capsule);
    if (!init_func) {{
        return NULL;
    }}
    return ((PyObject *(*)(void))init_func)();
}}

// distutils sometimes spuriously tells cl to export CPyInit___init__,
// so provide that so it chills out
PyMODINIT_FUNC PyInit___init__(void) {{ return PyInit_{modname}(); }}