File: hiredis.c

package info (click to toggle)
python-hiredis 0.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 408 kB
  • sloc: ansic: 4,214; python: 271; makefile: 10
file content (79 lines) | stat: -rw-r--r-- 2,269 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "hiredis.h"
#include "reader.h"

#if IS_PY3K
static int hiredis_ModuleTraverse(PyObject *m, visitproc visit, void *arg) {
    Py_VISIT(GET_STATE(m)->HiErr_Base);
    Py_VISIT(GET_STATE(m)->HiErr_ProtocolError);
    Py_VISIT(GET_STATE(m)->HiErr_ReplyError);
    return 0;
}

static int hiredis_ModuleClear(PyObject *m) {
    Py_CLEAR(GET_STATE(m)->HiErr_Base);
    Py_CLEAR(GET_STATE(m)->HiErr_ProtocolError);
    Py_CLEAR(GET_STATE(m)->HiErr_ReplyError);
    return 0;
}

static struct PyModuleDef hiredis_ModuleDef = {
    PyModuleDef_HEAD_INIT,
    MOD_HIREDIS,
    NULL,
    sizeof(struct hiredis_ModuleState), /* m_size */
    NULL, /* m_methods */
    NULL, /* m_reload */
    hiredis_ModuleTraverse, /* m_traverse */
    hiredis_ModuleClear, /* m_clear */
    NULL /* m_free */
};
#else
struct hiredis_ModuleState hiredis_py_module_state;
#endif

/* Keep pointer around for other classes to access the module state. */
PyObject *mod_hiredis;

#if IS_PY3K
PyMODINIT_FUNC PyInit_hiredis(void)
#else
PyMODINIT_FUNC inithiredis(void)
#endif

{
    if (PyType_Ready(&hiredis_ReaderType) < 0) {
#if IS_PY3K
        return NULL;
#else
        return;
#endif
    }

#if IS_PY3K
    mod_hiredis = PyModule_Create(&hiredis_ModuleDef);
#else
    mod_hiredis = Py_InitModule(MOD_HIREDIS, NULL);
#endif

    /* Setup custom exceptions */
    HIREDIS_STATE->HiErr_Base =
        PyErr_NewException(MOD_HIREDIS ".HiredisError", PyExc_Exception, NULL);
    HIREDIS_STATE->HiErr_ProtocolError =
        PyErr_NewException(MOD_HIREDIS ".ProtocolError", HIREDIS_STATE->HiErr_Base, NULL);
    HIREDIS_STATE->HiErr_ReplyError =
        PyErr_NewException(MOD_HIREDIS ".ReplyError", HIREDIS_STATE->HiErr_Base, NULL);

    Py_INCREF(HIREDIS_STATE->HiErr_Base);
    PyModule_AddObject(mod_hiredis, "HiredisError", HIREDIS_STATE->HiErr_Base);
    Py_INCREF(HIREDIS_STATE->HiErr_ProtocolError);
    PyModule_AddObject(mod_hiredis, "ProtocolError", HIREDIS_STATE->HiErr_ProtocolError);
    Py_INCREF(HIREDIS_STATE->HiErr_ReplyError);
    PyModule_AddObject(mod_hiredis, "ReplyError", HIREDIS_STATE->HiErr_ReplyError);

    Py_INCREF(&hiredis_ReaderType);
    PyModule_AddObject(mod_hiredis, "Reader", (PyObject *)&hiredis_ReaderType);

#if IS_PY3K
    return mod_hiredis;
#endif
}