2 * This file is part of the libsigrokdecode project.
4 * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "libsigrokdecode.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */
21 #include "libsigrokdecode-internal.h"
27 extern SRD_PRIV PyTypeObject srd_Decoder_type;
30 extern SRD_PRIV PyTypeObject srd_logic_type;
33 * When initialized, a reference to this module inside the Python interpreter
36 SRD_PRIV PyObject *mod_sigrokdecode = NULL;
40 static struct PyModuleDef sigrokdecode_module = {
41 PyModuleDef_HEAD_INIT,
42 .m_name = "sigrokdecode",
43 .m_doc = "sigrokdecode module",
48 /* FIXME: SRD_PRIV causes issues on MinGW. Investigate. */
49 PyMODINIT_FUNC PyInit_sigrokdecode(void)
53 /* tp_new needs to be assigned here for compiler portability. */
54 srd_Decoder_type.tp_new = PyType_GenericNew;
55 if (PyType_Ready(&srd_Decoder_type) < 0)
58 srd_logic_type.tp_new = PyType_GenericNew;
59 if (PyType_Ready(&srd_logic_type) < 0)
62 mod = PyModule_Create(&sigrokdecode_module);
63 Py_INCREF(&srd_Decoder_type);
64 if (PyModule_AddObject(mod, "Decoder",
65 (PyObject *)&srd_Decoder_type) == -1)
67 Py_INCREF(&srd_logic_type);
68 if (PyModule_AddObject(mod, "srd_logic",
69 (PyObject *)&srd_logic_type) == -1)
72 /* expose output types as symbols in the sigrokdecode module */
73 if (PyModule_AddIntConstant(mod, "OUTPUT_ANN", SRD_OUTPUT_ANN) == -1)
75 if (PyModule_AddIntConstant(mod, "OUTPUT_PROTO",
76 SRD_OUTPUT_PROTO) == -1)
78 if (PyModule_AddIntConstant(mod, "OUTPUT_BINARY",
79 SRD_OUTPUT_BINARY) == -1)
82 mod_sigrokdecode = mod;