• 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 // Add an attribute with name 'name' and value 'obj' to the module 'mod.
140 // On success, return 0 on success.
141 // On error, raise an exception and return -1.
142 PyAPI_FUNC(int) PyModule_AddObjectRef(PyObject *mod, const char *name, PyObject *value);
143 
144 // Similar to PyModule_AddObjectRef() but steal a reference to 'obj'
145 // (Py_DECREF(obj)) on success (if it returns 0).
146 PyAPI_FUNC(int) PyModule_AddObject(PyObject *mod, const char *, PyObject *value);
147 
148 PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long);
149 PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char *);
150 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
151 /* New in 3.9 */
152 PyAPI_FUNC(int) PyModule_AddType(PyObject *module, PyTypeObject *type);
153 #endif /* Py_LIMITED_API */
154 #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)
155 #define PyModule_AddStringMacro(m, c) PyModule_AddStringConstant(m, #c, c)
156 
157 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
158 /* New in 3.5 */
159 PyAPI_FUNC(int) PyModule_SetDocString(PyObject *, const char *);
160 PyAPI_FUNC(int) PyModule_AddFunctions(PyObject *, PyMethodDef *);
161 PyAPI_FUNC(int) PyModule_ExecDef(PyObject *module, PyModuleDef *def);
162 #endif
163 
164 #define Py_CLEANUP_SUPPORTED 0x20000
165 
166 #define PYTHON_API_VERSION 1013
167 #define PYTHON_API_STRING "1013"
168 /* The API version is maintained (independently from the Python version)
169    so we can detect mismatches between the interpreter and dynamically
170    loaded modules.  These are diagnosed by an error message but
171    the module is still loaded (because the mismatch can only be tested
172    after loading the module).  The error message is intended to
173    explain the core dump a few seconds later.
174 
175    The symbol PYTHON_API_STRING defines the same value as a string
176    literal.  *** PLEASE MAKE SURE THE DEFINITIONS MATCH. ***
177 
178    Please add a line or two to the top of this log for each API
179    version change:
180 
181    22-Feb-2006  MvL     1013    PEP 353 - long indices for sequence lengths
182 
183    19-Aug-2002  GvR     1012    Changes to string object struct for
184                                 interning changes, saving 3 bytes.
185 
186    17-Jul-2001  GvR     1011    Descr-branch, just to be on the safe side
187 
188    25-Jan-2001  FLD     1010    Parameters added to PyCode_New() and
189                                 PyFrame_New(); Python 2.1a2
190 
191    14-Mar-2000  GvR     1009    Unicode API added
192 
193    3-Jan-1999   GvR     1007    Decided to change back!  (Don't reuse 1008!)
194 
195    3-Dec-1998   GvR     1008    Python 1.5.2b1
196 
197    18-Jan-1997  GvR     1007    string interning and other speedups
198 
199    11-Oct-1996  GvR     renamed Py_Ellipses to Py_Ellipsis :-(
200 
201    30-Jul-1996  GvR     Slice and ellipses syntax added
202 
203    23-Jul-1996  GvR     For 1.4 -- better safe than sorry this time :-)
204 
205    7-Nov-1995   GvR     Keyword arguments (should've been done at 1.3 :-( )
206 
207    10-Jan-1995  GvR     Renamed globals to new naming scheme
208 
209    9-Jan-1995   GvR     Initial version (incompatible with older API)
210 */
211 
212 /* The PYTHON_ABI_VERSION is introduced in PEP 384. For the lifetime of
213    Python 3, it will stay at the value of 3; changes to the limited API
214    must be performed in a strictly backwards-compatible manner. */
215 #define PYTHON_ABI_VERSION 3
216 #define PYTHON_ABI_STRING "3"
217 
218 #ifdef Py_TRACE_REFS
219  /* When we are tracing reference counts, rename module creation functions so
220     modules compiled with incompatible settings will generate a
221     link-time error. */
222  #define PyModule_Create2 PyModule_Create2TraceRefs
223  #define PyModule_FromDefAndSpec2 PyModule_FromDefAndSpec2TraceRefs
224 #endif
225 
226 PyAPI_FUNC(PyObject *) PyModule_Create2(struct PyModuleDef*,
227                                      int apiver);
228 #ifndef Py_LIMITED_API
229 PyAPI_FUNC(PyObject *) _PyModule_CreateInitialized(struct PyModuleDef*,
230                                                    int apiver);
231 #endif
232 
233 #ifdef Py_LIMITED_API
234 #define PyModule_Create(module) \
235         PyModule_Create2(module, PYTHON_ABI_VERSION)
236 #else
237 #define PyModule_Create(module) \
238         PyModule_Create2(module, PYTHON_API_VERSION)
239 #endif
240 
241 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
242 /* New in 3.5 */
243 PyAPI_FUNC(PyObject *) PyModule_FromDefAndSpec2(PyModuleDef *def,
244                                                 PyObject *spec,
245                                                 int module_api_version);
246 
247 #ifdef Py_LIMITED_API
248 #define PyModule_FromDefAndSpec(module, spec) \
249     PyModule_FromDefAndSpec2(module, spec, PYTHON_ABI_VERSION)
250 #else
251 #define PyModule_FromDefAndSpec(module, spec) \
252     PyModule_FromDefAndSpec2(module, spec, PYTHON_API_VERSION)
253 #endif /* Py_LIMITED_API */
254 #endif /* New in 3.5 */
255 
256 #ifndef Py_LIMITED_API
257 PyAPI_DATA(const char *) _Py_PackageContext;
258 #endif
259 
260 #ifdef __cplusplus
261 }
262 #endif
263 #endif /* !Py_MODSUPPORT_H */
264