Chris@87
|
1 #ifndef Py_ABSTRACTOBJECT_H
|
Chris@87
|
2 #define Py_ABSTRACTOBJECT_H
|
Chris@87
|
3 #ifdef __cplusplus
|
Chris@87
|
4 extern "C" {
|
Chris@87
|
5 #endif
|
Chris@87
|
6
|
Chris@87
|
7 #ifdef PY_SSIZE_T_CLEAN
|
Chris@87
|
8 #define PyObject_CallFunction _PyObject_CallFunction_SizeT
|
Chris@87
|
9 #define PyObject_CallMethod _PyObject_CallMethod_SizeT
|
Chris@87
|
10 #endif
|
Chris@87
|
11
|
Chris@87
|
12 /* Abstract Object Interface (many thanks to Jim Fulton) */
|
Chris@87
|
13
|
Chris@87
|
14 /*
|
Chris@87
|
15 PROPOSAL: A Generic Python Object Interface for Python C Modules
|
Chris@87
|
16
|
Chris@87
|
17 Problem
|
Chris@87
|
18
|
Chris@87
|
19 Python modules written in C that must access Python objects must do
|
Chris@87
|
20 so through routines whose interfaces are described by a set of
|
Chris@87
|
21 include files. Unfortunately, these routines vary according to the
|
Chris@87
|
22 object accessed. To use these routines, the C programmer must check
|
Chris@87
|
23 the type of the object being used and must call a routine based on
|
Chris@87
|
24 the object type. For example, to access an element of a sequence,
|
Chris@87
|
25 the programmer must determine whether the sequence is a list or a
|
Chris@87
|
26 tuple:
|
Chris@87
|
27
|
Chris@87
|
28 if(is_tupleobject(o))
|
Chris@87
|
29 e=gettupleitem(o,i)
|
Chris@87
|
30 else if(is_listitem(o))
|
Chris@87
|
31 e=getlistitem(o,i)
|
Chris@87
|
32
|
Chris@87
|
33 If the programmer wants to get an item from another type of object
|
Chris@87
|
34 that provides sequence behavior, there is no clear way to do it
|
Chris@87
|
35 correctly.
|
Chris@87
|
36
|
Chris@87
|
37 The persistent programmer may peruse object.h and find that the
|
Chris@87
|
38 _typeobject structure provides a means of invoking up to (currently
|
Chris@87
|
39 about) 41 special operators. So, for example, a routine can get an
|
Chris@87
|
40 item from any object that provides sequence behavior. However, to
|
Chris@87
|
41 use this mechanism, the programmer must make their code dependent on
|
Chris@87
|
42 the current Python implementation.
|
Chris@87
|
43
|
Chris@87
|
44 Also, certain semantics, especially memory management semantics, may
|
Chris@87
|
45 differ by the type of object being used. Unfortunately, these
|
Chris@87
|
46 semantics are not clearly described in the current include files.
|
Chris@87
|
47 An abstract interface providing more consistent semantics is needed.
|
Chris@87
|
48
|
Chris@87
|
49 Proposal
|
Chris@87
|
50
|
Chris@87
|
51 I propose the creation of a standard interface (with an associated
|
Chris@87
|
52 library of routines and/or macros) for generically obtaining the
|
Chris@87
|
53 services of Python objects. This proposal can be viewed as one
|
Chris@87
|
54 components of a Python C interface consisting of several components.
|
Chris@87
|
55
|
Chris@87
|
56 From the viewpoint of C access to Python services, we have (as
|
Chris@87
|
57 suggested by Guido in off-line discussions):
|
Chris@87
|
58
|
Chris@87
|
59 - "Very high level layer": two or three functions that let you exec or
|
Chris@87
|
60 eval arbitrary Python code given as a string in a module whose name is
|
Chris@87
|
61 given, passing C values in and getting C values out using
|
Chris@87
|
62 mkvalue/getargs style format strings. This does not require the user
|
Chris@87
|
63 to declare any variables of type "PyObject *". This should be enough
|
Chris@87
|
64 to write a simple application that gets Python code from the user,
|
Chris@87
|
65 execs it, and returns the output or errors. (Error handling must also
|
Chris@87
|
66 be part of this API.)
|
Chris@87
|
67
|
Chris@87
|
68 - "Abstract objects layer": which is the subject of this proposal.
|
Chris@87
|
69 It has many functions operating on objects, and lest you do many
|
Chris@87
|
70 things from C that you can also write in Python, without going
|
Chris@87
|
71 through the Python parser.
|
Chris@87
|
72
|
Chris@87
|
73 - "Concrete objects layer": This is the public type-dependent
|
Chris@87
|
74 interface provided by the standard built-in types, such as floats,
|
Chris@87
|
75 strings, and lists. This interface exists and is currently
|
Chris@87
|
76 documented by the collection of include files provided with the
|
Chris@87
|
77 Python distributions.
|
Chris@87
|
78
|
Chris@87
|
79 From the point of view of Python accessing services provided by C
|
Chris@87
|
80 modules:
|
Chris@87
|
81
|
Chris@87
|
82 - "Python module interface": this interface consist of the basic
|
Chris@87
|
83 routines used to define modules and their members. Most of the
|
Chris@87
|
84 current extensions-writing guide deals with this interface.
|
Chris@87
|
85
|
Chris@87
|
86 - "Built-in object interface": this is the interface that a new
|
Chris@87
|
87 built-in type must provide and the mechanisms and rules that a
|
Chris@87
|
88 developer of a new built-in type must use and follow.
|
Chris@87
|
89
|
Chris@87
|
90 This proposal is a "first-cut" that is intended to spur
|
Chris@87
|
91 discussion. See especially the lists of notes.
|
Chris@87
|
92
|
Chris@87
|
93 The Python C object interface will provide four protocols: object,
|
Chris@87
|
94 numeric, sequence, and mapping. Each protocol consists of a
|
Chris@87
|
95 collection of related operations. If an operation that is not
|
Chris@87
|
96 provided by a particular type is invoked, then a standard exception,
|
Chris@87
|
97 NotImplementedError is raised with a operation name as an argument.
|
Chris@87
|
98 In addition, for convenience this interface defines a set of
|
Chris@87
|
99 constructors for building objects of built-in types. This is needed
|
Chris@87
|
100 so new objects can be returned from C functions that otherwise treat
|
Chris@87
|
101 objects generically.
|
Chris@87
|
102
|
Chris@87
|
103 Memory Management
|
Chris@87
|
104
|
Chris@87
|
105 For all of the functions described in this proposal, if a function
|
Chris@87
|
106 retains a reference to a Python object passed as an argument, then the
|
Chris@87
|
107 function will increase the reference count of the object. It is
|
Chris@87
|
108 unnecessary for the caller to increase the reference count of an
|
Chris@87
|
109 argument in anticipation of the object's retention.
|
Chris@87
|
110
|
Chris@87
|
111 All Python objects returned from functions should be treated as new
|
Chris@87
|
112 objects. Functions that return objects assume that the caller will
|
Chris@87
|
113 retain a reference and the reference count of the object has already
|
Chris@87
|
114 been incremented to account for this fact. A caller that does not
|
Chris@87
|
115 retain a reference to an object that is returned from a function
|
Chris@87
|
116 must decrement the reference count of the object (using
|
Chris@87
|
117 DECREF(object)) to prevent memory leaks.
|
Chris@87
|
118
|
Chris@87
|
119 Note that the behavior mentioned here is different from the current
|
Chris@87
|
120 behavior for some objects (e.g. lists and tuples) when certain
|
Chris@87
|
121 type-specific routines are called directly (e.g. setlistitem). The
|
Chris@87
|
122 proposed abstraction layer will provide a consistent memory
|
Chris@87
|
123 management interface, correcting for inconsistent behavior for some
|
Chris@87
|
124 built-in types.
|
Chris@87
|
125
|
Chris@87
|
126 Protocols
|
Chris@87
|
127
|
Chris@87
|
128 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
|
Chris@87
|
129
|
Chris@87
|
130 /* Object Protocol: */
|
Chris@87
|
131
|
Chris@87
|
132 /* Implemented elsewhere:
|
Chris@87
|
133
|
Chris@87
|
134 int PyObject_Print(PyObject *o, FILE *fp, int flags);
|
Chris@87
|
135
|
Chris@87
|
136 Print an object, o, on file, fp. Returns -1 on
|
Chris@87
|
137 error. The flags argument is used to enable certain printing
|
Chris@87
|
138 options. The only option currently supported is Py_Print_RAW.
|
Chris@87
|
139
|
Chris@87
|
140 (What should be said about Py_Print_RAW?)
|
Chris@87
|
141
|
Chris@87
|
142 */
|
Chris@87
|
143
|
Chris@87
|
144 /* Implemented elsewhere:
|
Chris@87
|
145
|
Chris@87
|
146 int PyObject_HasAttrString(PyObject *o, char *attr_name);
|
Chris@87
|
147
|
Chris@87
|
148 Returns 1 if o has the attribute attr_name, and 0 otherwise.
|
Chris@87
|
149 This is equivalent to the Python expression:
|
Chris@87
|
150 hasattr(o,attr_name).
|
Chris@87
|
151
|
Chris@87
|
152 This function always succeeds.
|
Chris@87
|
153
|
Chris@87
|
154 */
|
Chris@87
|
155
|
Chris@87
|
156 /* Implemented elsewhere:
|
Chris@87
|
157
|
Chris@87
|
158 PyObject* PyObject_GetAttrString(PyObject *o, char *attr_name);
|
Chris@87
|
159
|
Chris@87
|
160 Retrieve an attributed named attr_name form object o.
|
Chris@87
|
161 Returns the attribute value on success, or NULL on failure.
|
Chris@87
|
162 This is the equivalent of the Python expression: o.attr_name.
|
Chris@87
|
163
|
Chris@87
|
164 */
|
Chris@87
|
165
|
Chris@87
|
166 /* Implemented elsewhere:
|
Chris@87
|
167
|
Chris@87
|
168 int PyObject_HasAttr(PyObject *o, PyObject *attr_name);
|
Chris@87
|
169
|
Chris@87
|
170 Returns 1 if o has the attribute attr_name, and 0 otherwise.
|
Chris@87
|
171 This is equivalent to the Python expression:
|
Chris@87
|
172 hasattr(o,attr_name).
|
Chris@87
|
173
|
Chris@87
|
174 This function always succeeds.
|
Chris@87
|
175
|
Chris@87
|
176 */
|
Chris@87
|
177
|
Chris@87
|
178 /* Implemented elsewhere:
|
Chris@87
|
179
|
Chris@87
|
180 PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name);
|
Chris@87
|
181
|
Chris@87
|
182 Retrieve an attributed named attr_name form object o.
|
Chris@87
|
183 Returns the attribute value on success, or NULL on failure.
|
Chris@87
|
184 This is the equivalent of the Python expression: o.attr_name.
|
Chris@87
|
185
|
Chris@87
|
186 */
|
Chris@87
|
187
|
Chris@87
|
188
|
Chris@87
|
189 /* Implemented elsewhere:
|
Chris@87
|
190
|
Chris@87
|
191 int PyObject_SetAttrString(PyObject *o, char *attr_name, PyObject *v);
|
Chris@87
|
192
|
Chris@87
|
193 Set the value of the attribute named attr_name, for object o,
|
Chris@87
|
194 to the value, v. Returns -1 on failure. This is
|
Chris@87
|
195 the equivalent of the Python statement: o.attr_name=v.
|
Chris@87
|
196
|
Chris@87
|
197 */
|
Chris@87
|
198
|
Chris@87
|
199 /* Implemented elsewhere:
|
Chris@87
|
200
|
Chris@87
|
201 int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v);
|
Chris@87
|
202
|
Chris@87
|
203 Set the value of the attribute named attr_name, for object o,
|
Chris@87
|
204 to the value, v. Returns -1 on failure. This is
|
Chris@87
|
205 the equivalent of the Python statement: o.attr_name=v.
|
Chris@87
|
206
|
Chris@87
|
207 */
|
Chris@87
|
208
|
Chris@87
|
209 /* implemented as a macro:
|
Chris@87
|
210
|
Chris@87
|
211 int PyObject_DelAttrString(PyObject *o, char *attr_name);
|
Chris@87
|
212
|
Chris@87
|
213 Delete attribute named attr_name, for object o. Returns
|
Chris@87
|
214 -1 on failure. This is the equivalent of the Python
|
Chris@87
|
215 statement: del o.attr_name.
|
Chris@87
|
216
|
Chris@87
|
217 */
|
Chris@87
|
218 #define PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A),NULL)
|
Chris@87
|
219
|
Chris@87
|
220 /* implemented as a macro:
|
Chris@87
|
221
|
Chris@87
|
222 int PyObject_DelAttr(PyObject *o, PyObject *attr_name);
|
Chris@87
|
223
|
Chris@87
|
224 Delete attribute named attr_name, for object o. Returns -1
|
Chris@87
|
225 on failure. This is the equivalent of the Python
|
Chris@87
|
226 statement: del o.attr_name.
|
Chris@87
|
227
|
Chris@87
|
228 */
|
Chris@87
|
229 #define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A),NULL)
|
Chris@87
|
230
|
Chris@87
|
231 PyAPI_FUNC(int) PyObject_Cmp(PyObject *o1, PyObject *o2, int *result);
|
Chris@87
|
232
|
Chris@87
|
233 /*
|
Chris@87
|
234 Compare the values of o1 and o2 using a routine provided by
|
Chris@87
|
235 o1, if one exists, otherwise with a routine provided by o2.
|
Chris@87
|
236 The result of the comparison is returned in result. Returns
|
Chris@87
|
237 -1 on failure. This is the equivalent of the Python
|
Chris@87
|
238 statement: result=cmp(o1,o2).
|
Chris@87
|
239
|
Chris@87
|
240 */
|
Chris@87
|
241
|
Chris@87
|
242 /* Implemented elsewhere:
|
Chris@87
|
243
|
Chris@87
|
244 int PyObject_Compare(PyObject *o1, PyObject *o2);
|
Chris@87
|
245
|
Chris@87
|
246 Compare the values of o1 and o2 using a routine provided by
|
Chris@87
|
247 o1, if one exists, otherwise with a routine provided by o2.
|
Chris@87
|
248 Returns the result of the comparison on success. On error,
|
Chris@87
|
249 the value returned is undefined. This is equivalent to the
|
Chris@87
|
250 Python expression: cmp(o1,o2).
|
Chris@87
|
251
|
Chris@87
|
252 */
|
Chris@87
|
253
|
Chris@87
|
254 /* Implemented elsewhere:
|
Chris@87
|
255
|
Chris@87
|
256 PyObject *PyObject_Repr(PyObject *o);
|
Chris@87
|
257
|
Chris@87
|
258 Compute the string representation of object, o. Returns the
|
Chris@87
|
259 string representation on success, NULL on failure. This is
|
Chris@87
|
260 the equivalent of the Python expression: repr(o).
|
Chris@87
|
261
|
Chris@87
|
262 Called by the repr() built-in function and by reverse quotes.
|
Chris@87
|
263
|
Chris@87
|
264 */
|
Chris@87
|
265
|
Chris@87
|
266 /* Implemented elsewhere:
|
Chris@87
|
267
|
Chris@87
|
268 PyObject *PyObject_Str(PyObject *o);
|
Chris@87
|
269
|
Chris@87
|
270 Compute the string representation of object, o. Returns the
|
Chris@87
|
271 string representation on success, NULL on failure. This is
|
Chris@87
|
272 the equivalent of the Python expression: str(o).)
|
Chris@87
|
273
|
Chris@87
|
274 Called by the str() built-in function and by the print
|
Chris@87
|
275 statement.
|
Chris@87
|
276
|
Chris@87
|
277 */
|
Chris@87
|
278
|
Chris@87
|
279 /* Implemented elsewhere:
|
Chris@87
|
280
|
Chris@87
|
281 PyObject *PyObject_Unicode(PyObject *o);
|
Chris@87
|
282
|
Chris@87
|
283 Compute the unicode representation of object, o. Returns the
|
Chris@87
|
284 unicode representation on success, NULL on failure. This is
|
Chris@87
|
285 the equivalent of the Python expression: unistr(o).)
|
Chris@87
|
286
|
Chris@87
|
287 Called by the unistr() built-in function.
|
Chris@87
|
288
|
Chris@87
|
289 */
|
Chris@87
|
290
|
Chris@87
|
291 /* Declared elsewhere
|
Chris@87
|
292
|
Chris@87
|
293 PyAPI_FUNC(int) PyCallable_Check(PyObject *o);
|
Chris@87
|
294
|
Chris@87
|
295 Determine if the object, o, is callable. Return 1 if the
|
Chris@87
|
296 object is callable and 0 otherwise.
|
Chris@87
|
297
|
Chris@87
|
298 This function always succeeds.
|
Chris@87
|
299
|
Chris@87
|
300 */
|
Chris@87
|
301
|
Chris@87
|
302
|
Chris@87
|
303
|
Chris@87
|
304 PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable_object,
|
Chris@87
|
305 PyObject *args, PyObject *kw);
|
Chris@87
|
306
|
Chris@87
|
307 /*
|
Chris@87
|
308 Call a callable Python object, callable_object, with
|
Chris@87
|
309 arguments and keywords arguments. The 'args' argument can not be
|
Chris@87
|
310 NULL, but the 'kw' argument can be NULL.
|
Chris@87
|
311
|
Chris@87
|
312 */
|
Chris@87
|
313
|
Chris@87
|
314 PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable_object,
|
Chris@87
|
315 PyObject *args);
|
Chris@87
|
316
|
Chris@87
|
317 /*
|
Chris@87
|
318 Call a callable Python object, callable_object, with
|
Chris@87
|
319 arguments given by the tuple, args. If no arguments are
|
Chris@87
|
320 needed, then args may be NULL. Returns the result of the
|
Chris@87
|
321 call on success, or NULL on failure. This is the equivalent
|
Chris@87
|
322 of the Python expression: apply(o,args).
|
Chris@87
|
323
|
Chris@87
|
324 */
|
Chris@87
|
325
|
Chris@87
|
326 PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable_object,
|
Chris@87
|
327 char *format, ...);
|
Chris@87
|
328
|
Chris@87
|
329 /*
|
Chris@87
|
330 Call a callable Python object, callable_object, with a
|
Chris@87
|
331 variable number of C arguments. The C arguments are described
|
Chris@87
|
332 using a mkvalue-style format string. The format may be NULL,
|
Chris@87
|
333 indicating that no arguments are provided. Returns the
|
Chris@87
|
334 result of the call on success, or NULL on failure. This is
|
Chris@87
|
335 the equivalent of the Python expression: apply(o,args).
|
Chris@87
|
336
|
Chris@87
|
337 */
|
Chris@87
|
338
|
Chris@87
|
339
|
Chris@87
|
340 PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *o, char *m,
|
Chris@87
|
341 char *format, ...);
|
Chris@87
|
342
|
Chris@87
|
343 /*
|
Chris@87
|
344 Call the method named m of object o with a variable number of
|
Chris@87
|
345 C arguments. The C arguments are described by a mkvalue
|
Chris@87
|
346 format string. The format may be NULL, indicating that no
|
Chris@87
|
347 arguments are provided. Returns the result of the call on
|
Chris@87
|
348 success, or NULL on failure. This is the equivalent of the
|
Chris@87
|
349 Python expression: o.method(args).
|
Chris@87
|
350 */
|
Chris@87
|
351
|
Chris@87
|
352 PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable,
|
Chris@87
|
353 char *format, ...);
|
Chris@87
|
354 PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *o,
|
Chris@87
|
355 char *name,
|
Chris@87
|
356 char *format, ...);
|
Chris@87
|
357
|
Chris@87
|
358 PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable,
|
Chris@87
|
359 ...);
|
Chris@87
|
360
|
Chris@87
|
361 /*
|
Chris@87
|
362 Call a callable Python object, callable_object, with a
|
Chris@87
|
363 variable number of C arguments. The C arguments are provided
|
Chris@87
|
364 as PyObject * values, terminated by a NULL. Returns the
|
Chris@87
|
365 result of the call on success, or NULL on failure. This is
|
Chris@87
|
366 the equivalent of the Python expression: apply(o,args).
|
Chris@87
|
367 */
|
Chris@87
|
368
|
Chris@87
|
369
|
Chris@87
|
370 PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(PyObject *o,
|
Chris@87
|
371 PyObject *m, ...);
|
Chris@87
|
372
|
Chris@87
|
373 /*
|
Chris@87
|
374 Call the method named m of object o with a variable number of
|
Chris@87
|
375 C arguments. The C arguments are provided as PyObject *
|
Chris@87
|
376 values, terminated by NULL. Returns the result of the call
|
Chris@87
|
377 on success, or NULL on failure. This is the equivalent of
|
Chris@87
|
378 the Python expression: o.method(args).
|
Chris@87
|
379 */
|
Chris@87
|
380
|
Chris@87
|
381
|
Chris@87
|
382 /* Implemented elsewhere:
|
Chris@87
|
383
|
Chris@87
|
384 long PyObject_Hash(PyObject *o);
|
Chris@87
|
385
|
Chris@87
|
386 Compute and return the hash, hash_value, of an object, o. On
|
Chris@87
|
387 failure, return -1. This is the equivalent of the Python
|
Chris@87
|
388 expression: hash(o).
|
Chris@87
|
389
|
Chris@87
|
390 */
|
Chris@87
|
391
|
Chris@87
|
392
|
Chris@87
|
393 /* Implemented elsewhere:
|
Chris@87
|
394
|
Chris@87
|
395 int PyObject_IsTrue(PyObject *o);
|
Chris@87
|
396
|
Chris@87
|
397 Returns 1 if the object, o, is considered to be true, 0 if o is
|
Chris@87
|
398 considered to be false and -1 on failure. This is equivalent to the
|
Chris@87
|
399 Python expression: not not o
|
Chris@87
|
400
|
Chris@87
|
401 */
|
Chris@87
|
402
|
Chris@87
|
403 /* Implemented elsewhere:
|
Chris@87
|
404
|
Chris@87
|
405 int PyObject_Not(PyObject *o);
|
Chris@87
|
406
|
Chris@87
|
407 Returns 0 if the object, o, is considered to be true, 1 if o is
|
Chris@87
|
408 considered to be false and -1 on failure. This is equivalent to the
|
Chris@87
|
409 Python expression: not o
|
Chris@87
|
410
|
Chris@87
|
411 */
|
Chris@87
|
412
|
Chris@87
|
413 PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o);
|
Chris@87
|
414
|
Chris@87
|
415 /*
|
Chris@87
|
416 On success, returns a type object corresponding to the object
|
Chris@87
|
417 type of object o. On failure, returns NULL. This is
|
Chris@87
|
418 equivalent to the Python expression: type(o).
|
Chris@87
|
419 */
|
Chris@87
|
420
|
Chris@87
|
421 PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o);
|
Chris@87
|
422
|
Chris@87
|
423 /*
|
Chris@87
|
424 Return the size of object o. If the object, o, provides
|
Chris@87
|
425 both sequence and mapping protocols, the sequence size is
|
Chris@87
|
426 returned. On error, -1 is returned. This is the equivalent
|
Chris@87
|
427 to the Python expression: len(o).
|
Chris@87
|
428
|
Chris@87
|
429 */
|
Chris@87
|
430
|
Chris@87
|
431 /* For DLL compatibility */
|
Chris@87
|
432 #undef PyObject_Length
|
Chris@87
|
433 PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o);
|
Chris@87
|
434 #define PyObject_Length PyObject_Size
|
Chris@87
|
435
|
Chris@87
|
436 PyAPI_FUNC(Py_ssize_t) _PyObject_LengthHint(PyObject *o, Py_ssize_t);
|
Chris@87
|
437
|
Chris@87
|
438 /*
|
Chris@87
|
439 Guess the size of object o using len(o) or o.__length_hint__().
|
Chris@87
|
440 If neither of those return a non-negative value, then return the
|
Chris@87
|
441 default value. If one of the calls fails, this function returns -1.
|
Chris@87
|
442 */
|
Chris@87
|
443
|
Chris@87
|
444 PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key);
|
Chris@87
|
445
|
Chris@87
|
446 /*
|
Chris@87
|
447 Return element of o corresponding to the object, key, or NULL
|
Chris@87
|
448 on failure. This is the equivalent of the Python expression:
|
Chris@87
|
449 o[key].
|
Chris@87
|
450
|
Chris@87
|
451 */
|
Chris@87
|
452
|
Chris@87
|
453 PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v);
|
Chris@87
|
454
|
Chris@87
|
455 /*
|
Chris@87
|
456 Map the object, key, to the value, v. Returns
|
Chris@87
|
457 -1 on failure. This is the equivalent of the Python
|
Chris@87
|
458 statement: o[key]=v.
|
Chris@87
|
459 */
|
Chris@87
|
460
|
Chris@87
|
461 PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, char *key);
|
Chris@87
|
462
|
Chris@87
|
463 /*
|
Chris@87
|
464 Remove the mapping for object, key, from the object *o.
|
Chris@87
|
465 Returns -1 on failure. This is equivalent to
|
Chris@87
|
466 the Python statement: del o[key].
|
Chris@87
|
467 */
|
Chris@87
|
468
|
Chris@87
|
469 PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key);
|
Chris@87
|
470
|
Chris@87
|
471 /*
|
Chris@87
|
472 Delete the mapping for key from *o. Returns -1 on failure.
|
Chris@87
|
473 This is the equivalent of the Python statement: del o[key].
|
Chris@87
|
474 */
|
Chris@87
|
475
|
Chris@87
|
476 PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj,
|
Chris@87
|
477 const char **buffer,
|
Chris@87
|
478 Py_ssize_t *buffer_len);
|
Chris@87
|
479
|
Chris@87
|
480 /*
|
Chris@87
|
481 Takes an arbitrary object which must support the (character,
|
Chris@87
|
482 single segment) buffer interface and returns a pointer to a
|
Chris@87
|
483 read-only memory location useable as character based input
|
Chris@87
|
484 for subsequent processing.
|
Chris@87
|
485
|
Chris@87
|
486 0 is returned on success. buffer and buffer_len are only
|
Chris@87
|
487 set in case no error occurs. Otherwise, -1 is returned and
|
Chris@87
|
488 an exception set.
|
Chris@87
|
489
|
Chris@87
|
490 */
|
Chris@87
|
491
|
Chris@87
|
492 PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj);
|
Chris@87
|
493
|
Chris@87
|
494 /*
|
Chris@87
|
495 Checks whether an arbitrary object supports the (character,
|
Chris@87
|
496 single segment) buffer interface. Returns 1 on success, 0
|
Chris@87
|
497 on failure.
|
Chris@87
|
498
|
Chris@87
|
499 */
|
Chris@87
|
500
|
Chris@87
|
501 PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj,
|
Chris@87
|
502 const void **buffer,
|
Chris@87
|
503 Py_ssize_t *buffer_len);
|
Chris@87
|
504
|
Chris@87
|
505 /*
|
Chris@87
|
506 Same as PyObject_AsCharBuffer() except that this API expects
|
Chris@87
|
507 (readable, single segment) buffer interface and returns a
|
Chris@87
|
508 pointer to a read-only memory location which can contain
|
Chris@87
|
509 arbitrary data.
|
Chris@87
|
510
|
Chris@87
|
511 0 is returned on success. buffer and buffer_len are only
|
Chris@87
|
512 set in case no error occurs. Otherwise, -1 is returned and
|
Chris@87
|
513 an exception set.
|
Chris@87
|
514
|
Chris@87
|
515 */
|
Chris@87
|
516
|
Chris@87
|
517 PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj,
|
Chris@87
|
518 void **buffer,
|
Chris@87
|
519 Py_ssize_t *buffer_len);
|
Chris@87
|
520
|
Chris@87
|
521 /*
|
Chris@87
|
522 Takes an arbitrary object which must support the (writeable,
|
Chris@87
|
523 single segment) buffer interface and returns a pointer to a
|
Chris@87
|
524 writeable memory location in buffer of size buffer_len.
|
Chris@87
|
525
|
Chris@87
|
526 0 is returned on success. buffer and buffer_len are only
|
Chris@87
|
527 set in case no error occurs. Otherwise, -1 is returned and
|
Chris@87
|
528 an exception set.
|
Chris@87
|
529
|
Chris@87
|
530 */
|
Chris@87
|
531
|
Chris@87
|
532 /* new buffer API */
|
Chris@87
|
533
|
Chris@87
|
534 #define PyObject_CheckBuffer(obj) \
|
Chris@87
|
535 (((obj)->ob_type->tp_as_buffer != NULL) && \
|
Chris@87
|
536 (PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_NEWBUFFER)) && \
|
Chris@87
|
537 ((obj)->ob_type->tp_as_buffer->bf_getbuffer != NULL))
|
Chris@87
|
538
|
Chris@87
|
539 /* Return 1 if the getbuffer function is available, otherwise
|
Chris@87
|
540 return 0 */
|
Chris@87
|
541
|
Chris@87
|
542 PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, Py_buffer *view,
|
Chris@87
|
543 int flags);
|
Chris@87
|
544
|
Chris@87
|
545 /* This is a C-API version of the getbuffer function call. It checks
|
Chris@87
|
546 to make sure object has the required function pointer and issues the
|
Chris@87
|
547 call. Returns -1 and raises an error on failure and returns 0 on
|
Chris@87
|
548 success
|
Chris@87
|
549 */
|
Chris@87
|
550
|
Chris@87
|
551
|
Chris@87
|
552 PyAPI_FUNC(void *) PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices);
|
Chris@87
|
553
|
Chris@87
|
554 /* Get the memory area pointed to by the indices for the buffer given.
|
Chris@87
|
555 Note that view->ndim is the assumed size of indices
|
Chris@87
|
556 */
|
Chris@87
|
557
|
Chris@87
|
558 PyAPI_FUNC(int) PyBuffer_SizeFromFormat(const char *);
|
Chris@87
|
559
|
Chris@87
|
560 /* Return the implied itemsize of the data-format area from a
|
Chris@87
|
561 struct-style description */
|
Chris@87
|
562
|
Chris@87
|
563
|
Chris@87
|
564
|
Chris@87
|
565 PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, Py_buffer *view,
|
Chris@87
|
566 Py_ssize_t len, char fort);
|
Chris@87
|
567
|
Chris@87
|
568 PyAPI_FUNC(int) PyBuffer_FromContiguous(Py_buffer *view, void *buf,
|
Chris@87
|
569 Py_ssize_t len, char fort);
|
Chris@87
|
570
|
Chris@87
|
571
|
Chris@87
|
572 /* Copy len bytes of data from the contiguous chunk of memory
|
Chris@87
|
573 pointed to by buf into the buffer exported by obj. Return
|
Chris@87
|
574 0 on success and return -1 and raise a PyBuffer_Error on
|
Chris@87
|
575 error (i.e. the object does not have a buffer interface or
|
Chris@87
|
576 it is not working).
|
Chris@87
|
577
|
Chris@87
|
578 If fort is 'F' and the object is multi-dimensional,
|
Chris@87
|
579 then the data will be copied into the array in
|
Chris@87
|
580 Fortran-style (first dimension varies the fastest). If
|
Chris@87
|
581 fort is 'C', then the data will be copied into the array
|
Chris@87
|
582 in C-style (last dimension varies the fastest). If fort
|
Chris@87
|
583 is 'A', then it does not matter and the copy will be made
|
Chris@87
|
584 in whatever way is more efficient.
|
Chris@87
|
585
|
Chris@87
|
586 */
|
Chris@87
|
587
|
Chris@87
|
588 PyAPI_FUNC(int) PyObject_CopyData(PyObject *dest, PyObject *src);
|
Chris@87
|
589
|
Chris@87
|
590 /* Copy the data from the src buffer to the buffer of destination
|
Chris@87
|
591 */
|
Chris@87
|
592
|
Chris@87
|
593 PyAPI_FUNC(int) PyBuffer_IsContiguous(Py_buffer *view, char fort);
|
Chris@87
|
594
|
Chris@87
|
595
|
Chris@87
|
596 PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims,
|
Chris@87
|
597 Py_ssize_t *shape,
|
Chris@87
|
598 Py_ssize_t *strides,
|
Chris@87
|
599 int itemsize,
|
Chris@87
|
600 char fort);
|
Chris@87
|
601
|
Chris@87
|
602 /* Fill the strides array with byte-strides of a contiguous
|
Chris@87
|
603 (Fortran-style if fort is 'F' or C-style otherwise)
|
Chris@87
|
604 array of the given shape with the given number of bytes
|
Chris@87
|
605 per element.
|
Chris@87
|
606 */
|
Chris@87
|
607
|
Chris@87
|
608 PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf,
|
Chris@87
|
609 Py_ssize_t len, int readonly,
|
Chris@87
|
610 int flags);
|
Chris@87
|
611
|
Chris@87
|
612 /* Fills in a buffer-info structure correctly for an exporter
|
Chris@87
|
613 that can only share a contiguous chunk of memory of
|
Chris@87
|
614 "unsigned bytes" of the given length. Returns 0 on success
|
Chris@87
|
615 and -1 (with raising an error) on error.
|
Chris@87
|
616 */
|
Chris@87
|
617
|
Chris@87
|
618 PyAPI_FUNC(void) PyBuffer_Release(Py_buffer *view);
|
Chris@87
|
619
|
Chris@87
|
620 /* Releases a Py_buffer obtained from getbuffer ParseTuple's s*.
|
Chris@87
|
621 */
|
Chris@87
|
622
|
Chris@87
|
623 PyAPI_FUNC(PyObject *) PyObject_Format(PyObject* obj,
|
Chris@87
|
624 PyObject *format_spec);
|
Chris@87
|
625 /*
|
Chris@87
|
626 Takes an arbitrary object and returns the result of
|
Chris@87
|
627 calling obj.__format__(format_spec).
|
Chris@87
|
628 */
|
Chris@87
|
629
|
Chris@87
|
630 /* Iterators */
|
Chris@87
|
631
|
Chris@87
|
632 PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);
|
Chris@87
|
633 /* Takes an object and returns an iterator for it.
|
Chris@87
|
634 This is typically a new iterator but if the argument
|
Chris@87
|
635 is an iterator, this returns itself. */
|
Chris@87
|
636
|
Chris@87
|
637 #define PyIter_Check(obj) \
|
Chris@87
|
638 (PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_ITER) && \
|
Chris@87
|
639 (obj)->ob_type->tp_iternext != NULL && \
|
Chris@87
|
640 (obj)->ob_type->tp_iternext != &_PyObject_NextNotImplemented)
|
Chris@87
|
641
|
Chris@87
|
642 PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *);
|
Chris@87
|
643 /* Takes an iterator object and calls its tp_iternext slot,
|
Chris@87
|
644 returning the next value. If the iterator is exhausted,
|
Chris@87
|
645 this returns NULL without setting an exception.
|
Chris@87
|
646 NULL with an exception means an error occurred. */
|
Chris@87
|
647
|
Chris@87
|
648 /* Number Protocol:*/
|
Chris@87
|
649
|
Chris@87
|
650 PyAPI_FUNC(int) PyNumber_Check(PyObject *o);
|
Chris@87
|
651
|
Chris@87
|
652 /*
|
Chris@87
|
653 Returns 1 if the object, o, provides numeric protocols, and
|
Chris@87
|
654 false otherwise.
|
Chris@87
|
655
|
Chris@87
|
656 This function always succeeds.
|
Chris@87
|
657
|
Chris@87
|
658 */
|
Chris@87
|
659
|
Chris@87
|
660 PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2);
|
Chris@87
|
661
|
Chris@87
|
662 /*
|
Chris@87
|
663 Returns the result of adding o1 and o2, or null on failure.
|
Chris@87
|
664 This is the equivalent of the Python expression: o1+o2.
|
Chris@87
|
665
|
Chris@87
|
666
|
Chris@87
|
667 */
|
Chris@87
|
668
|
Chris@87
|
669 PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2);
|
Chris@87
|
670
|
Chris@87
|
671 /*
|
Chris@87
|
672 Returns the result of subtracting o2 from o1, or null on
|
Chris@87
|
673 failure. This is the equivalent of the Python expression:
|
Chris@87
|
674 o1-o2.
|
Chris@87
|
675
|
Chris@87
|
676 */
|
Chris@87
|
677
|
Chris@87
|
678 PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2);
|
Chris@87
|
679
|
Chris@87
|
680 /*
|
Chris@87
|
681 Returns the result of multiplying o1 and o2, or null on
|
Chris@87
|
682 failure. This is the equivalent of the Python expression:
|
Chris@87
|
683 o1*o2.
|
Chris@87
|
684
|
Chris@87
|
685
|
Chris@87
|
686 */
|
Chris@87
|
687
|
Chris@87
|
688 PyAPI_FUNC(PyObject *) PyNumber_Divide(PyObject *o1, PyObject *o2);
|
Chris@87
|
689
|
Chris@87
|
690 /*
|
Chris@87
|
691 Returns the result of dividing o1 by o2, or null on failure.
|
Chris@87
|
692 This is the equivalent of the Python expression: o1/o2.
|
Chris@87
|
693
|
Chris@87
|
694
|
Chris@87
|
695 */
|
Chris@87
|
696
|
Chris@87
|
697 PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2);
|
Chris@87
|
698
|
Chris@87
|
699 /*
|
Chris@87
|
700 Returns the result of dividing o1 by o2 giving an integral result,
|
Chris@87
|
701 or null on failure.
|
Chris@87
|
702 This is the equivalent of the Python expression: o1//o2.
|
Chris@87
|
703
|
Chris@87
|
704
|
Chris@87
|
705 */
|
Chris@87
|
706
|
Chris@87
|
707 PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2);
|
Chris@87
|
708
|
Chris@87
|
709 /*
|
Chris@87
|
710 Returns the result of dividing o1 by o2 giving a float result,
|
Chris@87
|
711 or null on failure.
|
Chris@87
|
712 This is the equivalent of the Python expression: o1/o2.
|
Chris@87
|
713
|
Chris@87
|
714
|
Chris@87
|
715 */
|
Chris@87
|
716
|
Chris@87
|
717 PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2);
|
Chris@87
|
718
|
Chris@87
|
719 /*
|
Chris@87
|
720 Returns the remainder of dividing o1 by o2, or null on
|
Chris@87
|
721 failure. This is the equivalent of the Python expression:
|
Chris@87
|
722 o1%o2.
|
Chris@87
|
723
|
Chris@87
|
724
|
Chris@87
|
725 */
|
Chris@87
|
726
|
Chris@87
|
727 PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2);
|
Chris@87
|
728
|
Chris@87
|
729 /*
|
Chris@87
|
730 See the built-in function divmod. Returns NULL on failure.
|
Chris@87
|
731 This is the equivalent of the Python expression:
|
Chris@87
|
732 divmod(o1,o2).
|
Chris@87
|
733
|
Chris@87
|
734
|
Chris@87
|
735 */
|
Chris@87
|
736
|
Chris@87
|
737 PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2,
|
Chris@87
|
738 PyObject *o3);
|
Chris@87
|
739
|
Chris@87
|
740 /*
|
Chris@87
|
741 See the built-in function pow. Returns NULL on failure.
|
Chris@87
|
742 This is the equivalent of the Python expression:
|
Chris@87
|
743 pow(o1,o2,o3), where o3 is optional.
|
Chris@87
|
744
|
Chris@87
|
745 */
|
Chris@87
|
746
|
Chris@87
|
747 PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o);
|
Chris@87
|
748
|
Chris@87
|
749 /*
|
Chris@87
|
750 Returns the negation of o on success, or null on failure.
|
Chris@87
|
751 This is the equivalent of the Python expression: -o.
|
Chris@87
|
752
|
Chris@87
|
753 */
|
Chris@87
|
754
|
Chris@87
|
755 PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o);
|
Chris@87
|
756
|
Chris@87
|
757 /*
|
Chris@87
|
758 Returns the (what?) of o on success, or NULL on failure.
|
Chris@87
|
759 This is the equivalent of the Python expression: +o.
|
Chris@87
|
760
|
Chris@87
|
761 */
|
Chris@87
|
762
|
Chris@87
|
763 PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o);
|
Chris@87
|
764
|
Chris@87
|
765 /*
|
Chris@87
|
766 Returns the absolute value of o, or null on failure. This is
|
Chris@87
|
767 the equivalent of the Python expression: abs(o).
|
Chris@87
|
768
|
Chris@87
|
769 */
|
Chris@87
|
770
|
Chris@87
|
771 PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o);
|
Chris@87
|
772
|
Chris@87
|
773 /*
|
Chris@87
|
774 Returns the bitwise negation of o on success, or NULL on
|
Chris@87
|
775 failure. This is the equivalent of the Python expression:
|
Chris@87
|
776 ~o.
|
Chris@87
|
777
|
Chris@87
|
778
|
Chris@87
|
779 */
|
Chris@87
|
780
|
Chris@87
|
781 PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2);
|
Chris@87
|
782
|
Chris@87
|
783 /*
|
Chris@87
|
784 Returns the result of left shifting o1 by o2 on success, or
|
Chris@87
|
785 NULL on failure. This is the equivalent of the Python
|
Chris@87
|
786 expression: o1 << o2.
|
Chris@87
|
787
|
Chris@87
|
788
|
Chris@87
|
789 */
|
Chris@87
|
790
|
Chris@87
|
791 PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2);
|
Chris@87
|
792
|
Chris@87
|
793 /*
|
Chris@87
|
794 Returns the result of right shifting o1 by o2 on success, or
|
Chris@87
|
795 NULL on failure. This is the equivalent of the Python
|
Chris@87
|
796 expression: o1 >> o2.
|
Chris@87
|
797
|
Chris@87
|
798 */
|
Chris@87
|
799
|
Chris@87
|
800 PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2);
|
Chris@87
|
801
|
Chris@87
|
802 /*
|
Chris@87
|
803 Returns the result of bitwise and of o1 and o2 on success, or
|
Chris@87
|
804 NULL on failure. This is the equivalent of the Python
|
Chris@87
|
805 expression: o1&o2.
|
Chris@87
|
806
|
Chris@87
|
807
|
Chris@87
|
808 */
|
Chris@87
|
809
|
Chris@87
|
810 PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2);
|
Chris@87
|
811
|
Chris@87
|
812 /*
|
Chris@87
|
813 Returns the bitwise exclusive or of o1 by o2 on success, or
|
Chris@87
|
814 NULL on failure. This is the equivalent of the Python
|
Chris@87
|
815 expression: o1^o2.
|
Chris@87
|
816
|
Chris@87
|
817
|
Chris@87
|
818 */
|
Chris@87
|
819
|
Chris@87
|
820 PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2);
|
Chris@87
|
821
|
Chris@87
|
822 /*
|
Chris@87
|
823 Returns the result of bitwise or on o1 and o2 on success, or
|
Chris@87
|
824 NULL on failure. This is the equivalent of the Python
|
Chris@87
|
825 expression: o1|o2.
|
Chris@87
|
826
|
Chris@87
|
827 */
|
Chris@87
|
828
|
Chris@87
|
829 /* Implemented elsewhere:
|
Chris@87
|
830
|
Chris@87
|
831 int PyNumber_Coerce(PyObject **p1, PyObject **p2);
|
Chris@87
|
832
|
Chris@87
|
833 This function takes the addresses of two variables of type
|
Chris@87
|
834 PyObject*.
|
Chris@87
|
835
|
Chris@87
|
836 If the objects pointed to by *p1 and *p2 have the same type,
|
Chris@87
|
837 increment their reference count and return 0 (success).
|
Chris@87
|
838 If the objects can be converted to a common numeric type,
|
Chris@87
|
839 replace *p1 and *p2 by their converted value (with 'new'
|
Chris@87
|
840 reference counts), and return 0.
|
Chris@87
|
841 If no conversion is possible, or if some other error occurs,
|
Chris@87
|
842 return -1 (failure) and don't increment the reference counts.
|
Chris@87
|
843 The call PyNumber_Coerce(&o1, &o2) is equivalent to the Python
|
Chris@87
|
844 statement o1, o2 = coerce(o1, o2).
|
Chris@87
|
845
|
Chris@87
|
846 */
|
Chris@87
|
847
|
Chris@87
|
848 #define PyIndex_Check(obj) \
|
Chris@87
|
849 ((obj)->ob_type->tp_as_number != NULL && \
|
Chris@87
|
850 PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_INDEX) && \
|
Chris@87
|
851 (obj)->ob_type->tp_as_number->nb_index != NULL)
|
Chris@87
|
852
|
Chris@87
|
853 PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o);
|
Chris@87
|
854
|
Chris@87
|
855 /*
|
Chris@87
|
856 Returns the object converted to a Python long or int
|
Chris@87
|
857 or NULL with an error raised on failure.
|
Chris@87
|
858 */
|
Chris@87
|
859
|
Chris@87
|
860 PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc);
|
Chris@87
|
861
|
Chris@87
|
862 /*
|
Chris@87
|
863 Returns the Integral instance converted to an int. The
|
Chris@87
|
864 instance is expected to be int or long or have an __int__
|
Chris@87
|
865 method. Steals integral's reference. error_format will be
|
Chris@87
|
866 used to create the TypeError if integral isn't actually an
|
Chris@87
|
867 Integral instance. error_format should be a format string
|
Chris@87
|
868 that can accept a char* naming integral's type.
|
Chris@87
|
869 */
|
Chris@87
|
870
|
Chris@87
|
871 PyAPI_FUNC(PyObject *) _PyNumber_ConvertIntegralToInt(
|
Chris@87
|
872 PyObject *integral,
|
Chris@87
|
873 const char* error_format);
|
Chris@87
|
874
|
Chris@87
|
875 /*
|
Chris@87
|
876 Returns the object converted to Py_ssize_t by going through
|
Chris@87
|
877 PyNumber_Index first. If an overflow error occurs while
|
Chris@87
|
878 converting the int-or-long to Py_ssize_t, then the second argument
|
Chris@87
|
879 is the error-type to return. If it is NULL, then the overflow error
|
Chris@87
|
880 is cleared and the value is clipped.
|
Chris@87
|
881 */
|
Chris@87
|
882
|
Chris@87
|
883 PyAPI_FUNC(PyObject *) PyNumber_Int(PyObject *o);
|
Chris@87
|
884
|
Chris@87
|
885 /*
|
Chris@87
|
886 Returns the o converted to an integer object on success, or
|
Chris@87
|
887 NULL on failure. This is the equivalent of the Python
|
Chris@87
|
888 expression: int(o).
|
Chris@87
|
889
|
Chris@87
|
890 */
|
Chris@87
|
891
|
Chris@87
|
892 PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o);
|
Chris@87
|
893
|
Chris@87
|
894 /*
|
Chris@87
|
895 Returns the o converted to a long integer object on success,
|
Chris@87
|
896 or NULL on failure. This is the equivalent of the Python
|
Chris@87
|
897 expression: long(o).
|
Chris@87
|
898
|
Chris@87
|
899 */
|
Chris@87
|
900
|
Chris@87
|
901 PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o);
|
Chris@87
|
902
|
Chris@87
|
903 /*
|
Chris@87
|
904 Returns the o converted to a float object on success, or NULL
|
Chris@87
|
905 on failure. This is the equivalent of the Python expression:
|
Chris@87
|
906 float(o).
|
Chris@87
|
907 */
|
Chris@87
|
908
|
Chris@87
|
909 /* In-place variants of (some of) the above number protocol functions */
|
Chris@87
|
910
|
Chris@87
|
911 PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2);
|
Chris@87
|
912
|
Chris@87
|
913 /*
|
Chris@87
|
914 Returns the result of adding o2 to o1, possibly in-place, or null
|
Chris@87
|
915 on failure. This is the equivalent of the Python expression:
|
Chris@87
|
916 o1 += o2.
|
Chris@87
|
917
|
Chris@87
|
918 */
|
Chris@87
|
919
|
Chris@87
|
920 PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2);
|
Chris@87
|
921
|
Chris@87
|
922 /*
|
Chris@87
|
923 Returns the result of subtracting o2 from o1, possibly in-place or
|
Chris@87
|
924 null on failure. This is the equivalent of the Python expression:
|
Chris@87
|
925 o1 -= o2.
|
Chris@87
|
926
|
Chris@87
|
927 */
|
Chris@87
|
928
|
Chris@87
|
929 PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2);
|
Chris@87
|
930
|
Chris@87
|
931 /*
|
Chris@87
|
932 Returns the result of multiplying o1 by o2, possibly in-place, or
|
Chris@87
|
933 null on failure. This is the equivalent of the Python expression:
|
Chris@87
|
934 o1 *= o2.
|
Chris@87
|
935
|
Chris@87
|
936 */
|
Chris@87
|
937
|
Chris@87
|
938 PyAPI_FUNC(PyObject *) PyNumber_InPlaceDivide(PyObject *o1, PyObject *o2);
|
Chris@87
|
939
|
Chris@87
|
940 /*
|
Chris@87
|
941 Returns the result of dividing o1 by o2, possibly in-place, or null
|
Chris@87
|
942 on failure. This is the equivalent of the Python expression:
|
Chris@87
|
943 o1 /= o2.
|
Chris@87
|
944
|
Chris@87
|
945 */
|
Chris@87
|
946
|
Chris@87
|
947 PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1,
|
Chris@87
|
948 PyObject *o2);
|
Chris@87
|
949
|
Chris@87
|
950 /*
|
Chris@87
|
951 Returns the result of dividing o1 by o2 giving an integral result,
|
Chris@87
|
952 possibly in-place, or null on failure.
|
Chris@87
|
953 This is the equivalent of the Python expression:
|
Chris@87
|
954 o1 /= o2.
|
Chris@87
|
955
|
Chris@87
|
956 */
|
Chris@87
|
957
|
Chris@87
|
958 PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1,
|
Chris@87
|
959 PyObject *o2);
|
Chris@87
|
960
|
Chris@87
|
961 /*
|
Chris@87
|
962 Returns the result of dividing o1 by o2 giving a float result,
|
Chris@87
|
963 possibly in-place, or null on failure.
|
Chris@87
|
964 This is the equivalent of the Python expression:
|
Chris@87
|
965 o1 /= o2.
|
Chris@87
|
966
|
Chris@87
|
967 */
|
Chris@87
|
968
|
Chris@87
|
969 PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2);
|
Chris@87
|
970
|
Chris@87
|
971 /*
|
Chris@87
|
972 Returns the remainder of dividing o1 by o2, possibly in-place, or
|
Chris@87
|
973 null on failure. This is the equivalent of the Python expression:
|
Chris@87
|
974 o1 %= o2.
|
Chris@87
|
975
|
Chris@87
|
976 */
|
Chris@87
|
977
|
Chris@87
|
978 PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2,
|
Chris@87
|
979 PyObject *o3);
|
Chris@87
|
980
|
Chris@87
|
981 /*
|
Chris@87
|
982 Returns the result of raising o1 to the power of o2, possibly
|
Chris@87
|
983 in-place, or null on failure. This is the equivalent of the Python
|
Chris@87
|
984 expression: o1 **= o2, or pow(o1, o2, o3) if o3 is present.
|
Chris@87
|
985
|
Chris@87
|
986 */
|
Chris@87
|
987
|
Chris@87
|
988 PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2);
|
Chris@87
|
989
|
Chris@87
|
990 /*
|
Chris@87
|
991 Returns the result of left shifting o1 by o2, possibly in-place, or
|
Chris@87
|
992 null on failure. This is the equivalent of the Python expression:
|
Chris@87
|
993 o1 <<= o2.
|
Chris@87
|
994
|
Chris@87
|
995 */
|
Chris@87
|
996
|
Chris@87
|
997 PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2);
|
Chris@87
|
998
|
Chris@87
|
999 /*
|
Chris@87
|
1000 Returns the result of right shifting o1 by o2, possibly in-place or
|
Chris@87
|
1001 null on failure. This is the equivalent of the Python expression:
|
Chris@87
|
1002 o1 >>= o2.
|
Chris@87
|
1003
|
Chris@87
|
1004 */
|
Chris@87
|
1005
|
Chris@87
|
1006 PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2);
|
Chris@87
|
1007
|
Chris@87
|
1008 /*
|
Chris@87
|
1009 Returns the result of bitwise and of o1 and o2, possibly in-place,
|
Chris@87
|
1010 or null on failure. This is the equivalent of the Python
|
Chris@87
|
1011 expression: o1 &= o2.
|
Chris@87
|
1012
|
Chris@87
|
1013 */
|
Chris@87
|
1014
|
Chris@87
|
1015 PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2);
|
Chris@87
|
1016
|
Chris@87
|
1017 /*
|
Chris@87
|
1018 Returns the bitwise exclusive or of o1 by o2, possibly in-place, or
|
Chris@87
|
1019 null on failure. This is the equivalent of the Python expression:
|
Chris@87
|
1020 o1 ^= o2.
|
Chris@87
|
1021
|
Chris@87
|
1022 */
|
Chris@87
|
1023
|
Chris@87
|
1024 PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2);
|
Chris@87
|
1025
|
Chris@87
|
1026 /*
|
Chris@87
|
1027 Returns the result of bitwise or of o1 and o2, possibly in-place,
|
Chris@87
|
1028 or null on failure. This is the equivalent of the Python
|
Chris@87
|
1029 expression: o1 |= o2.
|
Chris@87
|
1030
|
Chris@87
|
1031 */
|
Chris@87
|
1032
|
Chris@87
|
1033
|
Chris@87
|
1034 PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base);
|
Chris@87
|
1035
|
Chris@87
|
1036 /*
|
Chris@87
|
1037 Returns the integer n converted to a string with a base, with a base
|
Chris@87
|
1038 marker of 0b, 0o or 0x prefixed if applicable.
|
Chris@87
|
1039 If n is not an int object, it is converted with PyNumber_Index first.
|
Chris@87
|
1040 */
|
Chris@87
|
1041
|
Chris@87
|
1042
|
Chris@87
|
1043 /* Sequence protocol:*/
|
Chris@87
|
1044
|
Chris@87
|
1045 PyAPI_FUNC(int) PySequence_Check(PyObject *o);
|
Chris@87
|
1046
|
Chris@87
|
1047 /*
|
Chris@87
|
1048 Return 1 if the object provides sequence protocol, and zero
|
Chris@87
|
1049 otherwise.
|
Chris@87
|
1050
|
Chris@87
|
1051 This function always succeeds.
|
Chris@87
|
1052
|
Chris@87
|
1053 */
|
Chris@87
|
1054
|
Chris@87
|
1055 PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o);
|
Chris@87
|
1056
|
Chris@87
|
1057 /*
|
Chris@87
|
1058 Return the size of sequence object o, or -1 on failure.
|
Chris@87
|
1059
|
Chris@87
|
1060 */
|
Chris@87
|
1061
|
Chris@87
|
1062 /* For DLL compatibility */
|
Chris@87
|
1063 #undef PySequence_Length
|
Chris@87
|
1064 PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o);
|
Chris@87
|
1065 #define PySequence_Length PySequence_Size
|
Chris@87
|
1066
|
Chris@87
|
1067
|
Chris@87
|
1068 PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2);
|
Chris@87
|
1069
|
Chris@87
|
1070 /*
|
Chris@87
|
1071 Return the concatenation of o1 and o2 on success, and NULL on
|
Chris@87
|
1072 failure. This is the equivalent of the Python
|
Chris@87
|
1073 expression: o1+o2.
|
Chris@87
|
1074
|
Chris@87
|
1075 */
|
Chris@87
|
1076
|
Chris@87
|
1077 PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count);
|
Chris@87
|
1078
|
Chris@87
|
1079 /*
|
Chris@87
|
1080 Return the result of repeating sequence object o count times,
|
Chris@87
|
1081 or NULL on failure. This is the equivalent of the Python
|
Chris@87
|
1082 expression: o1*count.
|
Chris@87
|
1083
|
Chris@87
|
1084 */
|
Chris@87
|
1085
|
Chris@87
|
1086 PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i);
|
Chris@87
|
1087
|
Chris@87
|
1088 /*
|
Chris@87
|
1089 Return the ith element of o, or NULL on failure. This is the
|
Chris@87
|
1090 equivalent of the Python expression: o[i].
|
Chris@87
|
1091 */
|
Chris@87
|
1092
|
Chris@87
|
1093 PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
|
Chris@87
|
1094
|
Chris@87
|
1095 /*
|
Chris@87
|
1096 Return the slice of sequence object o between i1 and i2, or
|
Chris@87
|
1097 NULL on failure. This is the equivalent of the Python
|
Chris@87
|
1098 expression: o[i1:i2].
|
Chris@87
|
1099
|
Chris@87
|
1100 */
|
Chris@87
|
1101
|
Chris@87
|
1102 PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v);
|
Chris@87
|
1103
|
Chris@87
|
1104 /*
|
Chris@87
|
1105 Assign object v to the ith element of o. Returns
|
Chris@87
|
1106 -1 on failure. This is the equivalent of the Python
|
Chris@87
|
1107 statement: o[i]=v.
|
Chris@87
|
1108
|
Chris@87
|
1109 */
|
Chris@87
|
1110
|
Chris@87
|
1111 PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i);
|
Chris@87
|
1112
|
Chris@87
|
1113 /*
|
Chris@87
|
1114 Delete the ith element of object v. Returns
|
Chris@87
|
1115 -1 on failure. This is the equivalent of the Python
|
Chris@87
|
1116 statement: del o[i].
|
Chris@87
|
1117 */
|
Chris@87
|
1118
|
Chris@87
|
1119 PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2,
|
Chris@87
|
1120 PyObject *v);
|
Chris@87
|
1121
|
Chris@87
|
1122 /*
|
Chris@87
|
1123 Assign the sequence object, v, to the slice in sequence
|
Chris@87
|
1124 object, o, from i1 to i2. Returns -1 on failure. This is the
|
Chris@87
|
1125 equivalent of the Python statement: o[i1:i2]=v.
|
Chris@87
|
1126 */
|
Chris@87
|
1127
|
Chris@87
|
1128 PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
|
Chris@87
|
1129
|
Chris@87
|
1130 /*
|
Chris@87
|
1131 Delete the slice in sequence object, o, from i1 to i2.
|
Chris@87
|
1132 Returns -1 on failure. This is the equivalent of the Python
|
Chris@87
|
1133 statement: del o[i1:i2].
|
Chris@87
|
1134 */
|
Chris@87
|
1135
|
Chris@87
|
1136 PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o);
|
Chris@87
|
1137
|
Chris@87
|
1138 /*
|
Chris@87
|
1139 Returns the sequence, o, as a tuple on success, and NULL on failure.
|
Chris@87
|
1140 This is equivalent to the Python expression: tuple(o)
|
Chris@87
|
1141 */
|
Chris@87
|
1142
|
Chris@87
|
1143
|
Chris@87
|
1144 PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o);
|
Chris@87
|
1145 /*
|
Chris@87
|
1146 Returns the sequence, o, as a list on success, and NULL on failure.
|
Chris@87
|
1147 This is equivalent to the Python expression: list(o)
|
Chris@87
|
1148 */
|
Chris@87
|
1149
|
Chris@87
|
1150 PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m);
|
Chris@87
|
1151 /*
|
Chris@87
|
1152 Return the sequence, o, as a list, unless it's already a
|
Chris@87
|
1153 tuple or list. Use PySequence_Fast_GET_ITEM to access the
|
Chris@87
|
1154 members of this list, and PySequence_Fast_GET_SIZE to get its length.
|
Chris@87
|
1155
|
Chris@87
|
1156 Returns NULL on failure. If the object does not support iteration,
|
Chris@87
|
1157 raises a TypeError exception with m as the message text.
|
Chris@87
|
1158 */
|
Chris@87
|
1159
|
Chris@87
|
1160 #define PySequence_Fast_GET_SIZE(o) \
|
Chris@87
|
1161 (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o))
|
Chris@87
|
1162 /*
|
Chris@87
|
1163 Return the size of o, assuming that o was returned by
|
Chris@87
|
1164 PySequence_Fast and is not NULL.
|
Chris@87
|
1165 */
|
Chris@87
|
1166
|
Chris@87
|
1167 #define PySequence_Fast_GET_ITEM(o, i)\
|
Chris@87
|
1168 (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))
|
Chris@87
|
1169 /*
|
Chris@87
|
1170 Return the ith element of o, assuming that o was returned by
|
Chris@87
|
1171 PySequence_Fast, and that i is within bounds.
|
Chris@87
|
1172 */
|
Chris@87
|
1173
|
Chris@87
|
1174 #define PySequence_ITEM(o, i)\
|
Chris@87
|
1175 ( Py_TYPE(o)->tp_as_sequence->sq_item(o, i) )
|
Chris@87
|
1176 /* Assume tp_as_sequence and sq_item exist and that i does not
|
Chris@87
|
1177 need to be corrected for a negative index
|
Chris@87
|
1178 */
|
Chris@87
|
1179
|
Chris@87
|
1180 #define PySequence_Fast_ITEMS(sf) \
|
Chris@87
|
1181 (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \
|
Chris@87
|
1182 : ((PyTupleObject *)(sf))->ob_item)
|
Chris@87
|
1183 /* Return a pointer to the underlying item array for
|
Chris@87
|
1184 an object retured by PySequence_Fast */
|
Chris@87
|
1185
|
Chris@87
|
1186 PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value);
|
Chris@87
|
1187
|
Chris@87
|
1188 /*
|
Chris@87
|
1189 Return the number of occurrences on value on o, that is,
|
Chris@87
|
1190 return the number of keys for which o[key]==value. On
|
Chris@87
|
1191 failure, return -1. This is equivalent to the Python
|
Chris@87
|
1192 expression: o.count(value).
|
Chris@87
|
1193 */
|
Chris@87
|
1194
|
Chris@87
|
1195 PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob);
|
Chris@87
|
1196 /*
|
Chris@87
|
1197 Return -1 if error; 1 if ob in seq; 0 if ob not in seq.
|
Chris@87
|
1198 Use __contains__ if possible, else _PySequence_IterSearch().
|
Chris@87
|
1199 */
|
Chris@87
|
1200
|
Chris@87
|
1201 #define PY_ITERSEARCH_COUNT 1
|
Chris@87
|
1202 #define PY_ITERSEARCH_INDEX 2
|
Chris@87
|
1203 #define PY_ITERSEARCH_CONTAINS 3
|
Chris@87
|
1204 PyAPI_FUNC(Py_ssize_t) _PySequence_IterSearch(PyObject *seq,
|
Chris@87
|
1205 PyObject *obj, int operation);
|
Chris@87
|
1206 /*
|
Chris@87
|
1207 Iterate over seq. Result depends on the operation:
|
Chris@87
|
1208 PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if
|
Chris@87
|
1209 error.
|
Chris@87
|
1210 PY_ITERSEARCH_INDEX: return 0-based index of first occurrence of
|
Chris@87
|
1211 obj in seq; set ValueError and return -1 if none found;
|
Chris@87
|
1212 also return -1 on error.
|
Chris@87
|
1213 PY_ITERSEARCH_CONTAINS: return 1 if obj in seq, else 0; -1 on
|
Chris@87
|
1214 error.
|
Chris@87
|
1215 */
|
Chris@87
|
1216
|
Chris@87
|
1217 /* For DLL-level backwards compatibility */
|
Chris@87
|
1218 #undef PySequence_In
|
Chris@87
|
1219 PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value);
|
Chris@87
|
1220
|
Chris@87
|
1221 /* For source-level backwards compatibility */
|
Chris@87
|
1222 #define PySequence_In PySequence_Contains
|
Chris@87
|
1223
|
Chris@87
|
1224 /*
|
Chris@87
|
1225 Determine if o contains value. If an item in o is equal to
|
Chris@87
|
1226 X, return 1, otherwise return 0. On error, return -1. This
|
Chris@87
|
1227 is equivalent to the Python expression: value in o.
|
Chris@87
|
1228 */
|
Chris@87
|
1229
|
Chris@87
|
1230 PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value);
|
Chris@87
|
1231
|
Chris@87
|
1232 /*
|
Chris@87
|
1233 Return the first index for which o[i]=value. On error,
|
Chris@87
|
1234 return -1. This is equivalent to the Python
|
Chris@87
|
1235 expression: o.index(value).
|
Chris@87
|
1236 */
|
Chris@87
|
1237
|
Chris@87
|
1238 /* In-place versions of some of the above Sequence functions. */
|
Chris@87
|
1239
|
Chris@87
|
1240 PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2);
|
Chris@87
|
1241
|
Chris@87
|
1242 /*
|
Chris@87
|
1243 Append o2 to o1, in-place when possible. Return the resulting
|
Chris@87
|
1244 object, which could be o1, or NULL on failure. This is the
|
Chris@87
|
1245 equivalent of the Python expression: o1 += o2.
|
Chris@87
|
1246
|
Chris@87
|
1247 */
|
Chris@87
|
1248
|
Chris@87
|
1249 PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count);
|
Chris@87
|
1250
|
Chris@87
|
1251 /*
|
Chris@87
|
1252 Repeat o1 by count, in-place when possible. Return the resulting
|
Chris@87
|
1253 object, which could be o1, or NULL on failure. This is the
|
Chris@87
|
1254 equivalent of the Python expression: o1 *= count.
|
Chris@87
|
1255
|
Chris@87
|
1256 */
|
Chris@87
|
1257
|
Chris@87
|
1258 /* Mapping protocol:*/
|
Chris@87
|
1259
|
Chris@87
|
1260 PyAPI_FUNC(int) PyMapping_Check(PyObject *o);
|
Chris@87
|
1261
|
Chris@87
|
1262 /*
|
Chris@87
|
1263 Return 1 if the object provides mapping protocol, and zero
|
Chris@87
|
1264 otherwise.
|
Chris@87
|
1265
|
Chris@87
|
1266 This function always succeeds.
|
Chris@87
|
1267 */
|
Chris@87
|
1268
|
Chris@87
|
1269 PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o);
|
Chris@87
|
1270
|
Chris@87
|
1271 /*
|
Chris@87
|
1272 Returns the number of keys in object o on success, and -1 on
|
Chris@87
|
1273 failure. For objects that do not provide sequence protocol,
|
Chris@87
|
1274 this is equivalent to the Python expression: len(o).
|
Chris@87
|
1275 */
|
Chris@87
|
1276
|
Chris@87
|
1277 /* For DLL compatibility */
|
Chris@87
|
1278 #undef PyMapping_Length
|
Chris@87
|
1279 PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o);
|
Chris@87
|
1280 #define PyMapping_Length PyMapping_Size
|
Chris@87
|
1281
|
Chris@87
|
1282
|
Chris@87
|
1283 /* implemented as a macro:
|
Chris@87
|
1284
|
Chris@87
|
1285 int PyMapping_DelItemString(PyObject *o, char *key);
|
Chris@87
|
1286
|
Chris@87
|
1287 Remove the mapping for object, key, from the object *o.
|
Chris@87
|
1288 Returns -1 on failure. This is equivalent to
|
Chris@87
|
1289 the Python statement: del o[key].
|
Chris@87
|
1290 */
|
Chris@87
|
1291 #define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K))
|
Chris@87
|
1292
|
Chris@87
|
1293 /* implemented as a macro:
|
Chris@87
|
1294
|
Chris@87
|
1295 int PyMapping_DelItem(PyObject *o, PyObject *key);
|
Chris@87
|
1296
|
Chris@87
|
1297 Remove the mapping for object, key, from the object *o.
|
Chris@87
|
1298 Returns -1 on failure. This is equivalent to
|
Chris@87
|
1299 the Python statement: del o[key].
|
Chris@87
|
1300 */
|
Chris@87
|
1301 #define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K))
|
Chris@87
|
1302
|
Chris@87
|
1303 PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, char *key);
|
Chris@87
|
1304
|
Chris@87
|
1305 /*
|
Chris@87
|
1306 On success, return 1 if the mapping object has the key, key,
|
Chris@87
|
1307 and 0 otherwise. This is equivalent to the Python expression:
|
Chris@87
|
1308 o.has_key(key).
|
Chris@87
|
1309
|
Chris@87
|
1310 This function always succeeds.
|
Chris@87
|
1311 */
|
Chris@87
|
1312
|
Chris@87
|
1313 PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key);
|
Chris@87
|
1314
|
Chris@87
|
1315 /*
|
Chris@87
|
1316 Return 1 if the mapping object has the key, key,
|
Chris@87
|
1317 and 0 otherwise. This is equivalent to the Python expression:
|
Chris@87
|
1318 o.has_key(key).
|
Chris@87
|
1319
|
Chris@87
|
1320 This function always succeeds.
|
Chris@87
|
1321
|
Chris@87
|
1322 */
|
Chris@87
|
1323
|
Chris@87
|
1324 /* Implemented as macro:
|
Chris@87
|
1325
|
Chris@87
|
1326 PyObject *PyMapping_Keys(PyObject *o);
|
Chris@87
|
1327
|
Chris@87
|
1328 On success, return a list of the keys in object o. On
|
Chris@87
|
1329 failure, return NULL. This is equivalent to the Python
|
Chris@87
|
1330 expression: o.keys().
|
Chris@87
|
1331 */
|
Chris@87
|
1332 #define PyMapping_Keys(O) PyObject_CallMethod(O,"keys",NULL)
|
Chris@87
|
1333
|
Chris@87
|
1334 /* Implemented as macro:
|
Chris@87
|
1335
|
Chris@87
|
1336 PyObject *PyMapping_Values(PyObject *o);
|
Chris@87
|
1337
|
Chris@87
|
1338 On success, return a list of the values in object o. On
|
Chris@87
|
1339 failure, return NULL. This is equivalent to the Python
|
Chris@87
|
1340 expression: o.values().
|
Chris@87
|
1341 */
|
Chris@87
|
1342 #define PyMapping_Values(O) PyObject_CallMethod(O,"values",NULL)
|
Chris@87
|
1343
|
Chris@87
|
1344 /* Implemented as macro:
|
Chris@87
|
1345
|
Chris@87
|
1346 PyObject *PyMapping_Items(PyObject *o);
|
Chris@87
|
1347
|
Chris@87
|
1348 On success, return a list of the items in object o, where
|
Chris@87
|
1349 each item is a tuple containing a key-value pair. On
|
Chris@87
|
1350 failure, return NULL. This is equivalent to the Python
|
Chris@87
|
1351 expression: o.items().
|
Chris@87
|
1352
|
Chris@87
|
1353 */
|
Chris@87
|
1354 #define PyMapping_Items(O) PyObject_CallMethod(O,"items",NULL)
|
Chris@87
|
1355
|
Chris@87
|
1356 PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, char *key);
|
Chris@87
|
1357
|
Chris@87
|
1358 /*
|
Chris@87
|
1359 Return element of o corresponding to the object, key, or NULL
|
Chris@87
|
1360 on failure. This is the equivalent of the Python expression:
|
Chris@87
|
1361 o[key].
|
Chris@87
|
1362 */
|
Chris@87
|
1363
|
Chris@87
|
1364 PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, char *key,
|
Chris@87
|
1365 PyObject *value);
|
Chris@87
|
1366
|
Chris@87
|
1367 /*
|
Chris@87
|
1368 Map the object, key, to the value, v. Returns
|
Chris@87
|
1369 -1 on failure. This is the equivalent of the Python
|
Chris@87
|
1370 statement: o[key]=v.
|
Chris@87
|
1371 */
|
Chris@87
|
1372
|
Chris@87
|
1373
|
Chris@87
|
1374 PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass);
|
Chris@87
|
1375 /* isinstance(object, typeorclass) */
|
Chris@87
|
1376
|
Chris@87
|
1377 PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass);
|
Chris@87
|
1378 /* issubclass(object, typeorclass) */
|
Chris@87
|
1379
|
Chris@87
|
1380
|
Chris@87
|
1381 PyAPI_FUNC(int) _PyObject_RealIsInstance(PyObject *inst, PyObject *cls);
|
Chris@87
|
1382
|
Chris@87
|
1383 PyAPI_FUNC(int) _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls);
|
Chris@87
|
1384
|
Chris@87
|
1385
|
Chris@87
|
1386 /* For internal use by buffer API functions */
|
Chris@87
|
1387 PyAPI_FUNC(void) _Py_add_one_to_index_F(int nd, Py_ssize_t *index,
|
Chris@87
|
1388 const Py_ssize_t *shape);
|
Chris@87
|
1389 PyAPI_FUNC(void) _Py_add_one_to_index_C(int nd, Py_ssize_t *index,
|
Chris@87
|
1390 const Py_ssize_t *shape);
|
Chris@87
|
1391
|
Chris@87
|
1392
|
Chris@87
|
1393 #ifdef __cplusplus
|
Chris@87
|
1394 }
|
Chris@87
|
1395 #endif
|
Chris@87
|
1396 #endif /* Py_ABSTRACTOBJECT_H */
|