modsupport.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef Py_CPYTHON_MODSUPPORT_H
  2. # error "this header file must not be included directly"
  3. #endif
  4. /* If PY_SSIZE_T_CLEAN is defined, each functions treats #-specifier
  5. to mean Py_ssize_t */
  6. #ifdef PY_SSIZE_T_CLEAN
  7. #define _Py_VaBuildStack _Py_VaBuildStack_SizeT
  8. #else
  9. PyAPI_FUNC(PyObject *) _Py_VaBuildValue_SizeT(const char *, va_list);
  10. PyAPI_FUNC(PyObject **) _Py_VaBuildStack_SizeT(
  11. PyObject **small_stack,
  12. Py_ssize_t small_stack_len,
  13. const char *format,
  14. va_list va,
  15. Py_ssize_t *p_nargs);
  16. #endif
  17. PyAPI_FUNC(int) _PyArg_UnpackStack(
  18. PyObject *const *args,
  19. Py_ssize_t nargs,
  20. const char *name,
  21. Py_ssize_t min,
  22. Py_ssize_t max,
  23. ...);
  24. PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kwargs);
  25. PyAPI_FUNC(int) _PyArg_NoKwnames(const char *funcname, PyObject *kwnames);
  26. PyAPI_FUNC(int) _PyArg_NoPositional(const char *funcname, PyObject *args);
  27. #define _PyArg_NoKeywords(funcname, kwargs) \
  28. ((kwargs) == NULL || _PyArg_NoKeywords((funcname), (kwargs)))
  29. #define _PyArg_NoKwnames(funcname, kwnames) \
  30. ((kwnames) == NULL || _PyArg_NoKwnames((funcname), (kwnames)))
  31. #define _PyArg_NoPositional(funcname, args) \
  32. ((args) == NULL || _PyArg_NoPositional((funcname), (args)))
  33. #define _Py_ANY_VARARGS(n) ((n) == PY_SSIZE_T_MAX)
  34. PyAPI_FUNC(void) _PyArg_BadArgument(const char *, const char *, const char *, PyObject *);
  35. PyAPI_FUNC(int) _PyArg_CheckPositional(const char *, Py_ssize_t,
  36. Py_ssize_t, Py_ssize_t);
  37. #define _PyArg_CheckPositional(funcname, nargs, min, max) \
  38. ((!_Py_ANY_VARARGS(max) && (min) <= (nargs) && (nargs) <= (max)) \
  39. || _PyArg_CheckPositional((funcname), (nargs), (min), (max)))
  40. PyAPI_FUNC(PyObject **) _Py_VaBuildStack(
  41. PyObject **small_stack,
  42. Py_ssize_t small_stack_len,
  43. const char *format,
  44. va_list va,
  45. Py_ssize_t *p_nargs);
  46. typedef struct _PyArg_Parser {
  47. int initialized;
  48. const char *format;
  49. const char * const *keywords;
  50. const char *fname;
  51. const char *custom_msg;
  52. int pos; /* number of positional-only arguments */
  53. int min; /* minimal number of arguments */
  54. int max; /* maximal number of positional arguments */
  55. PyObject *kwtuple; /* tuple of keyword parameter names */
  56. struct _PyArg_Parser *next;
  57. } _PyArg_Parser;
  58. #ifdef PY_SSIZE_T_CLEAN
  59. #define _PyArg_ParseTupleAndKeywordsFast _PyArg_ParseTupleAndKeywordsFast_SizeT
  60. #define _PyArg_ParseStack _PyArg_ParseStack_SizeT
  61. #define _PyArg_ParseStackAndKeywords _PyArg_ParseStackAndKeywords_SizeT
  62. #define _PyArg_VaParseTupleAndKeywordsFast _PyArg_VaParseTupleAndKeywordsFast_SizeT
  63. #endif
  64. PyAPI_FUNC(int) _PyArg_ParseTupleAndKeywordsFast(PyObject *, PyObject *,
  65. struct _PyArg_Parser *, ...);
  66. PyAPI_FUNC(int) _PyArg_ParseStack(
  67. PyObject *const *args,
  68. Py_ssize_t nargs,
  69. const char *format,
  70. ...);
  71. PyAPI_FUNC(int) _PyArg_ParseStackAndKeywords(
  72. PyObject *const *args,
  73. Py_ssize_t nargs,
  74. PyObject *kwnames,
  75. struct _PyArg_Parser *,
  76. ...);
  77. PyAPI_FUNC(int) _PyArg_VaParseTupleAndKeywordsFast(PyObject *, PyObject *,
  78. struct _PyArg_Parser *, va_list);
  79. PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywords(
  80. PyObject *const *args, Py_ssize_t nargs,
  81. PyObject *kwargs, PyObject *kwnames,
  82. struct _PyArg_Parser *parser,
  83. int minpos, int maxpos, int minkw,
  84. PyObject **buf);
  85. PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywordsWithVararg(
  86. PyObject *const *args, Py_ssize_t nargs,
  87. PyObject *kwargs, PyObject *kwnames,
  88. struct _PyArg_Parser *parser,
  89. int minpos, int maxpos, int minkw,
  90. int vararg, PyObject **buf);
  91. #define _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, parser, minpos, maxpos, minkw, buf) \
  92. (((minkw) == 0 && (kwargs) == NULL && (kwnames) == NULL && \
  93. (minpos) <= (nargs) && (nargs) <= (maxpos) && (args) != NULL) ? (args) : \
  94. _PyArg_UnpackKeywords((args), (nargs), (kwargs), (kwnames), (parser), \
  95. (minpos), (maxpos), (minkw), (buf)))
  96. PyAPI_FUNC(PyObject *) _PyModule_CreateInitialized(PyModuleDef*, int apiver);
  97. PyAPI_FUNC(int) _PyModule_Add(PyObject *, const char *, PyObject *);