]> sigrok.org Git - libsigrokdecode.git/blame - module_sigrokdecode.c
Don't show a harmless/confusing warning on stdout.
[libsigrokdecode.git] / module_sigrokdecode.c
CommitLineData
bc5f5a43 1/*
50bd5d25 2 * This file is part of the libsigrokdecode project.
bc5f5a43
BV
3 *
4 * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
36784362 20#include <config.h>
f6c7eade
MC
21#include "libsigrokdecode-internal.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */
22#include "libsigrokdecode.h"
bc5f5a43 23
57790bc8
UH
24/** @cond PRIVATE */
25
201a85a8 26SRD_PRIV PyObject *srd_logic_type = NULL;
bc5f5a43 27
c9bfccc6 28/*
511e2123 29 * When initialized, a reference to this module inside the Python interpreter
d0a0ed03
BV
30 * lives here.
31 */
55c3c5f4 32SRD_PRIV PyObject *mod_sigrokdecode = NULL;
bc5f5a43 33
57790bc8
UH
34/** @endcond */
35
bc5f5a43
BV
36static struct PyModuleDef sigrokdecode_module = {
37 PyModuleDef_HEAD_INIT,
38 .m_name = "sigrokdecode",
f8e45857 39 .m_doc = "sigrokdecode module",
bc5f5a43 40 .m_size = -1,
bc5f5a43
BV
41};
42
57790bc8 43/** @cond PRIVATE */
53a07a6d 44PyMODINIT_FUNC PyInit_sigrokdecode(void)
bc5f5a43 45{
201a85a8 46 PyObject *mod, *Decoder_type, *logic_type;
bc5f5a43 47
201a85a8
DE
48 mod = PyModule_Create(&sigrokdecode_module);
49 if (!mod)
50 goto err_out;
bc5f5a43 51
201a85a8
DE
52 Decoder_type = srd_Decoder_type_new();
53 if (!Decoder_type)
54 goto err_out;
55 if (PyModule_AddObject(mod, "Decoder", Decoder_type) < 0)
56 goto err_out;
bc5f5a43 57
201a85a8
DE
58 logic_type = srd_logic_type_new();
59 if (!logic_type)
60 goto err_out;
61 if (PyModule_AddObject(mod, "srd_logic", logic_type) < 0)
62 goto err_out;
bc5f5a43 63
7ee0c40b 64 /* Expose output types as symbols in the sigrokdecode module */
201a85a8
DE
65 if (PyModule_AddIntConstant(mod, "OUTPUT_ANN", SRD_OUTPUT_ANN) < 0)
66 goto err_out;
67 if (PyModule_AddIntConstant(mod, "OUTPUT_PYTHON", SRD_OUTPUT_PYTHON) < 0)
68 goto err_out;
69 if (PyModule_AddIntConstant(mod, "OUTPUT_BINARY", SRD_OUTPUT_BINARY) < 0)
70 goto err_out;
71 if (PyModule_AddIntConstant(mod, "OUTPUT_META", SRD_OUTPUT_META) < 0)
72 goto err_out;
7ee0c40b 73 /* Expose meta input symbols. */
201a85a8
DE
74 if (PyModule_AddIntConstant(mod, "SRD_CONF_SAMPLERATE", SRD_CONF_SAMPLERATE) < 0)
75 goto err_out;
3e2a9de2 76
201a85a8 77 srd_logic_type = logic_type;
451680f1
BV
78 mod_sigrokdecode = mod;
79
bc5f5a43 80 return mod;
201a85a8
DE
81err_out:
82 Py_XDECREF(mod);
83 srd_exception_catch("Failed to initialize module");
84
85 return NULL;
bc5f5a43 86}
57790bc8 87/** @endcond */