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