blob: 1af1487deec9168cf7691b828bb6eed48ec3e33e [file] [log] [blame]
Victor Stinnerb6522d02016-12-19 13:12:08 +01001/* Abstract Object Interface (many thanks to Jim Fulton) */
2
Guido van Rossuma8275371995-07-18 14:07:00 +00003#ifndef Py_ABSTRACTOBJECT_H
4#define Py_ABSTRACTOBJECT_H
5#ifdef __cplusplus
6extern "C" {
7#endif
8
Victor Stinner2a358f82016-12-06 16:55:39 +01009/* === Object Protocol ================================================== */
Guido van Rossuma8275371995-07-18 14:07:00 +000010
Victor Stinner2a358f82016-12-06 16:55:39 +010011/* Implemented elsewhere:
Guido van Rossuma8275371995-07-18 14:07:00 +000012
Victor Stinner5bef7cd2016-12-15 09:14:25 +010013 int PyObject_Print(PyObject *o, FILE *fp, int flags);
Guido van Rossuma8275371995-07-18 14:07:00 +000014
Victor Stinner5bef7cd2016-12-15 09:14:25 +010015 Print an object 'o' on file 'fp'. Returns -1 on error. The flags argument
16 is used to enable certain printing options. The only option currently
17 supported is Py_Print_RAW.
Guido van Rossuma8275371995-07-18 14:07:00 +000018
Victor Stinner5bef7cd2016-12-15 09:14:25 +010019 (What should be said about Py_Print_RAW?). */
Victor Stinner2a358f82016-12-06 16:55:39 +010020
21
22/* Implemented elsewhere:
23
Victor Stinner5bef7cd2016-12-15 09:14:25 +010024 int PyObject_HasAttrString(PyObject *o, const char *attr_name);
Victor Stinner2a358f82016-12-06 16:55:39 +010025
Victor Stinner5bef7cd2016-12-15 09:14:25 +010026 Returns 1 if object 'o' has the attribute attr_name, and 0 otherwise.
Victor Stinner2a358f82016-12-06 16:55:39 +010027
Victor Stinner5bef7cd2016-12-15 09:14:25 +010028 This is equivalent to the Python expression: hasattr(o,attr_name).
29
30 This function always succeeds. */
31
Victor Stinner2a358f82016-12-06 16:55:39 +010032
33/* Implemented elsewhere:
34
Victor Stinner5bef7cd2016-12-15 09:14:25 +010035 PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name);
Victor Stinner2a358f82016-12-06 16:55:39 +010036
Victor Stinner5bef7cd2016-12-15 09:14:25 +010037 Retrieve an attributed named attr_name form object o.
38 Returns the attribute value on success, or NULL on failure.
Victor Stinner2a358f82016-12-06 16:55:39 +010039
Victor Stinner5bef7cd2016-12-15 09:14:25 +010040 This is the equivalent of the Python expression: o.attr_name. */
Victor Stinner2a358f82016-12-06 16:55:39 +010041
Guido van Rossuma8275371995-07-18 14:07:00 +000042
Victor Stinner2a358f82016-12-06 16:55:39 +010043/* Implemented elsewhere:
Guido van Rossuma8275371995-07-18 14:07:00 +000044
Victor Stinner5bef7cd2016-12-15 09:14:25 +010045 int PyObject_HasAttr(PyObject *o, PyObject *attr_name);
Guido van Rossuma8275371995-07-18 14:07:00 +000046
Victor Stinner5bef7cd2016-12-15 09:14:25 +010047 Returns 1 if o has the attribute attr_name, and 0 otherwise.
Guido van Rossuma8275371995-07-18 14:07:00 +000048
Victor Stinner5bef7cd2016-12-15 09:14:25 +010049 This is equivalent to the Python expression: hasattr(o,attr_name).
Guido van Rossuma8275371995-07-18 14:07:00 +000050
Victor Stinner5bef7cd2016-12-15 09:14:25 +010051 This function always succeeds. */
Guido van Rossuma8275371995-07-18 14:07:00 +000052
Victor Stinner2a358f82016-12-06 16:55:39 +010053/* Implemented elsewhere:
Guido van Rossuma8275371995-07-18 14:07:00 +000054
Victor Stinner5bef7cd2016-12-15 09:14:25 +010055 PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name);
Guido van Rossuma8275371995-07-18 14:07:00 +000056
Victor Stinner5bef7cd2016-12-15 09:14:25 +010057 Retrieve an attributed named 'attr_name' form object 'o'.
58 Returns the attribute value on success, or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +000059
Victor Stinner5bef7cd2016-12-15 09:14:25 +010060 This is the equivalent of the Python expression: o.attr_name. */
Marc-André Lemburgad7c98e2001-01-17 17:09:53 +000061
Marc-André Lemburgad7c98e2001-01-17 17:09:53 +000062
Victor Stinner5bef7cd2016-12-15 09:14:25 +010063/* Implemented elsewhere:
Thomas Wouters89f507f2006-12-13 04:49:30 +000064
Victor Stinner5bef7cd2016-12-15 09:14:25 +010065 int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v);
Guido van Rossuma8275371995-07-18 14:07:00 +000066
Victor Stinner5bef7cd2016-12-15 09:14:25 +010067 Set the value of the attribute named attr_name, for object 'o',
68 to the value 'v'. Raise an exception and return -1 on failure; return 0 on
69 success.
Guido van Rossuma8275371995-07-18 14:07:00 +000070
Victor Stinner5bef7cd2016-12-15 09:14:25 +010071 This is the equivalent of the Python statement o.attr_name=v. */
72
73
74/* Implemented elsewhere:
75
76 int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v);
77
78 Set the value of the attribute named attr_name, for object 'o', to the value
79 'v'. an exception and return -1 on failure; return 0 on success.
80
81 This is the equivalent of the Python statement o.attr_name=v. */
82
83/* Implemented as a macro:
84
85 int PyObject_DelAttrString(PyObject *o, const char *attr_name);
86
87 Delete attribute named attr_name, for object o. Returns
88 -1 on failure.
89
90 This is the equivalent of the Python statement: del o.attr_name. */
91#define PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A), NULL)
92
93
94/* Implemented as a macro:
95
96 int PyObject_DelAttr(PyObject *o, PyObject *attr_name);
97
98 Delete attribute named attr_name, for object o. Returns -1
99 on failure. This is the equivalent of the Python
100 statement: del o.attr_name. */
101#define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A), NULL)
102
103
104/* Implemented elsewhere:
105
106 PyObject *PyObject_Repr(PyObject *o);
107
108 Compute the string representation of object 'o'. Returns the
109 string representation on success, NULL on failure.
110
111 This is the equivalent of the Python expression: repr(o).
112
113 Called by the repr() built-in function. */
114
115
116/* Implemented elsewhere:
117
118 PyObject *PyObject_Str(PyObject *o);
119
120 Compute the string representation of object, o. Returns the
121 string representation on success, NULL on failure.
122
123 This is the equivalent of the Python expression: str(o).
124
125 Called by the str() and print() built-in functions. */
126
127
128/* Declared elsewhere
129
130 PyAPI_FUNC(int) PyCallable_Check(PyObject *o);
131
132 Determine if the object, o, is callable. Return 1 if the object is callable
133 and 0 otherwise.
134
135 This function always succeeds. */
136
137
138#ifdef PY_SSIZE_T_CLEAN
139# define PyObject_CallFunction _PyObject_CallFunction_SizeT
140# define PyObject_CallMethod _PyObject_CallMethod_SizeT
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100141#endif
142
Guido van Rossuma8275371995-07-18 14:07:00 +0000143
Victor Stinner2ff58a22019-06-17 14:27:23 +0200144#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
145/* Call a callable Python object without any arguments */
146PyAPI_FUNC(PyObject *) PyObject_CallNoArgs(PyObject *func);
147#endif
148
149
Victor Stinner2a358f82016-12-06 16:55:39 +0100150/* Call a callable Python object 'callable' with arguments given by the
151 tuple 'args' and keywords arguments given by the dictionary 'kwargs'.
Tim Peters6d6c1a32001-08-02 04:15:00 +0000152
Serhiy Storchaka25fc0882019-10-30 12:03:20 +0200153 'args' must not be NULL, use an empty tuple if no arguments are
Victor Stinner2a358f82016-12-06 16:55:39 +0100154 needed. If no named arguments are needed, 'kwargs' can be NULL.
Victor Stinner2d0eb652016-12-06 16:27:24 +0100155
Victor Stinner2a358f82016-12-06 16:55:39 +0100156 This is the equivalent of the Python expression:
157 callable(*args, **kwargs). */
158PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable,
159 PyObject *args, PyObject *kwargs);
160
Victor Stinner2d0eb652016-12-06 16:27:24 +0100161
Victor Stinner2a358f82016-12-06 16:55:39 +0100162/* Call a callable Python object 'callable', with arguments given by the
Serhiy Storchaka25fc0882019-10-30 12:03:20 +0200163 tuple 'args'. If no arguments are needed, then 'args' can be NULL.
Victor Stinner2d0eb652016-12-06 16:27:24 +0100164
Serhiy Storchaka25fc0882019-10-30 12:03:20 +0200165 Returns the result of the call on success, or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000166
Victor Stinner2a358f82016-12-06 16:55:39 +0100167 This is the equivalent of the Python expression:
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100168 callable(*args). */
Victor Stinner2a358f82016-12-06 16:55:39 +0100169PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable,
170 PyObject *args);
Guido van Rossuma8275371995-07-18 14:07:00 +0000171
Victor Stinner2a358f82016-12-06 16:55:39 +0100172/* Call a callable Python object, callable, with a variable number of C
173 arguments. The C arguments are described using a mkvalue-style format
174 string.
Victor Stinner2d0eb652016-12-06 16:27:24 +0100175
Victor Stinner2a358f82016-12-06 16:55:39 +0100176 The format may be NULL, indicating that no arguments are provided.
Victor Stinner2d0eb652016-12-06 16:27:24 +0100177
Victor Stinner2a358f82016-12-06 16:55:39 +0100178 Returns the result of the call on success, or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000179
Victor Stinner2a358f82016-12-06 16:55:39 +0100180 This is the equivalent of the Python expression:
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100181 callable(arg1, arg2, ...). */
Victor Stinner2a358f82016-12-06 16:55:39 +0100182PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable,
183 const char *format, ...);
Guido van Rossuma8275371995-07-18 14:07:00 +0000184
Victor Stinner2a358f82016-12-06 16:55:39 +0100185/* Call the method named 'name' of object 'obj' with a variable number of
186 C arguments. The C arguments are described by a mkvalue format string.
Guido van Rossuma8275371995-07-18 14:07:00 +0000187
Victor Stinner2a358f82016-12-06 16:55:39 +0100188 The format can be NULL, indicating that no arguments are provided.
Victor Stinner2d0eb652016-12-06 16:27:24 +0100189
Victor Stinner2a358f82016-12-06 16:55:39 +0100190 Returns the result of the call on success, or NULL on failure.
191
192 This is the equivalent of the Python expression:
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100193 obj.name(arg1, arg2, ...). */
Victor Stinner2a358f82016-12-06 16:55:39 +0100194PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *obj,
195 const char *name,
196 const char *format, ...);
Guido van Rossuma8275371995-07-18 14:07:00 +0000197
Victor Stinner2a358f82016-12-06 16:55:39 +0100198PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable,
199 const char *format,
200 ...);
201
202PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *obj,
203 const char *name,
204 const char *format,
205 ...);
206
Victor Stinner2a358f82016-12-06 16:55:39 +0100207/* Call a callable Python object 'callable' with a variable number of C
208 arguments. The C arguments are provided as PyObject* values, terminated
209 by a NULL.
Victor Stinner2d0eb652016-12-06 16:27:24 +0100210
Victor Stinner2a358f82016-12-06 16:55:39 +0100211 Returns the result of the call on success, or NULL on failure.
Victor Stinner2d0eb652016-12-06 16:27:24 +0100212
Victor Stinner2a358f82016-12-06 16:55:39 +0100213 This is the equivalent of the Python expression:
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100214 callable(arg1, arg2, ...). */
Victor Stinner2a358f82016-12-06 16:55:39 +0100215PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable,
216 ...);
Fred Drakeb421b8c2001-10-26 16:21:32 +0000217
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100218/* Call the method named 'name' of object 'obj' with a variable number of
219 C arguments. The C arguments are provided as PyObject* values, terminated
220 by NULL.
221
222 Returns the result of the call on success, or NULL on failure.
223
224 This is the equivalent of the Python expression: obj.name(*args). */
Guido van Rossuma8275371995-07-18 14:07:00 +0000225
Victor Stinner2a358f82016-12-06 16:55:39 +0100226PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(
227 PyObject *obj,
228 PyObject *name,
229 ...);
230
Victor Stinner2d0eb652016-12-06 16:27:24 +0100231
Victor Stinner2a358f82016-12-06 16:55:39 +0100232/* Implemented elsewhere:
Guido van Rossuma8275371995-07-18 14:07:00 +0000233
Andrew Svetlov95084022017-12-16 21:08:05 +0200234 Py_hash_t PyObject_Hash(PyObject *o);
Guido van Rossuma8275371995-07-18 14:07:00 +0000235
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100236 Compute and return the hash, hash_value, of an object, o. On
237 failure, return -1.
238
239 This is the equivalent of the Python expression: hash(o). */
Guido van Rossuma8275371995-07-18 14:07:00 +0000240
241
Victor Stinner2a358f82016-12-06 16:55:39 +0100242/* Implemented elsewhere:
Guido van Rossuma8275371995-07-18 14:07:00 +0000243
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100244 int PyObject_IsTrue(PyObject *o);
Guido van Rossuma8275371995-07-18 14:07:00 +0000245
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100246 Returns 1 if the object, o, is considered to be true, 0 if o is
247 considered to be false and -1 on failure.
248
249 This is equivalent to the Python expression: not not o. */
250
Guido van Rossuma8275371995-07-18 14:07:00 +0000251
Victor Stinner2a358f82016-12-06 16:55:39 +0100252/* Implemented elsewhere:
Guido van Rossumc3d3f961998-04-09 17:53:59 +0000253
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100254 int PyObject_Not(PyObject *o);
Guido van Rossumc3d3f961998-04-09 17:53:59 +0000255
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100256 Returns 0 if the object, o, is considered to be true, 1 if o is
257 considered to be false and -1 on failure.
Guido van Rossumc3d3f961998-04-09 17:53:59 +0000258
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100259 This is equivalent to the Python expression: not o. */
260
261
262/* Get the type of an object.
263
264 On success, returns a type object corresponding to the object type of object
265 'o'. On failure, returns NULL.
266
267 This is equivalent to the Python expression: type(o) */
Victor Stinner2a358f82016-12-06 16:55:39 +0100268PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o);
Guido van Rossuma8275371995-07-18 14:07:00 +0000269
Guido van Rossuma8275371995-07-18 14:07:00 +0000270
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100271/* Return the size of object 'o'. If the object 'o' provides both sequence and
272 mapping protocols, the sequence size is returned.
273
274 On error, -1 is returned.
275
276 This is the equivalent to the Python expression: len(o) */
Victor Stinner2a358f82016-12-06 16:55:39 +0100277PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o);
Jeremy Hylton6253f832000-07-12 12:56:19 +0000278
Guido van Rossuma8275371995-07-18 14:07:00 +0000279
Victor Stinner2a358f82016-12-06 16:55:39 +0100280/* For DLL compatibility */
Marc-André Lemburgcf5f3582000-07-17 09:22:55 +0000281#undef PyObject_Length
Victor Stinner2a358f82016-12-06 16:55:39 +0100282PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o);
Marc-André Lemburgcf5f3582000-07-17 09:22:55 +0000283#define PyObject_Length PyObject_Size
284
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100285/* Return element of 'o' corresponding to the object 'key'. Return NULL
286 on failure.
Marc-André Lemburgcf5f3582000-07-17 09:22:55 +0000287
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100288 This is the equivalent of the Python expression: o[key] */
Victor Stinner2a358f82016-12-06 16:55:39 +0100289PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key);
Guido van Rossuma8275371995-07-18 14:07:00 +0000290
Guido van Rossuma8275371995-07-18 14:07:00 +0000291
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100292/* Map the object 'key' to the value 'v' into 'o'.
293
294 Raise an exception and return -1 on failure; return 0 on success.
295
296 This is the equivalent of the Python statement: o[key]=v. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100297PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v);
Guido van Rossuma8275371995-07-18 14:07:00 +0000298
Serhiy Storchakaf5b11832018-05-22 11:02:44 +0300299/* Remove the mapping for the string 'key' from the object 'o'.
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100300 Returns -1 on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000301
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100302 This is equivalent to the Python statement: del o[key]. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100303PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key);
Martin v. Löwisb0d71d02002-01-05 10:50:30 +0000304
Serhiy Storchakaf5b11832018-05-22 11:02:44 +0300305/* Delete the mapping for the object 'key' from the object 'o'.
306 Returns -1 on failure.
Martin v. Löwisb0d71d02002-01-05 10:50:30 +0000307
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100308 This is the equivalent of the Python statement: del o[key]. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100309PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key);
Guido van Rossum6cdc6f41996-08-21 17:41:54 +0000310
Guido van Rossum6cdc6f41996-08-21 17:41:54 +0000311
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100312/* === New Buffer API ============================================ */
Travis E. Oliphantb99f7622007-08-18 11:21:56 +0000313
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100314/* Takes an arbitrary object and returns the result of calling
315 obj.__format__(format_spec). */
316PyAPI_FUNC(PyObject *) PyObject_Format(PyObject *obj,
Victor Stinner2a358f82016-12-06 16:55:39 +0100317 PyObject *format_spec);
Eric Smith8fd3eba2008-02-17 19:48:00 +0000318
Guido van Rossum213c7a62001-04-23 14:08:49 +0000319
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100320/* ==== Iterators ================================================ */
321
322/* Takes an object and returns an iterator for it.
323 This is typically a new iterator but if the argument is an iterator, this
324 returns itself. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100325PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);
Guido van Rossum59d1d2b2001-04-20 19:13:02 +0000326
Joshua Bronsonf0a6fde2021-03-23 18:47:21 -0400327/* Takes an AsyncIterable object and returns an AsyncIterator for it.
328 This is typically a new iterator but if the argument is an AsyncIterator,
329 this returns itself. */
330PyAPI_FUNC(PyObject *) PyObject_GetAiter(PyObject *);
331
Erlend Egeberg Aaslandcc540012021-02-16 16:05:58 +0100332/* Returns non-zero if the object 'obj' provides iterator protocols, and 0 otherwise.
Christian Tismerea62ce72018-06-09 20:32:25 +0200333
334 This function always succeeds. */
Serhiy Storchaka5cbefa92018-06-11 15:01:47 +0300335PyAPI_FUNC(int) PyIter_Check(PyObject *);
Guido van Rossum213c7a62001-04-23 14:08:49 +0000336
Joshua Bronsonf0a6fde2021-03-23 18:47:21 -0400337/* Returns non-zero if the object 'obj' provides AsyncIterator protocols, and 0 otherwise.
338
339 This function always succeeds. */
340PyAPI_FUNC(int) PyAiter_Check(PyObject *);
341
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100342/* Takes an iterator object and calls its tp_iternext slot,
343 returning the next value.
344
345 If the iterator is exhausted, this returns NULL without setting an
346 exception.
347
348 NULL with an exception means an error occurred. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100349PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *);
Guido van Rossum213c7a62001-04-23 14:08:49 +0000350
Vladimir Matveevcfb0f572020-10-13 10:26:51 -0700351#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
Vladimir Matveev037245c2020-10-09 17:15:15 -0700352
353/* Takes generator, coroutine or iterator object and sends the value into it.
354 Returns:
355 - PYGEN_RETURN (0) if generator has returned.
356 'result' parameter is filled with return value
357 - PYGEN_ERROR (-1) if exception was raised.
358 'result' parameter is NULL
359 - PYGEN_NEXT (1) if generator has yielded.
360 'result' parameter is filled with yielded value. */
361PyAPI_FUNC(PySendResult) PyIter_Send(PyObject *, PyObject *, PyObject **);
Vladimir Matveevcfb0f572020-10-13 10:26:51 -0700362#endif
Vladimir Matveev037245c2020-10-09 17:15:15 -0700363
Guido van Rossuma8275371995-07-18 14:07:00 +0000364
Victor Stinner2a358f82016-12-06 16:55:39 +0100365/* === Number Protocol ================================================== */
Guido van Rossuma8275371995-07-18 14:07:00 +0000366
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100367/* Returns 1 if the object 'o' provides numeric protocols, and 0 otherwise.
368
369 This function always succeeds. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100370PyAPI_FUNC(int) PyNumber_Check(PyObject *o);
Guido van Rossuma8275371995-07-18 14:07:00 +0000371
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100372/* Returns the result of adding o1 and o2, or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000373
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100374 This is the equivalent of the Python expression: o1 + o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100375PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2);
Guido van Rossuma8275371995-07-18 14:07:00 +0000376
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100377/* Returns the result of subtracting o2 from o1, or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000378
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100379 This is the equivalent of the Python expression: o1 - o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100380PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2);
Guido van Rossuma8275371995-07-18 14:07:00 +0000381
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100382/* Returns the result of multiplying o1 and o2, or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000383
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100384 This is the equivalent of the Python expression: o1 * o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100385PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2);
Guido van Rossuma8275371995-07-18 14:07:00 +0000386
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +0200387#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100388/* This is the equivalent of the Python expression: o1 @ o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100389PyAPI_FUNC(PyObject *) PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2);
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +0200390#endif
Benjamin Petersond51374e2014-04-09 23:55:56 -0400391
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100392/* Returns the result of dividing o1 by o2 giving an integral result,
393 or NULL on failure.
Guido van Rossum4668b002001-08-08 05:00:18 +0000394
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100395 This is the equivalent of the Python expression: o1 // o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100396PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2);
Guido van Rossum4668b002001-08-08 05:00:18 +0000397
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100398/* Returns the result of dividing o1 by o2 giving a float result, or NULL on
399 failure.
Guido van Rossum4668b002001-08-08 05:00:18 +0000400
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100401 This is the equivalent of the Python expression: o1 / o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100402PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2);
Guido van Rossum4668b002001-08-08 05:00:18 +0000403
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100404/* Returns the remainder of dividing o1 by o2, or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000405
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100406 This is the equivalent of the Python expression: o1 % o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100407PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2);
Guido van Rossuma8275371995-07-18 14:07:00 +0000408
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100409/* See the built-in function divmod.
Guido van Rossuma8275371995-07-18 14:07:00 +0000410
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100411 Returns NULL on failure.
412
413 This is the equivalent of the Python expression: divmod(o1, o2). */
Victor Stinner2a358f82016-12-06 16:55:39 +0100414PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2);
Guido van Rossuma8275371995-07-18 14:07:00 +0000415
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100416/* See the built-in function pow. Returns NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000417
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100418 This is the equivalent of the Python expression: pow(o1, o2, o3),
419 where o3 is optional. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100420PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2,
421 PyObject *o3);
Guido van Rossuma8275371995-07-18 14:07:00 +0000422
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100423/* Returns the negation of o on success, or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000424
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100425 This is the equivalent of the Python expression: -o. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100426PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o);
Guido van Rossuma8275371995-07-18 14:07:00 +0000427
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100428/* Returns the positive of o on success, or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000429
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100430 This is the equivalent of the Python expression: +o. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100431PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o);
Guido van Rossuma8275371995-07-18 14:07:00 +0000432
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100433/* Returns the absolute value of 'o', or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000434
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100435 This is the equivalent of the Python expression: abs(o). */
Victor Stinner2a358f82016-12-06 16:55:39 +0100436PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o);
Guido van Rossuma8275371995-07-18 14:07:00 +0000437
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100438/* Returns the bitwise negation of 'o' on success, or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000439
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100440 This is the equivalent of the Python expression: ~o. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100441PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o);
Guido van Rossuma8275371995-07-18 14:07:00 +0000442
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100443/* Returns the result of left shifting o1 by o2 on success, or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000444
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100445 This is the equivalent of the Python expression: o1 << o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100446PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2);
Guido van Rossuma8275371995-07-18 14:07:00 +0000447
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100448/* Returns the result of right shifting o1 by o2 on success, or NULL on
449 failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000450
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100451 This is the equivalent of the Python expression: o1 >> o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100452PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2);
Guido van Rossuma8275371995-07-18 14:07:00 +0000453
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100454/* Returns the result of bitwise and of o1 and o2 on success, or NULL on
455 failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000456
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100457 This is the equivalent of the Python expression: o1 & o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100458PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2);
Guido van Rossuma8275371995-07-18 14:07:00 +0000459
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100460/* Returns the bitwise exclusive or of o1 by o2 on success, or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000461
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100462 This is the equivalent of the Python expression: o1 ^ o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100463PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2);
Guido van Rossuma8275371995-07-18 14:07:00 +0000464
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100465/* Returns the result of bitwise or on o1 and o2 on success, or NULL on
466 failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000467
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100468 This is the equivalent of the Python expression: o1 | o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100469PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2);
470
Christian Tismerea62ce72018-06-09 20:32:25 +0200471/* Returns 1 if obj is an index integer (has the nb_index slot of the
472 tp_as_number structure filled in), and 0 otherwise. */
Serhiy Storchaka5cbefa92018-06-11 15:01:47 +0300473PyAPI_FUNC(int) PyIndex_Check(PyObject *);
Guido van Rossuma8275371995-07-18 14:07:00 +0000474
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100475/* Returns the object 'o' converted to a Python int, or NULL with an exception
476 raised on failure. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100477PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o);
Guido van Rossum38fff8c2006-03-07 18:50:55 +0000478
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100479/* Returns the object 'o' converted to Py_ssize_t by going through
480 PyNumber_Index() first.
Guido van Rossum38fff8c2006-03-07 18:50:55 +0000481
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100482 If an overflow error occurs while converting the int to Py_ssize_t, then the
483 second argument 'exc' is the error-type to return. If it is NULL, then the
484 overflow error is cleared and the value is clipped. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100485PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc);
Thomas Wouters00ee7ba2006-08-21 19:07:27 +0000486
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100487/* Returns the object 'o' converted to an integer object on success, or NULL
488 on failure.
Guido van Rossum38fff8c2006-03-07 18:50:55 +0000489
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100490 This is the equivalent of the Python expression: int(o). */
Victor Stinner2a358f82016-12-06 16:55:39 +0100491PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o);
Mark Dickinsond7467682009-01-10 22:14:33 +0000492
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100493/* Returns the object 'o' converted to a float object on success, or NULL
494 on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000495
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100496 This is the equivalent of the Python expression: float(o). */
Victor Stinner2a358f82016-12-06 16:55:39 +0100497PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o);
Guido van Rossuma8275371995-07-18 14:07:00 +0000498
Victor Stinner2a358f82016-12-06 16:55:39 +0100499
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100500/* --- In-place variants of (some of) the above number protocol functions -- */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000501
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100502/* Returns the result of adding o2 to o1, possibly in-place, or NULL
503 on failure.
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000504
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100505 This is the equivalent of the Python expression: o1 += o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100506PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2);
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000507
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100508/* Returns the result of subtracting o2 from o1, possibly in-place or
509 NULL on failure.
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000510
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100511 This is the equivalent of the Python expression: o1 -= o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100512PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2);
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000513
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100514/* Returns the result of multiplying o1 by o2, possibly in-place, or NULL on
515 failure.
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000516
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100517 This is the equivalent of the Python expression: o1 *= o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100518PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2);
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000519
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +0200520#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100521/* This is the equivalent of the Python expression: o1 @= o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100522PyAPI_FUNC(PyObject *) PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2);
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +0200523#endif
Benjamin Petersond51374e2014-04-09 23:55:56 -0400524
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100525/* Returns the result of dividing o1 by o2 giving an integral result, possibly
526 in-place, or NULL on failure.
Benjamin Petersond51374e2014-04-09 23:55:56 -0400527
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100528 This is the equivalent of the Python expression: o1 /= o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100529PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1,
530 PyObject *o2);
Guido van Rossum4668b002001-08-08 05:00:18 +0000531
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100532/* Returns the result of dividing o1 by o2 giving a float result, possibly
533 in-place, or null on failure.
Guido van Rossum4668b002001-08-08 05:00:18 +0000534
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100535 This is the equivalent of the Python expression: o1 /= o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100536PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1,
537 PyObject *o2);
Guido van Rossum4668b002001-08-08 05:00:18 +0000538
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100539/* Returns the remainder of dividing o1 by o2, possibly in-place, or NULL on
540 failure.
Guido van Rossum4668b002001-08-08 05:00:18 +0000541
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100542 This is the equivalent of the Python expression: o1 %= o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100543PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2);
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000544
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100545/* Returns the result of raising o1 to the power of o2, possibly in-place,
546 or NULL on failure.
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000547
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100548 This is the equivalent of the Python expression: o1 **= o2,
549 or o1 = pow(o1, o2, o3) if o3 is present. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100550PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2,
551 PyObject *o3);
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000552
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100553/* Returns the result of left shifting o1 by o2, possibly in-place, or NULL
554 on failure.
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000555
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100556 This is the equivalent of the Python expression: o1 <<= o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100557PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2);
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000558
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100559/* Returns the result of right shifting o1 by o2, possibly in-place or NULL
560 on failure.
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000561
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100562 This is the equivalent of the Python expression: o1 >>= o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100563PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2);
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000564
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100565/* Returns the result of bitwise and of o1 and o2, possibly in-place, or NULL
566 on failure.
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000567
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100568 This is the equivalent of the Python expression: o1 &= o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100569PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2);
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000570
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100571/* Returns the bitwise exclusive or of o1 by o2, possibly in-place, or NULL
572 on failure.
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000573
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100574 This is the equivalent of the Python expression: o1 ^= o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100575PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2);
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000576
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100577/* Returns the result of bitwise or of o1 and o2, possibly in-place,
578 or NULL on failure.
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000579
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100580 This is the equivalent of the Python expression: o1 |= o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100581PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2);
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000582
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100583/* Returns the integer n converted to a string with a base, with a base
584 marker of 0b, 0o or 0x prefixed if applicable.
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000585
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100586 If n is not an int object, it is converted with PyNumber_Index first. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100587PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base);
Guido van Rossumcd16bf62007-06-13 18:07:49 +0000588
Guido van Rossuma8275371995-07-18 14:07:00 +0000589
Victor Stinner2a358f82016-12-06 16:55:39 +0100590/* === Sequence protocol ================================================ */
Guido van Rossuma8275371995-07-18 14:07:00 +0000591
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100592/* Return 1 if the object provides sequence protocol, and zero
593 otherwise.
594
595 This function always succeeds. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100596PyAPI_FUNC(int) PySequence_Check(PyObject *o);
Guido van Rossuma8275371995-07-18 14:07:00 +0000597
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100598/* Return the size of sequence object o, or -1 on failure. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100599PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o);
Jeremy Hylton6253f832000-07-12 12:56:19 +0000600
Victor Stinner2a358f82016-12-06 16:55:39 +0100601/* For DLL compatibility */
Marc-André Lemburgcf5f3582000-07-17 09:22:55 +0000602#undef PySequence_Length
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100603PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o);
Marc-André Lemburgcf5f3582000-07-17 09:22:55 +0000604#define PySequence_Length PySequence_Size
605
606
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100607/* Return the concatenation of o1 and o2 on success, and NULL on failure.
608
609 This is the equivalent of the Python expression: o1 + o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100610PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2);
Guido van Rossuma8275371995-07-18 14:07:00 +0000611
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100612/* Return the result of repeating sequence object 'o' 'count' times,
613 or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000614
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100615 This is the equivalent of the Python expression: o * count. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100616PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count);
Guido van Rossuma8275371995-07-18 14:07:00 +0000617
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100618/* Return the ith element of o, or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000619
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100620 This is the equivalent of the Python expression: o[i]. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100621PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i);
Guido van Rossuma8275371995-07-18 14:07:00 +0000622
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100623/* Return the slice of sequence object o between i1 and i2, or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000624
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100625 This is the equivalent of the Python expression: o[i1:i2]. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100626PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
Guido van Rossuma8275371995-07-18 14:07:00 +0000627
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100628/* Assign object 'v' to the ith element of the sequence 'o'. Raise an exception
629 and return -1 on failure; return 0 on success.
Guido van Rossuma8275371995-07-18 14:07:00 +0000630
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100631 This is the equivalent of the Python statement o[i] = v. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100632PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v);
Guido van Rossuma8275371995-07-18 14:07:00 +0000633
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100634/* Delete the 'i'-th element of the sequence 'v'. Returns -1 on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000635
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100636 This is the equivalent of the Python statement: del o[i]. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100637PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i);
Guido van Rossum6cdc6f41996-08-21 17:41:54 +0000638
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100639/* Assign the sequence object 'v' to the slice in sequence object 'o',
640 from 'i1' to 'i2'. Returns -1 on failure.
Guido van Rossum6cdc6f41996-08-21 17:41:54 +0000641
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100642 This is the equivalent of the Python statement: o[i1:i2] = v. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100643PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2,
644 PyObject *v);
Guido van Rossuma8275371995-07-18 14:07:00 +0000645
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100646/* Delete the slice in sequence object 'o' from 'i1' to 'i2'.
647 Returns -1 on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000648
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100649 This is the equivalent of the Python statement: del o[i1:i2]. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100650PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
Guido van Rossum6cdc6f41996-08-21 17:41:54 +0000651
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100652/* Returns the sequence 'o' as a tuple on success, and NULL on failure.
Guido van Rossum6cdc6f41996-08-21 17:41:54 +0000653
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100654 This is equivalent to the Python expression: tuple(o). */
Victor Stinner2a358f82016-12-06 16:55:39 +0100655PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o);
Guido van Rossuma8275371995-07-18 14:07:00 +0000656
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100657/* Returns the sequence 'o' as a list on success, and NULL on failure.
658 This is equivalent to the Python expression: list(o) */
Victor Stinner2a358f82016-12-06 16:55:39 +0100659PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o);
Guido van Rossumf39fc431997-03-04 18:31:47 +0000660
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100661/* Return the sequence 'o' as a list, unless it's already a tuple or list.
662
663 Use PySequence_Fast_GET_ITEM to access the members of this list, and
664 PySequence_Fast_GET_SIZE to get its length.
665
666 Returns NULL on failure. If the object does not support iteration, raises a
667 TypeError exception with 'm' as the message text. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100668PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m);
Andrew M. Kuchling74042d62000-06-18 18:43:14 +0000669
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100670/* Return the size of the sequence 'o', assuming that 'o' was returned by
671 PySequence_Fast and is not NULL. */
Tim Peters1fc240e2001-10-26 05:06:50 +0000672#define PySequence_Fast_GET_SIZE(o) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000673 (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o))
Tim Peters1fc240e2001-10-26 05:06:50 +0000674
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100675/* Return the 'i'-th element of the sequence 'o', assuming that o was returned
676 by PySequence_Fast, and that i is within bounds. */
Andrew M. Kuchling74042d62000-06-18 18:43:14 +0000677#define PySequence_Fast_GET_ITEM(o, i)\
678 (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))
Andrew M. Kuchling74042d62000-06-18 18:43:14 +0000679
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100680/* Return a pointer to the underlying item array for
Min ho Kimc4cacc82019-07-31 08:16:13 +1000681 an object returned by PySequence_Fast */
Raymond Hettinger42bec932004-03-12 16:38:17 +0000682#define PySequence_Fast_ITEMS(sf) \
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000683 (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \
684 : ((PyTupleObject *)(sf))->ob_item)
Raymond Hettingerc1e4f9d2004-03-12 08:04:00 +0000685
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100686/* Return the number of occurrences on value on 'o', that is, return
687 the number of keys for which o[key] == value.
688
689 On failure, return -1. This is equivalent to the Python expression:
690 o.count(value). */
Victor Stinner2a358f82016-12-06 16:55:39 +0100691PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value);
Guido van Rossuma8275371995-07-18 14:07:00 +0000692
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100693/* Return 1 if 'ob' is in the sequence 'seq'; 0 if 'ob' is not in the sequence
694 'seq'; -1 on error.
Guido van Rossuma8275371995-07-18 14:07:00 +0000695
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100696 Use __contains__ if possible, else _PySequence_IterSearch(). */
Victor Stinner2a358f82016-12-06 16:55:39 +0100697PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob);
Tim Peterscb8d3682001-05-05 21:05:01 +0000698
Guido van Rossum83684531999-03-17 18:44:39 +0000699/* For DLL-level backwards compatibility */
700#undef PySequence_In
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100701/* Determine if the sequence 'o' contains 'value'. If an item in 'o' is equal
702 to 'value', return 1, otherwise return 0. On error, return -1.
703
704 This is equivalent to the Python expression: value in o. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100705PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value);
Guido van Rossum83684531999-03-17 18:44:39 +0000706
707/* For source-level backwards compatibility */
Guido van Rossumf1536db1998-08-23 22:06:59 +0000708#define PySequence_In PySequence_Contains
Guido van Rossuma8275371995-07-18 14:07:00 +0000709
Guido van Rossuma8275371995-07-18 14:07:00 +0000710
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100711/* Return the first index for which o[i] == value.
712 On error, return -1.
713
714 This is equivalent to the Python expression: o.index(value). */
Victor Stinner2a358f82016-12-06 16:55:39 +0100715PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value);
Guido van Rossuma8275371995-07-18 14:07:00 +0000716
Victor Stinner2a358f82016-12-06 16:55:39 +0100717
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100718/* --- In-place versions of some of the above Sequence functions --- */
Guido van Rossuma8275371995-07-18 14:07:00 +0000719
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100720/* Append sequence 'o2' to sequence 'o1', in-place when possible. Return the
721 resulting object, which could be 'o1', or NULL on failure.
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000722
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100723 This is the equivalent of the Python expression: o1 += o2. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100724PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2);
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000725
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100726/* Repeat sequence 'o' by 'count', in-place when possible. Return the resulting
727 object, which could be 'o', or NULL on failure.
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000728
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100729 This is the equivalent of the Python expression: o1 *= count. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100730PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count);
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000731
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000732
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100733/* === Mapping protocol ================================================= */
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000734
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100735/* Return 1 if the object provides mapping protocol, and 0 otherwise.
Guido van Rossuma8275371995-07-18 14:07:00 +0000736
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100737 This function always succeeds. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100738PyAPI_FUNC(int) PyMapping_Check(PyObject *o);
Guido van Rossuma8275371995-07-18 14:07:00 +0000739
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100740/* Returns the number of keys in mapping object 'o' on success, and -1 on
Serhiy Storchakaf5b11832018-05-22 11:02:44 +0300741 failure. This is equivalent to the Python expression: len(o). */
Victor Stinner2a358f82016-12-06 16:55:39 +0100742PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o);
Jeremy Hylton6253f832000-07-12 12:56:19 +0000743
Victor Stinner2a358f82016-12-06 16:55:39 +0100744/* For DLL compatibility */
Marc-André Lemburgcf5f3582000-07-17 09:22:55 +0000745#undef PyMapping_Length
Victor Stinner2a358f82016-12-06 16:55:39 +0100746PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o);
Marc-André Lemburgcf5f3582000-07-17 09:22:55 +0000747#define PyMapping_Length PyMapping_Size
748
749
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100750/* Implemented as a macro:
Guido van Rossuma25e5e91996-09-06 13:48:38 +0000751
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100752 int PyMapping_DelItemString(PyObject *o, const char *key);
Guido van Rossuma8275371995-07-18 14:07:00 +0000753
Serhiy Storchakaf5b11832018-05-22 11:02:44 +0300754 Remove the mapping for the string 'key' from the mapping 'o'. Returns -1 on
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100755 failure.
756
757 This is equivalent to the Python statement: del o[key]. */
Jeremy Hylton7c7ee5f2001-11-28 16:20:07 +0000758#define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K))
Guido van Rossuma25e5e91996-09-06 13:48:38 +0000759
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100760/* Implemented as a macro:
Guido van Rossuma8275371995-07-18 14:07:00 +0000761
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100762 int PyMapping_DelItem(PyObject *o, PyObject *key);
Guido van Rossuma8275371995-07-18 14:07:00 +0000763
Serhiy Storchakaf5b11832018-05-22 11:02:44 +0300764 Remove the mapping for the object 'key' from the mapping object 'o'.
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100765 Returns -1 on failure.
766
767 This is equivalent to the Python statement: del o[key]. */
Jeremy Hylton7c7ee5f2001-11-28 16:20:07 +0000768#define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K))
Guido van Rossuma8275371995-07-18 14:07:00 +0000769
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100770/* On success, return 1 if the mapping object 'o' has the key 'key',
771 and 0 otherwise.
772
773 This is equivalent to the Python expression: key in o.
774
775 This function always succeeds. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100776PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, const char *key);
Guido van Rossuma8275371995-07-18 14:07:00 +0000777
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100778/* Return 1 if the mapping object has the key 'key', and 0 otherwise.
Guido van Rossuma8275371995-07-18 14:07:00 +0000779
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100780 This is equivalent to the Python expression: key in o.
Guido van Rossuma8275371995-07-18 14:07:00 +0000781
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100782 This function always succeeds. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100783PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key);
Guido van Rossuma8275371995-07-18 14:07:00 +0000784
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100785/* On success, return a list or tuple of the keys in mapping object 'o'.
786 On failure, return NULL. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100787PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o);
Guido van Rossuma8275371995-07-18 14:07:00 +0000788
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100789/* On success, return a list or tuple of the values in mapping object 'o'.
790 On failure, return NULL. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100791PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o);
Guido van Rossuma8275371995-07-18 14:07:00 +0000792
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100793/* On success, return a list or tuple of the items in mapping object 'o',
794 where each item is a tuple containing a key-value pair. On failure, return
795 NULL. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100796PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o);
Guido van Rossuma8275371995-07-18 14:07:00 +0000797
Serhiy Storchakaf5b11832018-05-22 11:02:44 +0300798/* Return element of 'o' corresponding to the string 'key' or NULL on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000799
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100800 This is the equivalent of the Python expression: o[key]. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100801PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o,
802 const char *key);
Guido van Rossuma8275371995-07-18 14:07:00 +0000803
Serhiy Storchakaf5b11832018-05-22 11:02:44 +0300804/* Map the string 'key' to the value 'v' in the mapping 'o'.
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100805 Returns -1 on failure.
Guido van Rossuma8275371995-07-18 14:07:00 +0000806
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100807 This is the equivalent of the Python statement: o[key]=v. */
Victor Stinner2a358f82016-12-06 16:55:39 +0100808PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, const char *key,
809 PyObject *value);
Guido van Rossuma8275371995-07-18 14:07:00 +0000810
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100811/* isinstance(object, typeorclass) */
Mark Hammond91a681d2002-08-12 07:21:58 +0000812PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass);
Guido van Rossum823649d2001-03-21 18:40:58 +0000813
Victor Stinner5bef7cd2016-12-15 09:14:25 +0100814/* issubclass(object, typeorclass) */
Mark Hammond91a681d2002-08-12 07:21:58 +0000815PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass);
Guido van Rossum823649d2001-03-21 18:40:58 +0000816
Martin v. Löwis4d0d4712010-12-03 20:14:31 +0000817#ifndef Py_LIMITED_API
Victor Stinner40602832018-11-26 22:42:04 +0100818# define Py_CPYTHON_ABSTRACTOBJECT_H
819# include "cpython/abstract.h"
820# undef Py_CPYTHON_ABSTRACTOBJECT_H
821#endif
Antoine Pitrouf68c2a72010-09-01 12:58:21 +0000822
Guido van Rossum8ca687a1995-09-18 21:20:02 +0000823#ifdef __cplusplus
824}
825#endif
Guido van Rossuma8275371995-07-18 14:07:00 +0000826#endif /* Py_ABSTRACTOBJECT_H */