modsupport.h 9.4 KB

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