modsupport.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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>
  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. #ifndef Py_LIMITED_API
  19. #define _Py_VaBuildStack _Py_VaBuildStack_SizeT
  20. #endif
  21. #else
  22. #ifndef Py_LIMITED_API
  23. PyAPI_FUNC(PyObject *) _Py_VaBuildValue_SizeT(const char *, va_list);
  24. PyAPI_FUNC(PyObject **) _Py_VaBuildStack_SizeT(
  25. PyObject **small_stack,
  26. Py_ssize_t small_stack_len,
  27. const char *format,
  28. va_list va,
  29. Py_ssize_t *p_nargs);
  30. #endif /* !Py_LIMITED_API */
  31. #endif
  32. /* Due to a glitch in 3.2, the _SizeT versions weren't exported from the DLL. */
  33. #if !defined(PY_SSIZE_T_CLEAN) || !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
  34. PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...);
  35. PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...);
  36. PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
  37. const char *, char **, ...);
  38. PyAPI_FUNC(int) PyArg_VaParse(PyObject *, const char *, va_list);
  39. PyAPI_FUNC(int) PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *,
  40. const char *, char **, va_list);
  41. #endif
  42. PyAPI_FUNC(int) PyArg_ValidateKeywordArguments(PyObject *);
  43. PyAPI_FUNC(int) PyArg_UnpackTuple(PyObject *, const char *, Py_ssize_t, Py_ssize_t, ...);
  44. PyAPI_FUNC(PyObject *) Py_BuildValue(const char *, ...);
  45. PyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...);
  46. #ifndef Py_LIMITED_API
  47. PyAPI_FUNC(int) _PyArg_UnpackStack(
  48. PyObject *const *args,
  49. Py_ssize_t nargs,
  50. const char *name,
  51. Py_ssize_t min,
  52. Py_ssize_t max,
  53. ...);
  54. PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kwargs);
  55. PyAPI_FUNC(int) _PyArg_NoKwnames(const char *funcname, PyObject *kwnames);
  56. PyAPI_FUNC(int) _PyArg_NoPositional(const char *funcname, PyObject *args);
  57. #define _PyArg_NoKeywords(funcname, kwargs) \
  58. ((kwargs) == NULL || _PyArg_NoKeywords((funcname), (kwargs)))
  59. #define _PyArg_NoKwnames(funcname, kwnames) \
  60. ((kwnames) == NULL || _PyArg_NoKwnames((funcname), (kwnames)))
  61. #define _PyArg_NoPositional(funcname, args) \
  62. ((args) == NULL || _PyArg_NoPositional((funcname), (args)))
  63. PyAPI_FUNC(void) _PyArg_BadArgument(const char *, const char *, const char *, PyObject *);
  64. PyAPI_FUNC(int) _PyArg_CheckPositional(const char *, Py_ssize_t,
  65. Py_ssize_t, Py_ssize_t);
  66. #define _PyArg_CheckPositional(funcname, nargs, min, max) \
  67. (((min) <= (nargs) && (nargs) <= (max)) \
  68. || _PyArg_CheckPositional((funcname), (nargs), (min), (max)))
  69. #endif
  70. PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list);
  71. #ifndef Py_LIMITED_API
  72. PyAPI_FUNC(PyObject **) _Py_VaBuildStack(
  73. PyObject **small_stack,
  74. Py_ssize_t small_stack_len,
  75. const char *format,
  76. va_list va,
  77. Py_ssize_t *p_nargs);
  78. #endif
  79. #ifndef Py_LIMITED_API
  80. typedef struct _PyArg_Parser {
  81. const char *format;
  82. const char * const *keywords;
  83. const char *fname;
  84. const char *custom_msg;
  85. int pos; /* number of positional-only arguments */
  86. int min; /* minimal number of arguments */
  87. int max; /* maximal number of positional arguments */
  88. PyObject *kwtuple; /* tuple of keyword parameter names */
  89. struct _PyArg_Parser *next;
  90. } _PyArg_Parser;
  91. #ifdef PY_SSIZE_T_CLEAN
  92. #define _PyArg_ParseTupleAndKeywordsFast _PyArg_ParseTupleAndKeywordsFast_SizeT
  93. #define _PyArg_ParseStack _PyArg_ParseStack_SizeT
  94. #define _PyArg_ParseStackAndKeywords _PyArg_ParseStackAndKeywords_SizeT
  95. #define _PyArg_VaParseTupleAndKeywordsFast _PyArg_VaParseTupleAndKeywordsFast_SizeT
  96. #endif
  97. PyAPI_FUNC(int) _PyArg_ParseTupleAndKeywordsFast(PyObject *, PyObject *,
  98. struct _PyArg_Parser *, ...);
  99. PyAPI_FUNC(int) _PyArg_ParseStack(
  100. PyObject *const *args,
  101. Py_ssize_t nargs,
  102. const char *format,
  103. ...);
  104. PyAPI_FUNC(int) _PyArg_ParseStackAndKeywords(
  105. PyObject *const *args,
  106. Py_ssize_t nargs,
  107. PyObject *kwnames,
  108. struct _PyArg_Parser *,
  109. ...);
  110. PyAPI_FUNC(int) _PyArg_VaParseTupleAndKeywordsFast(PyObject *, PyObject *,
  111. struct _PyArg_Parser *, va_list);
  112. PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywords(
  113. PyObject *const *args, Py_ssize_t nargs,
  114. PyObject *kwargs, PyObject *kwnames,
  115. struct _PyArg_Parser *parser,
  116. int minpos, int maxpos, int minkw,
  117. PyObject **buf);
  118. #define _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, parser, minpos, maxpos, minkw, buf) \
  119. (((minkw) == 0 && (kwargs) == NULL && (kwnames) == NULL && \
  120. (minpos) <= (nargs) && (nargs) <= (maxpos) && args != NULL) ? (args) : \
  121. _PyArg_UnpackKeywords((args), (nargs), (kwargs), (kwnames), (parser), \
  122. (minpos), (maxpos), (minkw), (buf)))
  123. void _PyArg_Fini(void);
  124. #endif /* Py_LIMITED_API */
  125. PyAPI_FUNC(int) PyModule_AddObject(PyObject *, const char *, PyObject *);
  126. PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long);
  127. PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char *);
  128. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
  129. /* New in 3.9 */
  130. PyAPI_FUNC(int) PyModule_AddType(PyObject *module, PyTypeObject *type);
  131. #endif /* Py_LIMITED_API */
  132. #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)
  133. #define PyModule_AddStringMacro(m, c) PyModule_AddStringConstant(m, #c, c)
  134. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
  135. /* New in 3.5 */
  136. PyAPI_FUNC(int) PyModule_SetDocString(PyObject *, const char *);
  137. PyAPI_FUNC(int) PyModule_AddFunctions(PyObject *, PyMethodDef *);
  138. PyAPI_FUNC(int) PyModule_ExecDef(PyObject *module, PyModuleDef *def);
  139. #endif
  140. #define Py_CLEANUP_SUPPORTED 0x20000
  141. #define PYTHON_API_VERSION 1013
  142. #define PYTHON_API_STRING "1013"
  143. /* The API version is maintained (independently from the Python version)
  144. so we can detect mismatches between the interpreter and dynamically
  145. loaded modules. These are diagnosed by an error message but
  146. the module is still loaded (because the mismatch can only be tested
  147. after loading the module). The error message is intended to
  148. explain the core dump a few seconds later.
  149. The symbol PYTHON_API_STRING defines the same value as a string
  150. literal. *** PLEASE MAKE SURE THE DEFINITIONS MATCH. ***
  151. Please add a line or two to the top of this log for each API
  152. version change:
  153. 22-Feb-2006 MvL 1013 PEP 353 - long indices for sequence lengths
  154. 19-Aug-2002 GvR 1012 Changes to string object struct for
  155. interning changes, saving 3 bytes.
  156. 17-Jul-2001 GvR 1011 Descr-branch, just to be on the safe side
  157. 25-Jan-2001 FLD 1010 Parameters added to PyCode_New() and
  158. PyFrame_New(); Python 2.1a2
  159. 14-Mar-2000 GvR 1009 Unicode API added
  160. 3-Jan-1999 GvR 1007 Decided to change back! (Don't reuse 1008!)
  161. 3-Dec-1998 GvR 1008 Python 1.5.2b1
  162. 18-Jan-1997 GvR 1007 string interning and other speedups
  163. 11-Oct-1996 GvR renamed Py_Ellipses to Py_Ellipsis :-(
  164. 30-Jul-1996 GvR Slice and ellipses syntax added
  165. 23-Jul-1996 GvR For 1.4 -- better safe than sorry this time :-)
  166. 7-Nov-1995 GvR Keyword arguments (should've been done at 1.3 :-( )
  167. 10-Jan-1995 GvR Renamed globals to new naming scheme
  168. 9-Jan-1995 GvR Initial version (incompatible with older API)
  169. */
  170. /* The PYTHON_ABI_VERSION is introduced in PEP 384. For the lifetime of
  171. Python 3, it will stay at the value of 3; changes to the limited API
  172. must be performed in a strictly backwards-compatible manner. */
  173. #define PYTHON_ABI_VERSION 3
  174. #define PYTHON_ABI_STRING "3"
  175. #ifdef Py_TRACE_REFS
  176. /* When we are tracing reference counts, rename module creation functions so
  177. modules compiled with incompatible settings will generate a
  178. link-time error. */
  179. #define PyModule_Create2 PyModule_Create2TraceRefs
  180. #define PyModule_FromDefAndSpec2 PyModule_FromDefAndSpec2TraceRefs
  181. #endif
  182. PyAPI_FUNC(PyObject *) PyModule_Create2(struct PyModuleDef*,
  183. int apiver);
  184. #ifndef Py_LIMITED_API
  185. PyAPI_FUNC(PyObject *) _PyModule_CreateInitialized(struct PyModuleDef*,
  186. int apiver);
  187. #endif
  188. #ifdef Py_LIMITED_API
  189. #define PyModule_Create(module) \
  190. PyModule_Create2(module, PYTHON_ABI_VERSION)
  191. #else
  192. #define PyModule_Create(module) \
  193. PyModule_Create2(module, PYTHON_API_VERSION)
  194. #endif
  195. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
  196. /* New in 3.5 */
  197. PyAPI_FUNC(PyObject *) PyModule_FromDefAndSpec2(PyModuleDef *def,
  198. PyObject *spec,
  199. int module_api_version);
  200. #ifdef Py_LIMITED_API
  201. #define PyModule_FromDefAndSpec(module, spec) \
  202. PyModule_FromDefAndSpec2(module, spec, PYTHON_ABI_VERSION)
  203. #else
  204. #define PyModule_FromDefAndSpec(module, spec) \
  205. PyModule_FromDefAndSpec2(module, spec, PYTHON_API_VERSION)
  206. #endif /* Py_LIMITED_API */
  207. #endif /* New in 3.5 */
  208. #ifndef Py_LIMITED_API
  209. PyAPI_DATA(const char *) _Py_PackageContext;
  210. #endif
  211. #ifdef __cplusplus
  212. }
  213. #endif
  214. #endif /* !Py_MODSUPPORT_H */