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