Add spec package type with access to headers to python rpmb module
[platform/upstream/rpm.git] / python / rpmbmodule.c
1 #include "rpmsystem-py.h"
2
3 #include "spec-py.h"
4
5 #include "debug.h"
6
7 static char rpmb__doc__[] =
8 "";
9
10 /*
11   Do any common preliminary work before python 2 vs python 3 module creation:
12 */
13 static int prepareInitModule(void)
14 {
15     if (PyType_Ready(&spec_Type) < 0) return 0;
16     if (PyType_Ready(&specPkg_Type) < 0) return 0;
17
18     return 1;
19 }
20
21 static int initModule(PyObject *m)
22 {
23     Py_INCREF(&spec_Type);
24     PyModule_AddObject(m, "spec", (PyObject *) &spec_Type);
25     Py_INCREF(&specPkg_Type);
26     PyModule_AddObject(m, "specPkg", (PyObject *) &specPkg_Type);
27
28     return 1;
29 }
30
31 #if PY_MAJOR_VERSION >= 3
32 static struct PyModuleDef moduledef = {
33     PyModuleDef_HEAD_INIT,
34     "_rpmb",     /* m_name */
35     rpmb__doc__, /* m_doc */
36     0,           /* m_size */
37     NULL,        /* m_methods */
38     NULL,        /* m_reload */
39     NULL,        /* m_traverse */
40     NULL,        /* m_clear */
41     NULL         /* m_free */
42 };
43
44 PyObject * PyInit__rpm(void);   /* XXX eliminate gcc warning */
45 PyObject * PyInit__rpm(void)
46 {
47     PyObject *m;
48
49     if (!prepareInitModule())
50         return NULL;
51     m = PyModule_Create(&moduledef);
52     if (m == NULL || !initModule(m)) {
53         Py_XDECREF(m);
54         m = NULL;
55     }
56     return m;
57 }
58 #else
59 void init_rpmb(void);   /* XXX eliminate gcc warning */
60 void init_rpmb(void)
61 {
62     PyObject *m;
63   
64     if (!prepareInitModule())
65         return;
66
67     m = Py_InitModule3("_rpmb", NULL, rpmb__doc__);
68     if (m) initModule(m);
69 }
70 #endif