• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /* Module object interface */
3 
4 #ifndef Py_MODULEOBJECT_H
5 #define Py_MODULEOBJECT_H
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 PyAPI_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
16 PyAPI_FUNC(PyObject *) PyModule_NewObject(
17     PyObject *name
18     );
19 #endif
20 PyAPI_FUNC(PyObject *) PyModule_New(
21     const char *name            /* UTF-8 encoded string */
22     );
23 PyAPI_FUNC(PyObject *) PyModule_GetDict(PyObject *);
24 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
25 PyAPI_FUNC(PyObject *) PyModule_GetNameObject(PyObject *);
26 #endif
27 PyAPI_FUNC(const char *) PyModule_GetName(PyObject *);
28 Py_DEPRECATED(3.2) PyAPI_FUNC(const char *) PyModule_GetFilename(PyObject *);
29 PyAPI_FUNC(PyObject *) PyModule_GetFilenameObject(PyObject *);
30 PyAPI_FUNC(PyModuleDef*) PyModule_GetDef(PyObject*);
31 PyAPI_FUNC(void*) PyModule_GetState(PyObject*);
32 
33 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
34 /* New in 3.5 */
35 PyAPI_FUNC(PyObject *) PyModuleDef_Init(PyModuleDef*);
36 PyAPI_DATA(PyTypeObject) PyModuleDef_Type;
37 #endif
38 
39 typedef struct PyModuleDef_Base {
40   PyObject_HEAD
41   /* The function used to re-initialize the module.
42      This is only set for legacy (single-phase init) extension modules
43      and only used for those that support multiple initializations
44      (m_size >= 0).
45      It is set by _PyImport_LoadDynamicModuleWithSpec()
46      and _imp.create_builtin(). */
47   PyObject* (*m_init)(void);
48   /* The module's index into its interpreter's modules_by_index cache.
49      This is set for all extension modules but only used for legacy ones.
50      (See PyInterpreterState.modules_by_index for more info.)
51      It is set by PyModuleDef_Init(). */
52   Py_ssize_t m_index;
53   /* A copy of the module's __dict__ after the first time it was loaded.
54      This is only set/used for legacy modules that do not support
55      multiple initializations.
56      It is set by fix_up_extension() in import.c. */
57   PyObject* m_copy;
58 } PyModuleDef_Base;
59 
60 #define PyModuleDef_HEAD_INIT {  \
61     PyObject_HEAD_INIT(_Py_NULL) \
62     _Py_NULL, /* m_init */       \
63     0,        /* m_index */      \
64     _Py_NULL, /* m_copy */       \
65   }
66 
67 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
68 /* New in 3.5 */
69 struct PyModuleDef_Slot {
70     int slot;
71     void *value;
72 };
73 
74 #define Py_mod_create 1
75 #define Py_mod_exec 2
76 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030c0000
77 #  define Py_mod_multiple_interpreters 3
78 #endif
79 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
80 #  define Py_mod_gil 4
81 #endif
82 
83 
84 #ifndef Py_LIMITED_API
85 #define _Py_mod_LAST_SLOT 4
86 #endif
87 
88 #endif /* New in 3.5 */
89 
90 /* for Py_mod_multiple_interpreters: */
91 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030c0000
92 #  define Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED ((void *)0)
93 #  define Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED ((void *)1)
94 #  define Py_MOD_PER_INTERPRETER_GIL_SUPPORTED ((void *)2)
95 #endif
96 
97 /* for Py_mod_gil: */
98 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
99 #  define Py_MOD_GIL_USED ((void *)0)
100 #  define Py_MOD_GIL_NOT_USED ((void *)1)
101 #endif
102 
103 #if !defined(Py_LIMITED_API) && defined(Py_GIL_DISABLED)
104 PyAPI_FUNC(int) PyUnstable_Module_SetGIL(PyObject *module, void *gil);
105 #endif
106 
107 struct PyModuleDef {
108   PyModuleDef_Base m_base;
109   const char* m_name;
110   const char* m_doc;
111   Py_ssize_t m_size;
112   PyMethodDef *m_methods;
113   PyModuleDef_Slot *m_slots;
114   traverseproc m_traverse;
115   inquiry m_clear;
116   freefunc m_free;
117 };
118 
119 #ifdef __cplusplus
120 }
121 #endif
122 #endif /* !Py_MODULEOBJECT_H */
123