Example #1
0
/* Module */
PyObject *
init_fibers(void)
{
    PyObject *fibers;

    /* Main module */
#if PY_MAJOR_VERSION >= 3
    fibers = PyModule_Create(&fibers_module);
#else
    fibers = Py_InitModule("fibers", fibers_methods);
#endif

    /* keys for per-thread dictionary */
#if PY_MAJOR_VERSION >= 3
    current_fiber_key = PyUnicode_InternFromString("__fibers_current");
#else
    current_fiber_key = PyString_InternFromString("__fibers_current");
#endif
    if (current_fiber_key == NULL) {
        goto fail;
    }

    /* Exceptions */
    PyExc_FiberError = PyErr_NewException("fibers.error", NULL, NULL);
    MyPyModule_AddType(fibers, "error", (PyTypeObject *)PyExc_FiberError);

    /* Types */
    MyPyModule_AddType(fibers, "Fiber", &FiberType);

    /* Module version (the MODULE_VERSION macro is defined by setup.py) */
    PyModule_AddStringConstant(fibers, "__version__", STRINGIFY(MODULE_VERSION));

    return fibers;

fail:
#if PY_MAJOR_VERSION >= 3
    Py_DECREF(fibers);
#endif
    return NULL;

}
Example #2
0
/* Module */
PyObject *
init_fibers(void)
{
    PyObject *fibers;

    /* Main module */
#if PY_MAJOR_VERSION >= 3
    fibers = PyModule_Create(&fibers_module);
#else
    fibers = Py_InitModule("fibers._cfibers", fibers_methods);
#endif

    /* keys for per-thread dictionary */
#if PY_MAJOR_VERSION >= 3
    main_fiber_key = PyUnicode_InternFromString("__fibers_main");
    current_fiber_key = PyUnicode_InternFromString("__fibers_current");
#else
    main_fiber_key = PyString_InternFromString("__fibers_main");
    current_fiber_key = PyString_InternFromString("__fibers_current");
#endif
    if ((current_fiber_key == NULL) || (main_fiber_key == NULL)) {
        goto fail;
    }

    /* Exceptions */
    PyExc_FiberError = PyErr_NewException("fibers._cfibers.error", NULL, NULL);
    MyPyModule_AddType(fibers, "error", (PyTypeObject *)PyExc_FiberError);

    /* Types */
    MyPyModule_AddType(fibers, "Fiber", &FiberType);

    return fibers;

fail:
#if PY_MAJOR_VERSION >= 3
    Py_DECREF(fibers);
#endif
    return NULL;

}