xref: /third_party/python/Include/moduleobject.h (revision 7db96d56)
1
2/* Module object interface */
3
4#ifndef Py_MODULEOBJECT_H
5#define Py_MODULEOBJECT_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10PyAPI_DATA(PyTypeObject) PyModule_Type;
11
12#define PyModule_Check(op) PyObject_TypeCheck(op, &PyModule_Type)
13#define PyModule_CheckExact(op) Py_IS_TYPE(op, &PyModule_Type)
14
15#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
16PyAPI_FUNC(PyObject *) PyModule_NewObject(
17    PyObject *name
18    );
19#endif
20PyAPI_FUNC(PyObject *) PyModule_New(
21    const char *name            /* UTF-8 encoded string */
22    );
23PyAPI_FUNC(PyObject *) PyModule_GetDict(PyObject *);
24#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
25PyAPI_FUNC(PyObject *) PyModule_GetNameObject(PyObject *);
26#endif
27PyAPI_FUNC(const char *) PyModule_GetName(PyObject *);
28Py_DEPRECATED(3.2) PyAPI_FUNC(const char *) PyModule_GetFilename(PyObject *);
29PyAPI_FUNC(PyObject *) PyModule_GetFilenameObject(PyObject *);
30#ifndef Py_LIMITED_API
31PyAPI_FUNC(void) _PyModule_Clear(PyObject *);
32PyAPI_FUNC(void) _PyModule_ClearDict(PyObject *);
33PyAPI_FUNC(int) _PyModuleSpec_IsInitializing(PyObject *);
34#endif
35PyAPI_FUNC(PyModuleDef*) PyModule_GetDef(PyObject*);
36PyAPI_FUNC(void*) PyModule_GetState(PyObject*);
37
38#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
39/* New in 3.5 */
40PyAPI_FUNC(PyObject *) PyModuleDef_Init(PyModuleDef*);
41PyAPI_DATA(PyTypeObject) PyModuleDef_Type;
42#endif
43
44typedef struct PyModuleDef_Base {
45  PyObject_HEAD
46  PyObject* (*m_init)(void);
47  Py_ssize_t m_index;
48  PyObject* m_copy;
49} PyModuleDef_Base;
50
51#define PyModuleDef_HEAD_INIT {  \
52    PyObject_HEAD_INIT(_Py_NULL) \
53    _Py_NULL, /* m_init */       \
54    0,        /* m_index */      \
55    _Py_NULL, /* m_copy */       \
56  }
57
58#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
59/* New in 3.5 */
60struct PyModuleDef_Slot {
61    int slot;
62    void *value;
63};
64
65#define Py_mod_create 1
66#define Py_mod_exec 2
67
68#ifndef Py_LIMITED_API
69#define _Py_mod_LAST_SLOT 2
70#endif
71
72#endif /* New in 3.5 */
73
74struct PyModuleDef {
75  PyModuleDef_Base m_base;
76  const char* m_name;
77  const char* m_doc;
78  Py_ssize_t m_size;
79  PyMethodDef *m_methods;
80  PyModuleDef_Slot *m_slots;
81  traverseproc m_traverse;
82  inquiry m_clear;
83  freefunc m_free;
84};
85
86
87// Internal C API
88#ifdef Py_BUILD_CORE
89extern int _PyModule_IsExtension(PyObject *obj);
90#endif
91
92#ifdef __cplusplus
93}
94#endif
95#endif /* !Py_MODULEOBJECT_H */
96