jpayne@69
|
1 /* Abstract Object Interface (many thanks to Jim Fulton) */
|
jpayne@69
|
2
|
jpayne@69
|
3 #ifndef Py_ABSTRACTOBJECT_H
|
jpayne@69
|
4 #define Py_ABSTRACTOBJECT_H
|
jpayne@69
|
5 #ifdef __cplusplus
|
jpayne@69
|
6 extern "C" {
|
jpayne@69
|
7 #endif
|
jpayne@69
|
8
|
jpayne@69
|
9 /* === Object Protocol ================================================== */
|
jpayne@69
|
10
|
jpayne@69
|
11 /* Implemented elsewhere:
|
jpayne@69
|
12
|
jpayne@69
|
13 int PyObject_Print(PyObject *o, FILE *fp, int flags);
|
jpayne@69
|
14
|
jpayne@69
|
15 Print an object 'o' on file 'fp'. Returns -1 on error. The flags argument
|
jpayne@69
|
16 is used to enable certain printing options. The only option currently
|
jpayne@69
|
17 supported is Py_Print_RAW.
|
jpayne@69
|
18
|
jpayne@69
|
19 (What should be said about Py_Print_RAW?). */
|
jpayne@69
|
20
|
jpayne@69
|
21
|
jpayne@69
|
22 /* Implemented elsewhere:
|
jpayne@69
|
23
|
jpayne@69
|
24 int PyObject_HasAttrString(PyObject *o, const char *attr_name);
|
jpayne@69
|
25
|
jpayne@69
|
26 Returns 1 if object 'o' has the attribute attr_name, and 0 otherwise.
|
jpayne@69
|
27
|
jpayne@69
|
28 This is equivalent to the Python expression: hasattr(o,attr_name).
|
jpayne@69
|
29
|
jpayne@69
|
30 This function always succeeds. */
|
jpayne@69
|
31
|
jpayne@69
|
32
|
jpayne@69
|
33 /* Implemented elsewhere:
|
jpayne@69
|
34
|
jpayne@69
|
35 PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name);
|
jpayne@69
|
36
|
jpayne@69
|
37 Retrieve an attributed named attr_name form object o.
|
jpayne@69
|
38 Returns the attribute value on success, or NULL on failure.
|
jpayne@69
|
39
|
jpayne@69
|
40 This is the equivalent of the Python expression: o.attr_name. */
|
jpayne@69
|
41
|
jpayne@69
|
42
|
jpayne@69
|
43 /* Implemented elsewhere:
|
jpayne@69
|
44
|
jpayne@69
|
45 int PyObject_HasAttr(PyObject *o, PyObject *attr_name);
|
jpayne@69
|
46
|
jpayne@69
|
47 Returns 1 if o has the attribute attr_name, and 0 otherwise.
|
jpayne@69
|
48
|
jpayne@69
|
49 This is equivalent to the Python expression: hasattr(o,attr_name).
|
jpayne@69
|
50
|
jpayne@69
|
51 This function always succeeds. */
|
jpayne@69
|
52
|
jpayne@69
|
53 /* Implemented elsewhere:
|
jpayne@69
|
54
|
jpayne@69
|
55 PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name);
|
jpayne@69
|
56
|
jpayne@69
|
57 Retrieve an attributed named 'attr_name' form object 'o'.
|
jpayne@69
|
58 Returns the attribute value on success, or NULL on failure.
|
jpayne@69
|
59
|
jpayne@69
|
60 This is the equivalent of the Python expression: o.attr_name. */
|
jpayne@69
|
61
|
jpayne@69
|
62
|
jpayne@69
|
63 /* Implemented elsewhere:
|
jpayne@69
|
64
|
jpayne@69
|
65 int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v);
|
jpayne@69
|
66
|
jpayne@69
|
67 Set the value of the attribute named attr_name, for object 'o',
|
jpayne@69
|
68 to the value 'v'. Raise an exception and return -1 on failure; return 0 on
|
jpayne@69
|
69 success.
|
jpayne@69
|
70
|
jpayne@69
|
71 This is the equivalent of the Python statement o.attr_name=v. */
|
jpayne@69
|
72
|
jpayne@69
|
73
|
jpayne@69
|
74 /* Implemented elsewhere:
|
jpayne@69
|
75
|
jpayne@69
|
76 int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v);
|
jpayne@69
|
77
|
jpayne@69
|
78 Set the value of the attribute named attr_name, for object 'o', to the value
|
jpayne@69
|
79 'v'. an exception and return -1 on failure; return 0 on success.
|
jpayne@69
|
80
|
jpayne@69
|
81 This is the equivalent of the Python statement o.attr_name=v. */
|
jpayne@69
|
82
|
jpayne@69
|
83 /* Implemented as a macro:
|
jpayne@69
|
84
|
jpayne@69
|
85 int PyObject_DelAttrString(PyObject *o, const char *attr_name);
|
jpayne@69
|
86
|
jpayne@69
|
87 Delete attribute named attr_name, for object o. Returns
|
jpayne@69
|
88 -1 on failure.
|
jpayne@69
|
89
|
jpayne@69
|
90 This is the equivalent of the Python statement: del o.attr_name. */
|
jpayne@69
|
91 #define PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A), NULL)
|
jpayne@69
|
92
|
jpayne@69
|
93
|
jpayne@69
|
94 /* Implemented as a macro:
|
jpayne@69
|
95
|
jpayne@69
|
96 int PyObject_DelAttr(PyObject *o, PyObject *attr_name);
|
jpayne@69
|
97
|
jpayne@69
|
98 Delete attribute named attr_name, for object o. Returns -1
|
jpayne@69
|
99 on failure. This is the equivalent of the Python
|
jpayne@69
|
100 statement: del o.attr_name. */
|
jpayne@69
|
101 #define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A), NULL)
|
jpayne@69
|
102
|
jpayne@69
|
103
|
jpayne@69
|
104 /* Implemented elsewhere:
|
jpayne@69
|
105
|
jpayne@69
|
106 PyObject *PyObject_Repr(PyObject *o);
|
jpayne@69
|
107
|
jpayne@69
|
108 Compute the string representation of object 'o'. Returns the
|
jpayne@69
|
109 string representation on success, NULL on failure.
|
jpayne@69
|
110
|
jpayne@69
|
111 This is the equivalent of the Python expression: repr(o).
|
jpayne@69
|
112
|
jpayne@69
|
113 Called by the repr() built-in function. */
|
jpayne@69
|
114
|
jpayne@69
|
115
|
jpayne@69
|
116 /* Implemented elsewhere:
|
jpayne@69
|
117
|
jpayne@69
|
118 PyObject *PyObject_Str(PyObject *o);
|
jpayne@69
|
119
|
jpayne@69
|
120 Compute the string representation of object, o. Returns the
|
jpayne@69
|
121 string representation on success, NULL on failure.
|
jpayne@69
|
122
|
jpayne@69
|
123 This is the equivalent of the Python expression: str(o).
|
jpayne@69
|
124
|
jpayne@69
|
125 Called by the str() and print() built-in functions. */
|
jpayne@69
|
126
|
jpayne@69
|
127
|
jpayne@69
|
128 /* Declared elsewhere
|
jpayne@69
|
129
|
jpayne@69
|
130 PyAPI_FUNC(int) PyCallable_Check(PyObject *o);
|
jpayne@69
|
131
|
jpayne@69
|
132 Determine if the object, o, is callable. Return 1 if the object is callable
|
jpayne@69
|
133 and 0 otherwise.
|
jpayne@69
|
134
|
jpayne@69
|
135 This function always succeeds. */
|
jpayne@69
|
136
|
jpayne@69
|
137
|
jpayne@69
|
138 #ifdef PY_SSIZE_T_CLEAN
|
jpayne@69
|
139 # define PyObject_CallFunction _PyObject_CallFunction_SizeT
|
jpayne@69
|
140 # define PyObject_CallMethod _PyObject_CallMethod_SizeT
|
jpayne@69
|
141 #endif
|
jpayne@69
|
142
|
jpayne@69
|
143
|
jpayne@69
|
144 /* Call a callable Python object 'callable' with arguments given by the
|
jpayne@69
|
145 tuple 'args' and keywords arguments given by the dictionary 'kwargs'.
|
jpayne@69
|
146
|
jpayne@69
|
147 'args' must not be NULL, use an empty tuple if no arguments are
|
jpayne@69
|
148 needed. If no named arguments are needed, 'kwargs' can be NULL.
|
jpayne@69
|
149
|
jpayne@69
|
150 This is the equivalent of the Python expression:
|
jpayne@69
|
151 callable(*args, **kwargs). */
|
jpayne@69
|
152 PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable,
|
jpayne@69
|
153 PyObject *args, PyObject *kwargs);
|
jpayne@69
|
154
|
jpayne@69
|
155
|
jpayne@69
|
156 /* Call a callable Python object 'callable', with arguments given by the
|
jpayne@69
|
157 tuple 'args'. If no arguments are needed, then 'args' can be NULL.
|
jpayne@69
|
158
|
jpayne@69
|
159 Returns the result of the call on success, or NULL on failure.
|
jpayne@69
|
160
|
jpayne@69
|
161 This is the equivalent of the Python expression:
|
jpayne@69
|
162 callable(*args). */
|
jpayne@69
|
163 PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable,
|
jpayne@69
|
164 PyObject *args);
|
jpayne@69
|
165
|
jpayne@69
|
166 /* Call a callable Python object, callable, with a variable number of C
|
jpayne@69
|
167 arguments. The C arguments are described using a mkvalue-style format
|
jpayne@69
|
168 string.
|
jpayne@69
|
169
|
jpayne@69
|
170 The format may be NULL, indicating that no arguments are provided.
|
jpayne@69
|
171
|
jpayne@69
|
172 Returns the result of the call on success, or NULL on failure.
|
jpayne@69
|
173
|
jpayne@69
|
174 This is the equivalent of the Python expression:
|
jpayne@69
|
175 callable(arg1, arg2, ...). */
|
jpayne@69
|
176 PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable,
|
jpayne@69
|
177 const char *format, ...);
|
jpayne@69
|
178
|
jpayne@69
|
179 /* Call the method named 'name' of object 'obj' with a variable number of
|
jpayne@69
|
180 C arguments. The C arguments are described by a mkvalue format string.
|
jpayne@69
|
181
|
jpayne@69
|
182 The format can be NULL, indicating that no arguments are provided.
|
jpayne@69
|
183
|
jpayne@69
|
184 Returns the result of the call on success, or NULL on failure.
|
jpayne@69
|
185
|
jpayne@69
|
186 This is the equivalent of the Python expression:
|
jpayne@69
|
187 obj.name(arg1, arg2, ...). */
|
jpayne@69
|
188 PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *obj,
|
jpayne@69
|
189 const char *name,
|
jpayne@69
|
190 const char *format, ...);
|
jpayne@69
|
191
|
jpayne@69
|
192 PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable,
|
jpayne@69
|
193 const char *format,
|
jpayne@69
|
194 ...);
|
jpayne@69
|
195
|
jpayne@69
|
196 PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *obj,
|
jpayne@69
|
197 const char *name,
|
jpayne@69
|
198 const char *format,
|
jpayne@69
|
199 ...);
|
jpayne@69
|
200
|
jpayne@69
|
201 /* Call a callable Python object 'callable' with a variable number of C
|
jpayne@69
|
202 arguments. The C arguments are provided as PyObject* values, terminated
|
jpayne@69
|
203 by a NULL.
|
jpayne@69
|
204
|
jpayne@69
|
205 Returns the result of the call on success, or NULL on failure.
|
jpayne@69
|
206
|
jpayne@69
|
207 This is the equivalent of the Python expression:
|
jpayne@69
|
208 callable(arg1, arg2, ...). */
|
jpayne@69
|
209 PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable,
|
jpayne@69
|
210 ...);
|
jpayne@69
|
211
|
jpayne@69
|
212 /* Call the method named 'name' of object 'obj' with a variable number of
|
jpayne@69
|
213 C arguments. The C arguments are provided as PyObject* values, terminated
|
jpayne@69
|
214 by NULL.
|
jpayne@69
|
215
|
jpayne@69
|
216 Returns the result of the call on success, or NULL on failure.
|
jpayne@69
|
217
|
jpayne@69
|
218 This is the equivalent of the Python expression: obj.name(*args). */
|
jpayne@69
|
219
|
jpayne@69
|
220 PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(
|
jpayne@69
|
221 PyObject *obj,
|
jpayne@69
|
222 PyObject *name,
|
jpayne@69
|
223 ...);
|
jpayne@69
|
224
|
jpayne@69
|
225
|
jpayne@69
|
226 /* Implemented elsewhere:
|
jpayne@69
|
227
|
jpayne@69
|
228 Py_hash_t PyObject_Hash(PyObject *o);
|
jpayne@69
|
229
|
jpayne@69
|
230 Compute and return the hash, hash_value, of an object, o. On
|
jpayne@69
|
231 failure, return -1.
|
jpayne@69
|
232
|
jpayne@69
|
233 This is the equivalent of the Python expression: hash(o). */
|
jpayne@69
|
234
|
jpayne@69
|
235
|
jpayne@69
|
236 /* Implemented elsewhere:
|
jpayne@69
|
237
|
jpayne@69
|
238 int PyObject_IsTrue(PyObject *o);
|
jpayne@69
|
239
|
jpayne@69
|
240 Returns 1 if the object, o, is considered to be true, 0 if o is
|
jpayne@69
|
241 considered to be false and -1 on failure.
|
jpayne@69
|
242
|
jpayne@69
|
243 This is equivalent to the Python expression: not not o. */
|
jpayne@69
|
244
|
jpayne@69
|
245
|
jpayne@69
|
246 /* Implemented elsewhere:
|
jpayne@69
|
247
|
jpayne@69
|
248 int PyObject_Not(PyObject *o);
|
jpayne@69
|
249
|
jpayne@69
|
250 Returns 0 if the object, o, is considered to be true, 1 if o is
|
jpayne@69
|
251 considered to be false and -1 on failure.
|
jpayne@69
|
252
|
jpayne@69
|
253 This is equivalent to the Python expression: not o. */
|
jpayne@69
|
254
|
jpayne@69
|
255
|
jpayne@69
|
256 /* Get the type of an object.
|
jpayne@69
|
257
|
jpayne@69
|
258 On success, returns a type object corresponding to the object type of object
|
jpayne@69
|
259 'o'. On failure, returns NULL.
|
jpayne@69
|
260
|
jpayne@69
|
261 This is equivalent to the Python expression: type(o) */
|
jpayne@69
|
262 PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o);
|
jpayne@69
|
263
|
jpayne@69
|
264
|
jpayne@69
|
265 /* Return the size of object 'o'. If the object 'o' provides both sequence and
|
jpayne@69
|
266 mapping protocols, the sequence size is returned.
|
jpayne@69
|
267
|
jpayne@69
|
268 On error, -1 is returned.
|
jpayne@69
|
269
|
jpayne@69
|
270 This is the equivalent to the Python expression: len(o) */
|
jpayne@69
|
271 PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o);
|
jpayne@69
|
272
|
jpayne@69
|
273
|
jpayne@69
|
274 /* For DLL compatibility */
|
jpayne@69
|
275 #undef PyObject_Length
|
jpayne@69
|
276 PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o);
|
jpayne@69
|
277 #define PyObject_Length PyObject_Size
|
jpayne@69
|
278
|
jpayne@69
|
279 /* Return element of 'o' corresponding to the object 'key'. Return NULL
|
jpayne@69
|
280 on failure.
|
jpayne@69
|
281
|
jpayne@69
|
282 This is the equivalent of the Python expression: o[key] */
|
jpayne@69
|
283 PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key);
|
jpayne@69
|
284
|
jpayne@69
|
285
|
jpayne@69
|
286 /* Map the object 'key' to the value 'v' into 'o'.
|
jpayne@69
|
287
|
jpayne@69
|
288 Raise an exception and return -1 on failure; return 0 on success.
|
jpayne@69
|
289
|
jpayne@69
|
290 This is the equivalent of the Python statement: o[key]=v. */
|
jpayne@69
|
291 PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v);
|
jpayne@69
|
292
|
jpayne@69
|
293 /* Remove the mapping for the string 'key' from the object 'o'.
|
jpayne@69
|
294 Returns -1 on failure.
|
jpayne@69
|
295
|
jpayne@69
|
296 This is equivalent to the Python statement: del o[key]. */
|
jpayne@69
|
297 PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key);
|
jpayne@69
|
298
|
jpayne@69
|
299 /* Delete the mapping for the object 'key' from the object 'o'.
|
jpayne@69
|
300 Returns -1 on failure.
|
jpayne@69
|
301
|
jpayne@69
|
302 This is the equivalent of the Python statement: del o[key]. */
|
jpayne@69
|
303 PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key);
|
jpayne@69
|
304
|
jpayne@69
|
305
|
jpayne@69
|
306 /* === Old Buffer API ============================================ */
|
jpayne@69
|
307
|
jpayne@69
|
308 /* FIXME: usage of these should all be replaced in Python itself
|
jpayne@69
|
309 but for backwards compatibility we will implement them.
|
jpayne@69
|
310 Their usage without a corresponding "unlock" mechanism
|
jpayne@69
|
311 may create issues (but they would already be there). */
|
jpayne@69
|
312
|
jpayne@69
|
313 /* Takes an arbitrary object which must support the (character, single segment)
|
jpayne@69
|
314 buffer interface and returns a pointer to a read-only memory location
|
jpayne@69
|
315 useable as character based input for subsequent processing.
|
jpayne@69
|
316
|
jpayne@69
|
317 Return 0 on success. buffer and buffer_len are only set in case no error
|
jpayne@69
|
318 occurs. Otherwise, -1 is returned and an exception set. */
|
jpayne@69
|
319 Py_DEPRECATED(3.0)
|
jpayne@69
|
320 PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj,
|
jpayne@69
|
321 const char **buffer,
|
jpayne@69
|
322 Py_ssize_t *buffer_len);
|
jpayne@69
|
323
|
jpayne@69
|
324 /* Checks whether an arbitrary object supports the (character, single segment)
|
jpayne@69
|
325 buffer interface.
|
jpayne@69
|
326
|
jpayne@69
|
327 Returns 1 on success, 0 on failure. */
|
jpayne@69
|
328 Py_DEPRECATED(3.0) PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj);
|
jpayne@69
|
329
|
jpayne@69
|
330 /* Same as PyObject_AsCharBuffer() except that this API expects (readable,
|
jpayne@69
|
331 single segment) buffer interface and returns a pointer to a read-only memory
|
jpayne@69
|
332 location which can contain arbitrary data.
|
jpayne@69
|
333
|
jpayne@69
|
334 0 is returned on success. buffer and buffer_len are only set in case no
|
jpayne@69
|
335 error occurs. Otherwise, -1 is returned and an exception set. */
|
jpayne@69
|
336 Py_DEPRECATED(3.0)
|
jpayne@69
|
337 PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj,
|
jpayne@69
|
338 const void **buffer,
|
jpayne@69
|
339 Py_ssize_t *buffer_len);
|
jpayne@69
|
340
|
jpayne@69
|
341 /* Takes an arbitrary object which must support the (writable, single segment)
|
jpayne@69
|
342 buffer interface and returns a pointer to a writable memory location in
|
jpayne@69
|
343 buffer of size 'buffer_len'.
|
jpayne@69
|
344
|
jpayne@69
|
345 Return 0 on success. buffer and buffer_len are only set in case no error
|
jpayne@69
|
346 occurs. Otherwise, -1 is returned and an exception set. */
|
jpayne@69
|
347 Py_DEPRECATED(3.0)
|
jpayne@69
|
348 PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj,
|
jpayne@69
|
349 void **buffer,
|
jpayne@69
|
350 Py_ssize_t *buffer_len);
|
jpayne@69
|
351
|
jpayne@69
|
352
|
jpayne@69
|
353 /* === New Buffer API ============================================ */
|
jpayne@69
|
354
|
jpayne@69
|
355 /* Takes an arbitrary object and returns the result of calling
|
jpayne@69
|
356 obj.__format__(format_spec). */
|
jpayne@69
|
357 PyAPI_FUNC(PyObject *) PyObject_Format(PyObject *obj,
|
jpayne@69
|
358 PyObject *format_spec);
|
jpayne@69
|
359
|
jpayne@69
|
360
|
jpayne@69
|
361 /* ==== Iterators ================================================ */
|
jpayne@69
|
362
|
jpayne@69
|
363 /* Takes an object and returns an iterator for it.
|
jpayne@69
|
364 This is typically a new iterator but if the argument is an iterator, this
|
jpayne@69
|
365 returns itself. */
|
jpayne@69
|
366 PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);
|
jpayne@69
|
367
|
jpayne@69
|
368 /* Returns 1 if the object 'obj' provides iterator protocols, and 0 otherwise.
|
jpayne@69
|
369
|
jpayne@69
|
370 This function always succeeds. */
|
jpayne@69
|
371 PyAPI_FUNC(int) PyIter_Check(PyObject *);
|
jpayne@69
|
372
|
jpayne@69
|
373 /* Takes an iterator object and calls its tp_iternext slot,
|
jpayne@69
|
374 returning the next value.
|
jpayne@69
|
375
|
jpayne@69
|
376 If the iterator is exhausted, this returns NULL without setting an
|
jpayne@69
|
377 exception.
|
jpayne@69
|
378
|
jpayne@69
|
379 NULL with an exception means an error occurred. */
|
jpayne@69
|
380 PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *);
|
jpayne@69
|
381
|
jpayne@69
|
382
|
jpayne@69
|
383 /* === Number Protocol ================================================== */
|
jpayne@69
|
384
|
jpayne@69
|
385 /* Returns 1 if the object 'o' provides numeric protocols, and 0 otherwise.
|
jpayne@69
|
386
|
jpayne@69
|
387 This function always succeeds. */
|
jpayne@69
|
388 PyAPI_FUNC(int) PyNumber_Check(PyObject *o);
|
jpayne@69
|
389
|
jpayne@69
|
390 /* Returns the result of adding o1 and o2, or NULL on failure.
|
jpayne@69
|
391
|
jpayne@69
|
392 This is the equivalent of the Python expression: o1 + o2. */
|
jpayne@69
|
393 PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2);
|
jpayne@69
|
394
|
jpayne@69
|
395 /* Returns the result of subtracting o2 from o1, or NULL on failure.
|
jpayne@69
|
396
|
jpayne@69
|
397 This is the equivalent of the Python expression: o1 - o2. */
|
jpayne@69
|
398 PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2);
|
jpayne@69
|
399
|
jpayne@69
|
400 /* Returns the result of multiplying o1 and o2, or NULL on failure.
|
jpayne@69
|
401
|
jpayne@69
|
402 This is the equivalent of the Python expression: o1 * o2. */
|
jpayne@69
|
403 PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2);
|
jpayne@69
|
404
|
jpayne@69
|
405 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
|
jpayne@69
|
406 /* This is the equivalent of the Python expression: o1 @ o2. */
|
jpayne@69
|
407 PyAPI_FUNC(PyObject *) PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2);
|
jpayne@69
|
408 #endif
|
jpayne@69
|
409
|
jpayne@69
|
410 /* Returns the result of dividing o1 by o2 giving an integral result,
|
jpayne@69
|
411 or NULL on failure.
|
jpayne@69
|
412
|
jpayne@69
|
413 This is the equivalent of the Python expression: o1 // o2. */
|
jpayne@69
|
414 PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2);
|
jpayne@69
|
415
|
jpayne@69
|
416 /* Returns the result of dividing o1 by o2 giving a float result, or NULL on
|
jpayne@69
|
417 failure.
|
jpayne@69
|
418
|
jpayne@69
|
419 This is the equivalent of the Python expression: o1 / o2. */
|
jpayne@69
|
420 PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2);
|
jpayne@69
|
421
|
jpayne@69
|
422 /* Returns the remainder of dividing o1 by o2, or NULL on failure.
|
jpayne@69
|
423
|
jpayne@69
|
424 This is the equivalent of the Python expression: o1 % o2. */
|
jpayne@69
|
425 PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2);
|
jpayne@69
|
426
|
jpayne@69
|
427 /* See the built-in function divmod.
|
jpayne@69
|
428
|
jpayne@69
|
429 Returns NULL on failure.
|
jpayne@69
|
430
|
jpayne@69
|
431 This is the equivalent of the Python expression: divmod(o1, o2). */
|
jpayne@69
|
432 PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2);
|
jpayne@69
|
433
|
jpayne@69
|
434 /* See the built-in function pow. Returns NULL on failure.
|
jpayne@69
|
435
|
jpayne@69
|
436 This is the equivalent of the Python expression: pow(o1, o2, o3),
|
jpayne@69
|
437 where o3 is optional. */
|
jpayne@69
|
438 PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2,
|
jpayne@69
|
439 PyObject *o3);
|
jpayne@69
|
440
|
jpayne@69
|
441 /* Returns the negation of o on success, or NULL on failure.
|
jpayne@69
|
442
|
jpayne@69
|
443 This is the equivalent of the Python expression: -o. */
|
jpayne@69
|
444 PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o);
|
jpayne@69
|
445
|
jpayne@69
|
446 /* Returns the positive of o on success, or NULL on failure.
|
jpayne@69
|
447
|
jpayne@69
|
448 This is the equivalent of the Python expression: +o. */
|
jpayne@69
|
449 PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o);
|
jpayne@69
|
450
|
jpayne@69
|
451 /* Returns the absolute value of 'o', or NULL on failure.
|
jpayne@69
|
452
|
jpayne@69
|
453 This is the equivalent of the Python expression: abs(o). */
|
jpayne@69
|
454 PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o);
|
jpayne@69
|
455
|
jpayne@69
|
456 /* Returns the bitwise negation of 'o' on success, or NULL on failure.
|
jpayne@69
|
457
|
jpayne@69
|
458 This is the equivalent of the Python expression: ~o. */
|
jpayne@69
|
459 PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o);
|
jpayne@69
|
460
|
jpayne@69
|
461 /* Returns the result of left shifting o1 by o2 on success, or NULL on failure.
|
jpayne@69
|
462
|
jpayne@69
|
463 This is the equivalent of the Python expression: o1 << o2. */
|
jpayne@69
|
464 PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2);
|
jpayne@69
|
465
|
jpayne@69
|
466 /* Returns the result of right shifting o1 by o2 on success, or NULL on
|
jpayne@69
|
467 failure.
|
jpayne@69
|
468
|
jpayne@69
|
469 This is the equivalent of the Python expression: o1 >> o2. */
|
jpayne@69
|
470 PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2);
|
jpayne@69
|
471
|
jpayne@69
|
472 /* Returns the result of bitwise and of o1 and o2 on success, or NULL on
|
jpayne@69
|
473 failure.
|
jpayne@69
|
474
|
jpayne@69
|
475 This is the equivalent of the Python expression: o1 & o2. */
|
jpayne@69
|
476 PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2);
|
jpayne@69
|
477
|
jpayne@69
|
478 /* Returns the bitwise exclusive or of o1 by o2 on success, or NULL on failure.
|
jpayne@69
|
479
|
jpayne@69
|
480 This is the equivalent of the Python expression: o1 ^ o2. */
|
jpayne@69
|
481 PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2);
|
jpayne@69
|
482
|
jpayne@69
|
483 /* Returns the result of bitwise or on o1 and o2 on success, or NULL on
|
jpayne@69
|
484 failure.
|
jpayne@69
|
485
|
jpayne@69
|
486 This is the equivalent of the Python expression: o1 | o2. */
|
jpayne@69
|
487 PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2);
|
jpayne@69
|
488
|
jpayne@69
|
489 /* Returns 1 if obj is an index integer (has the nb_index slot of the
|
jpayne@69
|
490 tp_as_number structure filled in), and 0 otherwise. */
|
jpayne@69
|
491 PyAPI_FUNC(int) PyIndex_Check(PyObject *);
|
jpayne@69
|
492
|
jpayne@69
|
493 /* Returns the object 'o' converted to a Python int, or NULL with an exception
|
jpayne@69
|
494 raised on failure. */
|
jpayne@69
|
495 PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o);
|
jpayne@69
|
496
|
jpayne@69
|
497 /* Returns the object 'o' converted to Py_ssize_t by going through
|
jpayne@69
|
498 PyNumber_Index() first.
|
jpayne@69
|
499
|
jpayne@69
|
500 If an overflow error occurs while converting the int to Py_ssize_t, then the
|
jpayne@69
|
501 second argument 'exc' is the error-type to return. If it is NULL, then the
|
jpayne@69
|
502 overflow error is cleared and the value is clipped. */
|
jpayne@69
|
503 PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc);
|
jpayne@69
|
504
|
jpayne@69
|
505 /* Returns the object 'o' converted to an integer object on success, or NULL
|
jpayne@69
|
506 on failure.
|
jpayne@69
|
507
|
jpayne@69
|
508 This is the equivalent of the Python expression: int(o). */
|
jpayne@69
|
509 PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o);
|
jpayne@69
|
510
|
jpayne@69
|
511 /* Returns the object 'o' converted to a float object on success, or NULL
|
jpayne@69
|
512 on failure.
|
jpayne@69
|
513
|
jpayne@69
|
514 This is the equivalent of the Python expression: float(o). */
|
jpayne@69
|
515 PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o);
|
jpayne@69
|
516
|
jpayne@69
|
517
|
jpayne@69
|
518 /* --- In-place variants of (some of) the above number protocol functions -- */
|
jpayne@69
|
519
|
jpayne@69
|
520 /* Returns the result of adding o2 to o1, possibly in-place, or NULL
|
jpayne@69
|
521 on failure.
|
jpayne@69
|
522
|
jpayne@69
|
523 This is the equivalent of the Python expression: o1 += o2. */
|
jpayne@69
|
524 PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2);
|
jpayne@69
|
525
|
jpayne@69
|
526 /* Returns the result of subtracting o2 from o1, possibly in-place or
|
jpayne@69
|
527 NULL on failure.
|
jpayne@69
|
528
|
jpayne@69
|
529 This is the equivalent of the Python expression: o1 -= o2. */
|
jpayne@69
|
530 PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2);
|
jpayne@69
|
531
|
jpayne@69
|
532 /* Returns the result of multiplying o1 by o2, possibly in-place, or NULL on
|
jpayne@69
|
533 failure.
|
jpayne@69
|
534
|
jpayne@69
|
535 This is the equivalent of the Python expression: o1 *= o2. */
|
jpayne@69
|
536 PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2);
|
jpayne@69
|
537
|
jpayne@69
|
538 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
|
jpayne@69
|
539 /* This is the equivalent of the Python expression: o1 @= o2. */
|
jpayne@69
|
540 PyAPI_FUNC(PyObject *) PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2);
|
jpayne@69
|
541 #endif
|
jpayne@69
|
542
|
jpayne@69
|
543 /* Returns the result of dividing o1 by o2 giving an integral result, possibly
|
jpayne@69
|
544 in-place, or NULL on failure.
|
jpayne@69
|
545
|
jpayne@69
|
546 This is the equivalent of the Python expression: o1 /= o2. */
|
jpayne@69
|
547 PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1,
|
jpayne@69
|
548 PyObject *o2);
|
jpayne@69
|
549
|
jpayne@69
|
550 /* Returns the result of dividing o1 by o2 giving a float result, possibly
|
jpayne@69
|
551 in-place, or null on failure.
|
jpayne@69
|
552
|
jpayne@69
|
553 This is the equivalent of the Python expression: o1 /= o2. */
|
jpayne@69
|
554 PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1,
|
jpayne@69
|
555 PyObject *o2);
|
jpayne@69
|
556
|
jpayne@69
|
557 /* Returns the remainder of dividing o1 by o2, possibly in-place, or NULL on
|
jpayne@69
|
558 failure.
|
jpayne@69
|
559
|
jpayne@69
|
560 This is the equivalent of the Python expression: o1 %= o2. */
|
jpayne@69
|
561 PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2);
|
jpayne@69
|
562
|
jpayne@69
|
563 /* Returns the result of raising o1 to the power of o2, possibly in-place,
|
jpayne@69
|
564 or NULL on failure.
|
jpayne@69
|
565
|
jpayne@69
|
566 This is the equivalent of the Python expression: o1 **= o2,
|
jpayne@69
|
567 or o1 = pow(o1, o2, o3) if o3 is present. */
|
jpayne@69
|
568 PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2,
|
jpayne@69
|
569 PyObject *o3);
|
jpayne@69
|
570
|
jpayne@69
|
571 /* Returns the result of left shifting o1 by o2, possibly in-place, or NULL
|
jpayne@69
|
572 on failure.
|
jpayne@69
|
573
|
jpayne@69
|
574 This is the equivalent of the Python expression: o1 <<= o2. */
|
jpayne@69
|
575 PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2);
|
jpayne@69
|
576
|
jpayne@69
|
577 /* Returns the result of right shifting o1 by o2, possibly in-place or NULL
|
jpayne@69
|
578 on failure.
|
jpayne@69
|
579
|
jpayne@69
|
580 This is the equivalent of the Python expression: o1 >>= o2. */
|
jpayne@69
|
581 PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2);
|
jpayne@69
|
582
|
jpayne@69
|
583 /* Returns the result of bitwise and of o1 and o2, possibly in-place, or NULL
|
jpayne@69
|
584 on failure.
|
jpayne@69
|
585
|
jpayne@69
|
586 This is the equivalent of the Python expression: o1 &= o2. */
|
jpayne@69
|
587 PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2);
|
jpayne@69
|
588
|
jpayne@69
|
589 /* Returns the bitwise exclusive or of o1 by o2, possibly in-place, or NULL
|
jpayne@69
|
590 on failure.
|
jpayne@69
|
591
|
jpayne@69
|
592 This is the equivalent of the Python expression: o1 ^= o2. */
|
jpayne@69
|
593 PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2);
|
jpayne@69
|
594
|
jpayne@69
|
595 /* Returns the result of bitwise or of o1 and o2, possibly in-place,
|
jpayne@69
|
596 or NULL on failure.
|
jpayne@69
|
597
|
jpayne@69
|
598 This is the equivalent of the Python expression: o1 |= o2. */
|
jpayne@69
|
599 PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2);
|
jpayne@69
|
600
|
jpayne@69
|
601 /* Returns the integer n converted to a string with a base, with a base
|
jpayne@69
|
602 marker of 0b, 0o or 0x prefixed if applicable.
|
jpayne@69
|
603
|
jpayne@69
|
604 If n is not an int object, it is converted with PyNumber_Index first. */
|
jpayne@69
|
605 PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base);
|
jpayne@69
|
606
|
jpayne@69
|
607
|
jpayne@69
|
608 /* === Sequence protocol ================================================ */
|
jpayne@69
|
609
|
jpayne@69
|
610 /* Return 1 if the object provides sequence protocol, and zero
|
jpayne@69
|
611 otherwise.
|
jpayne@69
|
612
|
jpayne@69
|
613 This function always succeeds. */
|
jpayne@69
|
614 PyAPI_FUNC(int) PySequence_Check(PyObject *o);
|
jpayne@69
|
615
|
jpayne@69
|
616 /* Return the size of sequence object o, or -1 on failure. */
|
jpayne@69
|
617 PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o);
|
jpayne@69
|
618
|
jpayne@69
|
619 /* For DLL compatibility */
|
jpayne@69
|
620 #undef PySequence_Length
|
jpayne@69
|
621 PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o);
|
jpayne@69
|
622 #define PySequence_Length PySequence_Size
|
jpayne@69
|
623
|
jpayne@69
|
624
|
jpayne@69
|
625 /* Return the concatenation of o1 and o2 on success, and NULL on failure.
|
jpayne@69
|
626
|
jpayne@69
|
627 This is the equivalent of the Python expression: o1 + o2. */
|
jpayne@69
|
628 PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2);
|
jpayne@69
|
629
|
jpayne@69
|
630 /* Return the result of repeating sequence object 'o' 'count' times,
|
jpayne@69
|
631 or NULL on failure.
|
jpayne@69
|
632
|
jpayne@69
|
633 This is the equivalent of the Python expression: o * count. */
|
jpayne@69
|
634 PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count);
|
jpayne@69
|
635
|
jpayne@69
|
636 /* Return the ith element of o, or NULL on failure.
|
jpayne@69
|
637
|
jpayne@69
|
638 This is the equivalent of the Python expression: o[i]. */
|
jpayne@69
|
639 PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i);
|
jpayne@69
|
640
|
jpayne@69
|
641 /* Return the slice of sequence object o between i1 and i2, or NULL on failure.
|
jpayne@69
|
642
|
jpayne@69
|
643 This is the equivalent of the Python expression: o[i1:i2]. */
|
jpayne@69
|
644 PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
|
jpayne@69
|
645
|
jpayne@69
|
646 /* Assign object 'v' to the ith element of the sequence 'o'. Raise an exception
|
jpayne@69
|
647 and return -1 on failure; return 0 on success.
|
jpayne@69
|
648
|
jpayne@69
|
649 This is the equivalent of the Python statement o[i] = v. */
|
jpayne@69
|
650 PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v);
|
jpayne@69
|
651
|
jpayne@69
|
652 /* Delete the 'i'-th element of the sequence 'v'. Returns -1 on failure.
|
jpayne@69
|
653
|
jpayne@69
|
654 This is the equivalent of the Python statement: del o[i]. */
|
jpayne@69
|
655 PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i);
|
jpayne@69
|
656
|
jpayne@69
|
657 /* Assign the sequence object 'v' to the slice in sequence object 'o',
|
jpayne@69
|
658 from 'i1' to 'i2'. Returns -1 on failure.
|
jpayne@69
|
659
|
jpayne@69
|
660 This is the equivalent of the Python statement: o[i1:i2] = v. */
|
jpayne@69
|
661 PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2,
|
jpayne@69
|
662 PyObject *v);
|
jpayne@69
|
663
|
jpayne@69
|
664 /* Delete the slice in sequence object 'o' from 'i1' to 'i2'.
|
jpayne@69
|
665 Returns -1 on failure.
|
jpayne@69
|
666
|
jpayne@69
|
667 This is the equivalent of the Python statement: del o[i1:i2]. */
|
jpayne@69
|
668 PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
|
jpayne@69
|
669
|
jpayne@69
|
670 /* Returns the sequence 'o' as a tuple on success, and NULL on failure.
|
jpayne@69
|
671
|
jpayne@69
|
672 This is equivalent to the Python expression: tuple(o). */
|
jpayne@69
|
673 PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o);
|
jpayne@69
|
674
|
jpayne@69
|
675 /* Returns the sequence 'o' as a list on success, and NULL on failure.
|
jpayne@69
|
676 This is equivalent to the Python expression: list(o) */
|
jpayne@69
|
677 PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o);
|
jpayne@69
|
678
|
jpayne@69
|
679 /* Return the sequence 'o' as a list, unless it's already a tuple or list.
|
jpayne@69
|
680
|
jpayne@69
|
681 Use PySequence_Fast_GET_ITEM to access the members of this list, and
|
jpayne@69
|
682 PySequence_Fast_GET_SIZE to get its length.
|
jpayne@69
|
683
|
jpayne@69
|
684 Returns NULL on failure. If the object does not support iteration, raises a
|
jpayne@69
|
685 TypeError exception with 'm' as the message text. */
|
jpayne@69
|
686 PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m);
|
jpayne@69
|
687
|
jpayne@69
|
688 /* Return the size of the sequence 'o', assuming that 'o' was returned by
|
jpayne@69
|
689 PySequence_Fast and is not NULL. */
|
jpayne@69
|
690 #define PySequence_Fast_GET_SIZE(o) \
|
jpayne@69
|
691 (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o))
|
jpayne@69
|
692
|
jpayne@69
|
693 /* Return the 'i'-th element of the sequence 'o', assuming that o was returned
|
jpayne@69
|
694 by PySequence_Fast, and that i is within bounds. */
|
jpayne@69
|
695 #define PySequence_Fast_GET_ITEM(o, i)\
|
jpayne@69
|
696 (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))
|
jpayne@69
|
697
|
jpayne@69
|
698 /* Return a pointer to the underlying item array for
|
jpayne@69
|
699 an object retured by PySequence_Fast */
|
jpayne@69
|
700 #define PySequence_Fast_ITEMS(sf) \
|
jpayne@69
|
701 (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \
|
jpayne@69
|
702 : ((PyTupleObject *)(sf))->ob_item)
|
jpayne@69
|
703
|
jpayne@69
|
704 /* Return the number of occurrences on value on 'o', that is, return
|
jpayne@69
|
705 the number of keys for which o[key] == value.
|
jpayne@69
|
706
|
jpayne@69
|
707 On failure, return -1. This is equivalent to the Python expression:
|
jpayne@69
|
708 o.count(value). */
|
jpayne@69
|
709 PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value);
|
jpayne@69
|
710
|
jpayne@69
|
711 /* Return 1 if 'ob' is in the sequence 'seq'; 0 if 'ob' is not in the sequence
|
jpayne@69
|
712 'seq'; -1 on error.
|
jpayne@69
|
713
|
jpayne@69
|
714 Use __contains__ if possible, else _PySequence_IterSearch(). */
|
jpayne@69
|
715 PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob);
|
jpayne@69
|
716
|
jpayne@69
|
717 /* For DLL-level backwards compatibility */
|
jpayne@69
|
718 #undef PySequence_In
|
jpayne@69
|
719 /* Determine if the sequence 'o' contains 'value'. If an item in 'o' is equal
|
jpayne@69
|
720 to 'value', return 1, otherwise return 0. On error, return -1.
|
jpayne@69
|
721
|
jpayne@69
|
722 This is equivalent to the Python expression: value in o. */
|
jpayne@69
|
723 PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value);
|
jpayne@69
|
724
|
jpayne@69
|
725 /* For source-level backwards compatibility */
|
jpayne@69
|
726 #define PySequence_In PySequence_Contains
|
jpayne@69
|
727
|
jpayne@69
|
728
|
jpayne@69
|
729 /* Return the first index for which o[i] == value.
|
jpayne@69
|
730 On error, return -1.
|
jpayne@69
|
731
|
jpayne@69
|
732 This is equivalent to the Python expression: o.index(value). */
|
jpayne@69
|
733 PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value);
|
jpayne@69
|
734
|
jpayne@69
|
735
|
jpayne@69
|
736 /* --- In-place versions of some of the above Sequence functions --- */
|
jpayne@69
|
737
|
jpayne@69
|
738 /* Append sequence 'o2' to sequence 'o1', in-place when possible. Return the
|
jpayne@69
|
739 resulting object, which could be 'o1', or NULL on failure.
|
jpayne@69
|
740
|
jpayne@69
|
741 This is the equivalent of the Python expression: o1 += o2. */
|
jpayne@69
|
742 PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2);
|
jpayne@69
|
743
|
jpayne@69
|
744 /* Repeat sequence 'o' by 'count', in-place when possible. Return the resulting
|
jpayne@69
|
745 object, which could be 'o', or NULL on failure.
|
jpayne@69
|
746
|
jpayne@69
|
747 This is the equivalent of the Python expression: o1 *= count. */
|
jpayne@69
|
748 PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count);
|
jpayne@69
|
749
|
jpayne@69
|
750
|
jpayne@69
|
751 /* === Mapping protocol ================================================= */
|
jpayne@69
|
752
|
jpayne@69
|
753 /* Return 1 if the object provides mapping protocol, and 0 otherwise.
|
jpayne@69
|
754
|
jpayne@69
|
755 This function always succeeds. */
|
jpayne@69
|
756 PyAPI_FUNC(int) PyMapping_Check(PyObject *o);
|
jpayne@69
|
757
|
jpayne@69
|
758 /* Returns the number of keys in mapping object 'o' on success, and -1 on
|
jpayne@69
|
759 failure. This is equivalent to the Python expression: len(o). */
|
jpayne@69
|
760 PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o);
|
jpayne@69
|
761
|
jpayne@69
|
762 /* For DLL compatibility */
|
jpayne@69
|
763 #undef PyMapping_Length
|
jpayne@69
|
764 PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o);
|
jpayne@69
|
765 #define PyMapping_Length PyMapping_Size
|
jpayne@69
|
766
|
jpayne@69
|
767
|
jpayne@69
|
768 /* Implemented as a macro:
|
jpayne@69
|
769
|
jpayne@69
|
770 int PyMapping_DelItemString(PyObject *o, const char *key);
|
jpayne@69
|
771
|
jpayne@69
|
772 Remove the mapping for the string 'key' from the mapping 'o'. Returns -1 on
|
jpayne@69
|
773 failure.
|
jpayne@69
|
774
|
jpayne@69
|
775 This is equivalent to the Python statement: del o[key]. */
|
jpayne@69
|
776 #define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K))
|
jpayne@69
|
777
|
jpayne@69
|
778 /* Implemented as a macro:
|
jpayne@69
|
779
|
jpayne@69
|
780 int PyMapping_DelItem(PyObject *o, PyObject *key);
|
jpayne@69
|
781
|
jpayne@69
|
782 Remove the mapping for the object 'key' from the mapping object 'o'.
|
jpayne@69
|
783 Returns -1 on failure.
|
jpayne@69
|
784
|
jpayne@69
|
785 This is equivalent to the Python statement: del o[key]. */
|
jpayne@69
|
786 #define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K))
|
jpayne@69
|
787
|
jpayne@69
|
788 /* On success, return 1 if the mapping object 'o' has the key 'key',
|
jpayne@69
|
789 and 0 otherwise.
|
jpayne@69
|
790
|
jpayne@69
|
791 This is equivalent to the Python expression: key in o.
|
jpayne@69
|
792
|
jpayne@69
|
793 This function always succeeds. */
|
jpayne@69
|
794 PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, const char *key);
|
jpayne@69
|
795
|
jpayne@69
|
796 /* Return 1 if the mapping object has the key 'key', and 0 otherwise.
|
jpayne@69
|
797
|
jpayne@69
|
798 This is equivalent to the Python expression: key in o.
|
jpayne@69
|
799
|
jpayne@69
|
800 This function always succeeds. */
|
jpayne@69
|
801 PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key);
|
jpayne@69
|
802
|
jpayne@69
|
803 /* On success, return a list or tuple of the keys in mapping object 'o'.
|
jpayne@69
|
804 On failure, return NULL. */
|
jpayne@69
|
805 PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o);
|
jpayne@69
|
806
|
jpayne@69
|
807 /* On success, return a list or tuple of the values in mapping object 'o'.
|
jpayne@69
|
808 On failure, return NULL. */
|
jpayne@69
|
809 PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o);
|
jpayne@69
|
810
|
jpayne@69
|
811 /* On success, return a list or tuple of the items in mapping object 'o',
|
jpayne@69
|
812 where each item is a tuple containing a key-value pair. On failure, return
|
jpayne@69
|
813 NULL. */
|
jpayne@69
|
814 PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o);
|
jpayne@69
|
815
|
jpayne@69
|
816 /* Return element of 'o' corresponding to the string 'key' or NULL on failure.
|
jpayne@69
|
817
|
jpayne@69
|
818 This is the equivalent of the Python expression: o[key]. */
|
jpayne@69
|
819 PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o,
|
jpayne@69
|
820 const char *key);
|
jpayne@69
|
821
|
jpayne@69
|
822 /* Map the string 'key' to the value 'v' in the mapping 'o'.
|
jpayne@69
|
823 Returns -1 on failure.
|
jpayne@69
|
824
|
jpayne@69
|
825 This is the equivalent of the Python statement: o[key]=v. */
|
jpayne@69
|
826 PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, const char *key,
|
jpayne@69
|
827 PyObject *value);
|
jpayne@69
|
828
|
jpayne@69
|
829 /* isinstance(object, typeorclass) */
|
jpayne@69
|
830 PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass);
|
jpayne@69
|
831
|
jpayne@69
|
832 /* issubclass(object, typeorclass) */
|
jpayne@69
|
833 PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass);
|
jpayne@69
|
834
|
jpayne@69
|
835 #ifndef Py_LIMITED_API
|
jpayne@69
|
836 # define Py_CPYTHON_ABSTRACTOBJECT_H
|
jpayne@69
|
837 # include "cpython/abstract.h"
|
jpayne@69
|
838 # undef Py_CPYTHON_ABSTRACTOBJECT_H
|
jpayne@69
|
839 #endif
|
jpayne@69
|
840
|
jpayne@69
|
841 #ifdef __cplusplus
|
jpayne@69
|
842 }
|
jpayne@69
|
843 #endif
|
jpayne@69
|
844 #endif /* Py_ABSTRACTOBJECT_H */
|