Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Include/modsupport.h
12 views
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> // va_list
11
12
PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...);
13
PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...);
14
PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
15
const char *, char **, ...);
16
PyAPI_FUNC(int) PyArg_VaParse(PyObject *, const char *, va_list);
17
PyAPI_FUNC(int) PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *,
18
const char *, char **, va_list);
19
20
PyAPI_FUNC(int) PyArg_ValidateKeywordArguments(PyObject *);
21
PyAPI_FUNC(int) PyArg_UnpackTuple(PyObject *, const char *, Py_ssize_t, Py_ssize_t, ...);
22
PyAPI_FUNC(PyObject *) Py_BuildValue(const char *, ...);
23
PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list);
24
25
// Add an attribute with name 'name' and value 'obj' to the module 'mod.
26
// On success, return 0 on success.
27
// On error, raise an exception and return -1.
28
PyAPI_FUNC(int) PyModule_AddObjectRef(PyObject *mod, const char *name, PyObject *value);
29
30
// Similar to PyModule_AddObjectRef() but steal a reference to 'obj'
31
// (Py_DECREF(obj)) on success (if it returns 0).
32
PyAPI_FUNC(int) PyModule_AddObject(PyObject *mod, const char *, PyObject *value);
33
34
PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long);
35
PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char *);
36
37
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
38
/* New in 3.9 */
39
PyAPI_FUNC(int) PyModule_AddType(PyObject *module, PyTypeObject *type);
40
#endif /* Py_LIMITED_API */
41
42
#define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant((m), #c, (c))
43
#define PyModule_AddStringMacro(m, c) PyModule_AddStringConstant((m), #c, (c))
44
45
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
46
/* New in 3.5 */
47
PyAPI_FUNC(int) PyModule_SetDocString(PyObject *, const char *);
48
PyAPI_FUNC(int) PyModule_AddFunctions(PyObject *, PyMethodDef *);
49
PyAPI_FUNC(int) PyModule_ExecDef(PyObject *module, PyModuleDef *def);
50
#endif
51
52
#define Py_CLEANUP_SUPPORTED 0x20000
53
54
#define PYTHON_API_VERSION 1013
55
#define PYTHON_API_STRING "1013"
56
/* The API version is maintained (independently from the Python version)
57
so we can detect mismatches between the interpreter and dynamically
58
loaded modules. These are diagnosed by an error message but
59
the module is still loaded (because the mismatch can only be tested
60
after loading the module). The error message is intended to
61
explain the core dump a few seconds later.
62
63
The symbol PYTHON_API_STRING defines the same value as a string
64
literal. *** PLEASE MAKE SURE THE DEFINITIONS MATCH. ***
65
66
Please add a line or two to the top of this log for each API
67
version change:
68
69
22-Feb-2006 MvL 1013 PEP 353 - long indices for sequence lengths
70
71
19-Aug-2002 GvR 1012 Changes to string object struct for
72
interning changes, saving 3 bytes.
73
74
17-Jul-2001 GvR 1011 Descr-branch, just to be on the safe side
75
76
25-Jan-2001 FLD 1010 Parameters added to PyCode_New() and
77
PyFrame_New(); Python 2.1a2
78
79
14-Mar-2000 GvR 1009 Unicode API added
80
81
3-Jan-1999 GvR 1007 Decided to change back! (Don't reuse 1008!)
82
83
3-Dec-1998 GvR 1008 Python 1.5.2b1
84
85
18-Jan-1997 GvR 1007 string interning and other speedups
86
87
11-Oct-1996 GvR renamed Py_Ellipses to Py_Ellipsis :-(
88
89
30-Jul-1996 GvR Slice and ellipses syntax added
90
91
23-Jul-1996 GvR For 1.4 -- better safe than sorry this time :-)
92
93
7-Nov-1995 GvR Keyword arguments (should've been done at 1.3 :-( )
94
95
10-Jan-1995 GvR Renamed globals to new naming scheme
96
97
9-Jan-1995 GvR Initial version (incompatible with older API)
98
*/
99
100
/* The PYTHON_ABI_VERSION is introduced in PEP 384. For the lifetime of
101
Python 3, it will stay at the value of 3; changes to the limited API
102
must be performed in a strictly backwards-compatible manner. */
103
#define PYTHON_ABI_VERSION 3
104
#define PYTHON_ABI_STRING "3"
105
106
#ifdef Py_TRACE_REFS
107
/* When we are tracing reference counts, rename module creation functions so
108
modules compiled with incompatible settings will generate a
109
link-time error. */
110
#define PyModule_Create2 PyModule_Create2TraceRefs
111
#define PyModule_FromDefAndSpec2 PyModule_FromDefAndSpec2TraceRefs
112
#endif
113
114
PyAPI_FUNC(PyObject *) PyModule_Create2(PyModuleDef*, int apiver);
115
116
#ifdef Py_LIMITED_API
117
#define PyModule_Create(module) \
118
PyModule_Create2((module), PYTHON_ABI_VERSION)
119
#else
120
#define PyModule_Create(module) \
121
PyModule_Create2((module), PYTHON_API_VERSION)
122
#endif
123
124
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
125
/* New in 3.5 */
126
PyAPI_FUNC(PyObject *) PyModule_FromDefAndSpec2(PyModuleDef *def,
127
PyObject *spec,
128
int module_api_version);
129
130
#ifdef Py_LIMITED_API
131
#define PyModule_FromDefAndSpec(module, spec) \
132
PyModule_FromDefAndSpec2((module), (spec), PYTHON_ABI_VERSION)
133
#else
134
#define PyModule_FromDefAndSpec(module, spec) \
135
PyModule_FromDefAndSpec2((module), (spec), PYTHON_API_VERSION)
136
#endif /* Py_LIMITED_API */
137
138
#endif /* New in 3.5 */
139
140
#ifndef Py_LIMITED_API
141
# define Py_CPYTHON_MODSUPPORT_H
142
# include "cpython/modsupport.h"
143
# undef Py_CPYTHON_MODSUPPORT_H
144
#endif
145
146
#ifdef __cplusplus
147
}
148
#endif
149
#endif /* !Py_MODSUPPORT_H */
150
151