moduleobject.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* Module object interface */
  2. #ifndef Py_MODULEOBJECT_H
  3. #define Py_MODULEOBJECT_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. PyAPI_DATA(PyTypeObject) PyModule_Type;
  8. #define PyModule_Check(op) PyObject_TypeCheck((op), &PyModule_Type)
  9. #define PyModule_CheckExact(op) Py_IS_TYPE((op), &PyModule_Type)
  10. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
  11. PyAPI_FUNC(PyObject *) PyModule_NewObject(
  12. PyObject *name
  13. );
  14. #endif
  15. PyAPI_FUNC(PyObject *) PyModule_New(
  16. const char *name /* UTF-8 encoded string */
  17. );
  18. PyAPI_FUNC(PyObject *) PyModule_GetDict(PyObject *);
  19. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
  20. PyAPI_FUNC(PyObject *) PyModule_GetNameObject(PyObject *);
  21. #endif
  22. PyAPI_FUNC(const char *) PyModule_GetName(PyObject *);
  23. Py_DEPRECATED(3.2) PyAPI_FUNC(const char *) PyModule_GetFilename(PyObject *);
  24. PyAPI_FUNC(PyObject *) PyModule_GetFilenameObject(PyObject *);
  25. #ifndef Py_LIMITED_API
  26. PyAPI_FUNC(void) _PyModule_Clear(PyObject *);
  27. PyAPI_FUNC(void) _PyModule_ClearDict(PyObject *);
  28. PyAPI_FUNC(int) _PyModuleSpec_IsInitializing(PyObject *);
  29. #endif
  30. PyAPI_FUNC(PyModuleDef*) PyModule_GetDef(PyObject*);
  31. PyAPI_FUNC(void*) PyModule_GetState(PyObject*);
  32. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
  33. /* New in 3.5 */
  34. PyAPI_FUNC(PyObject *) PyModuleDef_Init(PyModuleDef*);
  35. PyAPI_DATA(PyTypeObject) PyModuleDef_Type;
  36. #endif
  37. typedef struct PyModuleDef_Base {
  38. PyObject_HEAD
  39. /* The function used to re-initialize the module.
  40. This is only set for legacy (single-phase init) extension modules
  41. and only used for those that support multiple initializations
  42. (m_size >= 0).
  43. It is set by _PyImport_LoadDynamicModuleWithSpec()
  44. and _imp.create_builtin(). */
  45. PyObject* (*m_init)(void);
  46. /* The module's index into its interpreter's modules_by_index cache.
  47. This is set for all extension modules but only used for legacy ones.
  48. (See PyInterpreterState.modules_by_index for more info.)
  49. It is set by PyModuleDef_Init(). */
  50. Py_ssize_t m_index;
  51. /* A copy of the module's __dict__ after the first time it was loaded.
  52. This is only set/used for legacy modules that do not support
  53. multiple initializations.
  54. It is set by _PyImport_FixupExtensionObject(). */
  55. PyObject* m_copy;
  56. } PyModuleDef_Base;
  57. #define PyModuleDef_HEAD_INIT { \
  58. PyObject_HEAD_INIT(_Py_NULL) \
  59. _Py_NULL, /* m_init */ \
  60. 0, /* m_index */ \
  61. _Py_NULL, /* m_copy */ \
  62. }
  63. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
  64. /* New in 3.5 */
  65. struct PyModuleDef_Slot {
  66. int slot;
  67. void *value;
  68. };
  69. #define Py_mod_create 1
  70. #define Py_mod_exec 2
  71. #define Py_mod_multiple_interpreters 3
  72. #ifndef Py_LIMITED_API
  73. #define _Py_mod_LAST_SLOT 3
  74. #endif
  75. /* for Py_mod_multiple_interpreters: */
  76. #define Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED ((void *)0)
  77. #define Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED ((void *)1)
  78. #define Py_MOD_PER_INTERPRETER_GIL_SUPPORTED ((void *)2)
  79. #endif /* New in 3.5 */
  80. struct PyModuleDef {
  81. PyModuleDef_Base m_base;
  82. const char* m_name;
  83. const char* m_doc;
  84. Py_ssize_t m_size;
  85. PyMethodDef *m_methods;
  86. PyModuleDef_Slot *m_slots;
  87. traverseproc m_traverse;
  88. inquiry m_clear;
  89. freefunc m_free;
  90. };
  91. // Internal C API
  92. #ifdef Py_BUILD_CORE
  93. extern int _PyModule_IsExtension(PyObject *obj);
  94. #endif
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. #endif /* !Py_MODULEOBJECT_H */