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