Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Include/moduleobject.h
12 views
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
#ifndef Py_LIMITED_API
31
PyAPI_FUNC(void) _PyModule_Clear(PyObject *);
32
PyAPI_FUNC(void) _PyModule_ClearDict(PyObject *);
33
PyAPI_FUNC(int) _PyModuleSpec_IsInitializing(PyObject *);
34
#endif
35
PyAPI_FUNC(PyModuleDef*) PyModule_GetDef(PyObject*);
36
PyAPI_FUNC(void*) PyModule_GetState(PyObject*);
37
38
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
39
/* New in 3.5 */
40
PyAPI_FUNC(PyObject *) PyModuleDef_Init(PyModuleDef*);
41
PyAPI_DATA(PyTypeObject) PyModuleDef_Type;
42
#endif
43
44
typedef struct PyModuleDef_Base {
45
PyObject_HEAD
46
/* The function used to re-initialize the module.
47
This is only set for legacy (single-phase init) extension modules
48
and only used for those that support multiple initializations
49
(m_size >= 0).
50
It is set by _PyImport_LoadDynamicModuleWithSpec()
51
and _imp.create_builtin(). */
52
PyObject* (*m_init)(void);
53
/* The module's index into its interpreter's modules_by_index cache.
54
This is set for all extension modules but only used for legacy ones.
55
(See PyInterpreterState.modules_by_index for more info.)
56
It is set by PyModuleDef_Init(). */
57
Py_ssize_t m_index;
58
/* A copy of the module's __dict__ after the first time it was loaded.
59
This is only set/used for legacy modules that do not support
60
multiple initializations.
61
It is set by _PyImport_FixupExtensionObject(). */
62
PyObject* m_copy;
63
} PyModuleDef_Base;
64
65
#define PyModuleDef_HEAD_INIT { \
66
PyObject_HEAD_INIT(_Py_NULL) \
67
_Py_NULL, /* m_init */ \
68
0, /* m_index */ \
69
_Py_NULL, /* m_copy */ \
70
}
71
72
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
73
/* New in 3.5 */
74
struct PyModuleDef_Slot {
75
int slot;
76
void *value;
77
};
78
79
#define Py_mod_create 1
80
#define Py_mod_exec 2
81
#define Py_mod_multiple_interpreters 3
82
83
#ifndef Py_LIMITED_API
84
#define _Py_mod_LAST_SLOT 3
85
#endif
86
87
/* for Py_mod_multiple_interpreters: */
88
#define Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED ((void *)0)
89
#define Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED ((void *)1)
90
#define Py_MOD_PER_INTERPRETER_GIL_SUPPORTED ((void *)2)
91
92
#endif /* New in 3.5 */
93
94
struct PyModuleDef {
95
PyModuleDef_Base m_base;
96
const char* m_name;
97
const char* m_doc;
98
Py_ssize_t m_size;
99
PyMethodDef *m_methods;
100
PyModuleDef_Slot *m_slots;
101
traverseproc m_traverse;
102
inquiry m_clear;
103
freefunc m_free;
104
};
105
106
107
// Internal C API
108
#ifdef Py_BUILD_CORE
109
extern int _PyModule_IsExtension(PyObject *obj);
110
#endif
111
112
#ifdef __cplusplus
113
}
114
#endif
115
#endif /* !Py_MODULEOBJECT_H */
116
117