modsupport.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #ifndef Py_MODSUPPORT_H
  2. #define Py_MODSUPPORT_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /* Module support interface */
  7. #include <stdarg.h> // va_list
  8. /* If PY_SSIZE_T_CLEAN is defined, each functions treats #-specifier
  9. to mean Py_ssize_t */
  10. #ifdef PY_SSIZE_T_CLEAN
  11. #define PyArg_Parse _PyArg_Parse_SizeT
  12. #define PyArg_ParseTuple _PyArg_ParseTuple_SizeT
  13. #define PyArg_ParseTupleAndKeywords _PyArg_ParseTupleAndKeywords_SizeT
  14. #define PyArg_VaParse _PyArg_VaParse_SizeT
  15. #define PyArg_VaParseTupleAndKeywords _PyArg_VaParseTupleAndKeywords_SizeT
  16. #define Py_BuildValue _Py_BuildValue_SizeT
  17. #define Py_VaBuildValue _Py_VaBuildValue_SizeT
  18. #endif
  19. /* Due to a glitch in 3.2, the _SizeT versions weren't exported from the DLL. */
  20. #if !defined(PY_SSIZE_T_CLEAN) || !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
  21. PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...);
  22. PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...);
  23. PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
  24. const char *, char **, ...);
  25. PyAPI_FUNC(int) PyArg_VaParse(PyObject *, const char *, va_list);
  26. PyAPI_FUNC(int) PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *,
  27. const char *, char **, va_list);
  28. #endif
  29. PyAPI_FUNC(int) PyArg_ValidateKeywordArguments(PyObject *);
  30. PyAPI_FUNC(int) PyArg_UnpackTuple(PyObject *, const char *, Py_ssize_t, Py_ssize_t, ...);
  31. PyAPI_FUNC(PyObject *) Py_BuildValue(const char *, ...);
  32. PyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...);
  33. PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list);
  34. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030a0000
  35. // Add an attribute with name 'name' and value 'obj' to the module 'mod.
  36. // On success, return 0 on success.
  37. // On error, raise an exception and return -1.
  38. PyAPI_FUNC(int) PyModule_AddObjectRef(PyObject *mod, const char *name, PyObject *value);
  39. #endif /* Py_LIMITED_API */
  40. // Similar to PyModule_AddObjectRef() but steal a reference to 'obj'
  41. // (Py_DECREF(obj)) on success (if it returns 0).
  42. PyAPI_FUNC(int) PyModule_AddObject(PyObject *mod, const char *, PyObject *value);
  43. PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long);
  44. PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char *);
  45. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
  46. /* New in 3.9 */
  47. PyAPI_FUNC(int) PyModule_AddType(PyObject *module, PyTypeObject *type);
  48. #endif /* Py_LIMITED_API */
  49. #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant((m), #c, (c))
  50. #define PyModule_AddStringMacro(m, c) PyModule_AddStringConstant((m), #c, (c))
  51. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
  52. /* New in 3.5 */
  53. PyAPI_FUNC(int) PyModule_SetDocString(PyObject *, const char *);
  54. PyAPI_FUNC(int) PyModule_AddFunctions(PyObject *, PyMethodDef *);
  55. PyAPI_FUNC(int) PyModule_ExecDef(PyObject *module, PyModuleDef *def);
  56. #endif
  57. #define Py_CLEANUP_SUPPORTED 0x20000
  58. #define PYTHON_API_VERSION 1013
  59. #define PYTHON_API_STRING "1013"
  60. /* The API version is maintained (independently from the Python version)
  61. so we can detect mismatches between the interpreter and dynamically
  62. loaded modules. These are diagnosed by an error message but
  63. the module is still loaded (because the mismatch can only be tested
  64. after loading the module). The error message is intended to
  65. explain the core dump a few seconds later.
  66. The symbol PYTHON_API_STRING defines the same value as a string
  67. literal. *** PLEASE MAKE SURE THE DEFINITIONS MATCH. ***
  68. Please add a line or two to the top of this log for each API
  69. version change:
  70. 22-Feb-2006 MvL 1013 PEP 353 - long indices for sequence lengths
  71. 19-Aug-2002 GvR 1012 Changes to string object struct for
  72. interning changes, saving 3 bytes.
  73. 17-Jul-2001 GvR 1011 Descr-branch, just to be on the safe side
  74. 25-Jan-2001 FLD 1010 Parameters added to PyCode_New() and
  75. PyFrame_New(); Python 2.1a2
  76. 14-Mar-2000 GvR 1009 Unicode API added
  77. 3-Jan-1999 GvR 1007 Decided to change back! (Don't reuse 1008!)
  78. 3-Dec-1998 GvR 1008 Python 1.5.2b1
  79. 18-Jan-1997 GvR 1007 string interning and other speedups
  80. 11-Oct-1996 GvR renamed Py_Ellipses to Py_Ellipsis :-(
  81. 30-Jul-1996 GvR Slice and ellipses syntax added
  82. 23-Jul-1996 GvR For 1.4 -- better safe than sorry this time :-)
  83. 7-Nov-1995 GvR Keyword arguments (should've been done at 1.3 :-( )
  84. 10-Jan-1995 GvR Renamed globals to new naming scheme
  85. 9-Jan-1995 GvR Initial version (incompatible with older API)
  86. */
  87. /* The PYTHON_ABI_VERSION is introduced in PEP 384. For the lifetime of
  88. Python 3, it will stay at the value of 3; changes to the limited API
  89. must be performed in a strictly backwards-compatible manner. */
  90. #define PYTHON_ABI_VERSION 3
  91. #define PYTHON_ABI_STRING "3"
  92. #ifdef Py_TRACE_REFS
  93. /* When we are tracing reference counts, rename module creation functions so
  94. modules compiled with incompatible settings will generate a
  95. link-time error. */
  96. #define PyModule_Create2 PyModule_Create2TraceRefs
  97. #define PyModule_FromDefAndSpec2 PyModule_FromDefAndSpec2TraceRefs
  98. #endif
  99. PyAPI_FUNC(PyObject *) PyModule_Create2(PyModuleDef*, int apiver);
  100. #ifdef Py_LIMITED_API
  101. #define PyModule_Create(module) \
  102. PyModule_Create2((module), PYTHON_ABI_VERSION)
  103. #else
  104. #define PyModule_Create(module) \
  105. PyModule_Create2((module), PYTHON_API_VERSION)
  106. #endif
  107. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
  108. /* New in 3.5 */
  109. PyAPI_FUNC(PyObject *) PyModule_FromDefAndSpec2(PyModuleDef *def,
  110. PyObject *spec,
  111. int module_api_version);
  112. #ifdef Py_LIMITED_API
  113. #define PyModule_FromDefAndSpec(module, spec) \
  114. PyModule_FromDefAndSpec2((module), (spec), PYTHON_ABI_VERSION)
  115. #else
  116. #define PyModule_FromDefAndSpec(module, spec) \
  117. PyModule_FromDefAndSpec2((module), (spec), PYTHON_API_VERSION)
  118. #endif /* Py_LIMITED_API */
  119. #endif /* New in 3.5 */
  120. #ifndef Py_LIMITED_API
  121. # define Py_CPYTHON_MODSUPPORT_H
  122. # include "cpython/modsupport.h"
  123. # undef Py_CPYTHON_MODSUPPORT_H
  124. #endif
  125. #ifdef __cplusplus
  126. }
  127. #endif
  128. #endif /* !Py_MODSUPPORT_H */